Skip to content

exesse/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Structures and Algorithms

Codacy Badge Python Go

Fun way to learn Algorithms and Data Structures by solving LeetCode problems.

Table of Contents

Data Structures

Array

A a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key.

Time Complexity:

  • Access: O(1)
  • Search: O(n)
  • Insert: O(n)
  • Remove: O(n)

Click to watch explanation on YouTube

Problems:

Linked List

A linear collection of data elements, called nodes, each pointing to the next node by means of a pointer. It is a data structure consisting of a group of nodes which together represent a sequence. Possible types are:

  • Singly-linked list: linked list in which each node points to the next node and the last node points to null.

  • Doubly-linked list: linked list in which each node has two pointers, p and n, such that p points to the previous node and n points to the next node; the last node's n pointer points to null.

  • Circular-linked list: linked list in which each node points to the next node and the last node points back to the first node.

Time Complexity:

  • Access: O(n)
  • Search: O(n)
  • Insert: O(1)
  • Remove: O(1)

Click to watch explanation on YouTube

Hash Map

A data structure that can map keys to values. A hash map uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found. Used to map data of an arbitrary size to data of a fixed size. The values returned by a hash function are called hash values, hash codes, or simply hashes. If two keys map to the same value, a collision occurs.

Collision Resolution:

  • Separate Chaining: each bucket is independent, and contains a list of entries for each index. The time for hash map operations is the time to find the bucket (constant time), plus the time to iterate through the list.

  • Open Addressing: when a new entry is inserted, the buckets are examined, starting with the hashed-to-slot and proceeding in some sequence, until an unoccupied slot is found. The name open addressing refers to the fact that the location of an item is not always determined by its hash value.

Time Complexity:

  • Access: O(1)
  • Search: O(1) or O(n)
  • Insert: O(1) or O(n)
  • Remove: O(1) or O(n)

Click to watch explanation on YouTube

Problems:

Algorithms

Breadth First Search

A graph traversal algorithm which explores the neighbor nodes first, before moving to the next level neighbors.

Time Complexity: O(|V| + |E|)

Click to watch explanation on YouTube

Depth First Search

A graph traversal algorithm which explores as far as possible along each branch before backtracking.

Time Complexity: O(|V| + |E|)

Click to watch explanation on YouTube

Problems: