- Quick sort
- Binary Search
- Merge sort
- Heap sort
- Radix sort
- Balanced binary Tree
- Implement Heap
- BST delete
-
Binary Search
-
Selection Sort
-
Bubble Sort
-
Insert Sort
-
Merge Sort
-
Heap Sort
-
Quick Sort/Quick select
- Nuts and bolts problem
- Median finding
-
Radix Sort
- Given array of integers, take each integer mod 10 divide 1. Put into linked list.
- Then consider linked lists in order.
- Then repeat for mod 100 divide 10.
- Repeat his process util divide by biggest power of 10 in array.
- Sort n numbers from range 0 to 2^n-1 in linear time
-
Counting Sort
-
Bucket Sort
-
Shell Sort
-
Activity Selection: You are given n activities with their start and finish times. Select the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time.
-
Kruskal’s Minimum Spanning Tree Algorithm:
- Sort all edges in increasing order of weight
- Pick smallest edge, check if it forms a cycle using the Union-Find algorithm. If not, add edge.
- Repeat until there are v-1 edges
-
Huffman Coding: TODO
-
Prims Algorithm for MST
-
Dijkstra's Shortest Path
-
Job Sequencing Problem: Given an array of jobs where every job has a deadline and associated profit if the job is finished before the deadline
- Sort jobs by decreasing profit and pick jobs that can fit
-
Longest Increasing Subsequence
- O(n^2) time complexity
- Store longest increasing subsequence so far
-
Edit distance
- TODO
-
Longest increasing subsequence
- L(A, B) = Max(L(A[:n-1], B[n-1])) + 1 if A[n] == B[n]
- Max(L(A[:n-1], B[:n]), L(A[:n], B[:n-1]))
-
Naive: consider each point as the starting point
-
KMP Algorithm:
- Build longestPrefixSuffix Array by setting i = 0, j = 1. If i == j, store i+1 in LPS and increment i and j. If i != j, increment j, store 0 at position j in LPS Array or make i = LPS[i-1], and check again.
- Iterate through array (j) and pattern array (i). If mismatch, then LPS[i-1] is the next point of comparison in pattern array.
-
Rabin-Karp
-
Suffix Array
-
Anagram substring: keep counts of each letter in hash, keep running window count. If same, anagram found.
-
Longest Palindrome Substring: Manacher's algorithm
- Print all permutations
- Knights Tour
- Rat in the Maze
- N Queens
- Subset sum
- M Coloring Problem
- Sudoku
- Generate two subsets of equal size with minimum difference
-
Find median of two sorted arrays.
- Take median of both arrays: med1, med2.
- If med1 < med2, look for median in right half of arr1 and left half of arr2.
- Repeat til only 4 elements left.
-
Counting Inversions: merge sort with counter
-
Closest pair of points
- Sort by x coordinate.
- Split plane into two halves
- Find min = min(min_left, min_right)
- Consider all points distance min from split point
- min = min(min, min_split)
-
Topological Sort: Recursive call to sort for all children before processing this element
- TODO
-
Bipartiate Graph: BFS
-
Dijkstra's Shortest Path
- At each step, add vertex from unincluded set that has minimum distance
-
Minimum Spanning Tree
-
Given an array of strings, can the strings chain to form a circle.
- For each string, take first and last character and add a edge
- If eulerian circuit exists, then true.
- Eulerian circuit if single strongly connected component and in degree = out degree.
-
Given sorted order of words in an alien language, figure out order of letters in the language.
- Make a graph where edges are when first character mismatch.
- Find topological sorting
-
Shortest chain of words to reach a target word: BFS
-
Find same contact in a list of contacts: find connected components.