Algorithms

Back

By Category

Sorting & Selection

Searching

Graph Algorithms

Dynamic Programming

String Algorithms

Greedy Algorithms

Backtracking

Bit Manipulation & Math

Streaming Algorithms

Cryptography


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

Dynamic Programming: Optimal substructure + overlapping subproblems

Greedy: Local optimal choices lead to global optimum

Backtracking: Try all possibilities with pruning

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