- Contiguous Arrays
- Good and Bad vs Linked Lists
- Linked Lists
- Good and bad vs Arrays
- Operations: search, insert, remove
- Stack
- Operations: push, pop
- Queue
- Operations: enqueue, dequeue
- Dictionary (key-value storage)
- Operations: search_by_key, insert, remove_by_key
- Specialized Operations: max, min, predecessor, successor
- Binary Search Tree
- Operations: search, min, max, traversal, insert, delete (tricky)
- Balanced Binary Search Tree
- Priority Queue
- Operations: insert, min/max, pop min/max.
- Hash
- Linked list vs linear probing implementations
- Useful for duplicate detection (or substring detection).
- Heap
- Array representation vs binary tree representation
- Selection sort
- Iterate along array
- Move minimum of elements after i to i.
- Heap sort
- Selection sort into a heap
- Convert array to min heap
- Removing minimum is now O(log n)
- Fast heap construction
- Insert sort (Keeping sorted sublist)
- Iterate along the array
- For each element, put in the correct place up to i.
- Incremental sort is online algorithm
- Tree sort
- Insert sort into a balanced binary tree
- Recover sorted array as in order traversal
- Merge sort (Divide and Conquer)
- Good for sorting linked lists because does not require fast random access
- Bad: needs buffer
- Quick sort (Randomization)
- O(n * h) where h is the height of the recursive call stack
- To ensure random start state, randomly permute array before starting
- Nut-bolt problem: given n nuts and n bolts, match each bolt to each nut in average O(nlogn).
- Randomly pick a bolt, sort nuts based on bolt, then use the nut found to sort bolts.
- Bucket sort
- External sort (Multiway Mergesort)
- Given k sorted lists on disk and k sorted top blocks in memory.
- Make a heap with the top elements of the k top blocks.
- Pop from heap and store in output array in memory and push from that subarray
- When output array full, write to disk and when top block empty, read from disk.
- Binary search
- Modified binary search to count occurrences of a letter
- One sided binary search
- Binary Search
- Closest Pair
- Uniqueness
- Looking for kth most occuring element
- Selecting kth largest element
- Convex hull
- Undirected v. directed
- Weighted v. unweighted
- Simple - no self loops, no multiedges
- Spare v. dense
- Cyclic v. acyclic
- Adjacency Matrix
- Adjacency List
- Graph traversal
- 3 states: undiscovered, discovered, processed (visited all neighbors)
- BFS
- Finding shortest path by keeping a parent array while BFS and backtracking
- Connected Component and bipartite Graphs
- DFS
- Finding cycles
- Disconnecting graphs
- Topological sorting
- Strongly Connected
def backtrack:
if solution:
process_solution
else:
construct_candidate_next_values_array
for each candidate in next_values:
make_move
backtrack
unmake_move
- Generating powerset
- Generating permutations
- Generating all paths
- Sudoku
- Optimization: look for most constrained (least number of options) next square and look ahead to get possible values
- Random search
- Local search - generate transition function that changes a few parameters of the search space slightly to generate new candidate to test
- Simulated Annealing - local search with random jump to a far away solution. Prevents being trapped in local minima.
- Genetic algorithm
- Maximum cut problem - partitioning weighted graph G into sets with maximum weighted edges.
- Find recursive solution first
- Consider whether you are reusing values. If so, precompute and store.
- Fibonacci
- Binomial Coefficient
- Approximate String Matching (edit distance)
- Assign cost to substitution, insertion, deletion.
- Recursively compute min cost of string by taking minimum cost of sub, insert, delete.
- Precompute minimum cost in a table
- Reconstruct path
- Substring Matching
- Longest Common subsequence
- Maximum Monotone subsequence
- The partition problem without rearrangement