Algorithms
Back
By Category
Sorting & Selection
- Bubble Sort - O(n²), simple, educational
- Counting Sort - O(n + k), linear for integers
- Heap Sort - O(n log n), guaranteed, in-place
- Merge Sort - O(n log n), stable, divide and conquer
- Quick Sort - O(n log n), average, divide and conquer
- Quickselect - O(n), average, k-th element selection
- Radix Sort - O(d(n + k)), linear for fixed digits
Searching
Graph Algorithms
Dynamic Programming
String Algorithms
Greedy Algorithms
Backtracking
Bit Manipulation & Math
Streaming Algorithms
Cryptography
- ROT13 - O(n), simple substitution cipher
Complexity Reference
Time Complexity Classes
| Class |
Name |
Example |
| O(1) |
Constant |
Hash table lookup |
| O(log n) |
Logarithmic |
Binary search |
| O(n) |
Linear |
Array scan |
| O(n log n) |
Linearithmic |
Merge sort |
| O(n²) |
Quadratic |
Nested loops |
| O(2^n) |
Exponential |
Subset enumeration |
| O(n!) |
Factorial |
Permutation enumeration |
Common Patterns
Divide and Conquer: Split problem, solve recursively, combine
- Quick Sort, Merge Sort, Binary Search
Dynamic Programming: Optimal substructure + overlapping subproblems
- Knapsack, LCS, Edit Distance
Greedy: Local optimal choices lead to global optimum
- Huffman, Interval Scheduling, Dijkstra
Backtracking: Try all possibilities with pruning
- N-Queens, Subsets, Permutations
Choosing an Algorithm
| Problem Type |
Consider |
| Sorted array search |
Binary Search |
| Shortest path |
BFS (unweighted), Dijkstra (weighted) |
| String matching |
KMP, Rabin-Karp |
| Optimization with constraints |
DP, Greedy |
| All combinations |
Backtracking |
| Streaming data |
Reservoir Sampling, Count-Min, HLL |