Cheat Sheet
Constraints To Tags
Constraint | Time Complexity | Tags |
---|---|---|
n ≈ 10^8 | O(log n) / O(√n) / O(1) | Math, GCD/LCM, Fast Power, Binary Representation, Prime Numbers |
n ≈ 10^6 | O(n) | Two Pointers, Stack/Queue, Hash Table/Set, Prefix Sum, Greedy, 1D-DP, BFS/DFS on Tree, Topological Sort, Union Find |
n ≈ 10^5 | O(n log n) | Sorting (Merge/Quick), Binary Search, Heap/Priority Queue, Tree Map/Set, Segment Tree, Intervals |
n ≈ 10^4 | O(n²) | 2D-DP, Matrix Operations, Graph Algorithms (BFS/DFS), Shortest Path (Bellman-Ford), Palindrome |
n ≈ 200 | O(n³) | 3D-DP, Floyd Warshall, All Pairs Shortest Path, Three Pointers |
n ≈ 20 | O(2^n) / O(n!) | Backtracking, Bitmask DP, Subset Generation, Permutations, Combinations |
Below is a visual representation of different algorithm complexities and their common use cases:
Algorithm Complexity Guide
n ≈ 10^8
O(log n) / O(√n) / O(1)
Math
GCD/LCM
Fast Power
Binary Rep.
Prime Numbers
n ≈ 10^6
O(n)
Two Pointers
Stack/Queue
Hash Table
Prefix Sum
1D-DP
Tree Algorithms
n ≈ 10^5
O(n log n)
Sorting
Binary Search
Heap
Tree Map/Set
Segment Tree
n ≈ 10^4
O(n²)
2D-DP
Matrix Ops
Graph Algos
Grid Traversal
n ≈ 200
O(n³)
3D-DP
Floyd Warshall
All Pairs SP
Three Pointers
n ≈ 20
O(2^n) / O(n!)
Backtracking
Bitmask DP
Subset Gen.
Permutations