Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 166: Master Indexes

Quick Reference Indexes for the Entire Book

This chapter provides multiple cross-referenced indexes to help you quickly find algorithms, data structures, patterns, complexity classes, and formulas. Use it as a lookup companion while solving problems.


How to Use These Indexes

  • Algorithm Index: Look up an algorithm by name to find its chapter, time complexity, and space complexity.
  • Data Structure Index: Compare data structures by their operation complexities.
  • Pattern Recognition Index: Given a problem keyword, find the technique you should apply.
  • Complexity Index: Given a constraint on n, determine the maximum algorithm complexity you can afford.
  • Formula Index: Quick lookup for mathematical formulas used across the book.

Algorithm Index

Sorting Algorithms

AlgorithmChapterTime (Avg)Time (Worst)SpaceStable
Bubble Sort5O(n²)O(n²)O(1)Yes
Selection Sort5O(n²)O(n²)O(1)No
Insertion Sort5O(n²)O(n²)O(1)Yes
Merge Sort5O(n log n)O(n log n)O(n)Yes
QuickSort5O(n log n)O(n²)O(log n)No
Heap Sort5O(n log n)O(n log n)O(1)No
Counting Sort5O(n + k)O(n + k)O(k)Yes
Radix Sort5O(d(n + k))O(d(n + k))O(n + k)Yes
Tim Sort5O(n log n)O(n log n)O(n)Yes

Searching Algorithms

AlgorithmChapterTimeSpaceNotes
Binary Search6O(log n)O(1)Requires sorted input
Ternary Search6O(log n)O(1)Unimodal functions
Exponential Search6O(log n)O(1)Unbounded search
Interpolation Search6O(log log n) avgO(1)Uniform distribution
Fibonacci Search6O(log n)O(1)No division needed

Graph Algorithms

AlgorithmChapterTimeSpaceUse Case
DFS23O(V + E)O(V)Traversal, connectivity
BFS24O(V + E)O(V)Shortest path (unweighted)
Topological Sort25O(V + E)O(V)DAG ordering
Dijkstra26O((V+E) log V)O(V)Single-source shortest path
Bellman-Ford82O(VE)O(V)Negative edges
Floyd-Warshall82O(V³)O(V²)All-pairs shortest path
Kruskal27O(E log E)O(V)MST
Prim27O((V+E) log V)O(V)MST
Tarjan SCC81O(V + E)O(V)Strongly connected components
Kosaraju81O(V + E)O(V)Strongly connected components
Dinic83O(V²E)O(V + E)Max flow
Hopcroft-Karp112O(E√V)O(V + E)Bipartite matching
A* Search65O(E log V)O(V)Heuristic shortest path
Johnson82O(V² log V + VE)O(V²)All-pairs (sparse)

String Algorithms

AlgorithmChapterTimeSpaceUse Case
KMP41O(n + m)O(m)Pattern matching
Z Algorithm42O(n + m)O(n + m)Pattern matching
Rabin-Karp40O(n + m) avgO(1)Multiple pattern matching
Aho-Corasick46O(n + m + z)O(nm)Multi-pattern matching
Suffix Array44O(n log n)O(n)Suffix sorting
Suffix Automaton45O(n)O(n)All substrings
Manacher119O(n)O(n)All palindromes
Suffix Tree87O(n)O(n)Generalized suffix queries
Palindromic Tree88O(n)O(n)Distinct palindromic substrings
BWT/FM-Index120O(n) build, O(m) queryO(n)Compressed full-text search

Number Theory

AlgorithmChapterTimeUse Case
Sieve of Eratosthenes60O(n log log n)Prime generation
GCD (Euclidean)60O(log min(a,b))Greatest common divisor
Modular Exponentiation60O(log n)Fast power
Miller-Rabin175O(k log²n)Primality test
Pollard’s Rho175O(n^{1/4})Factorization

Optimization & Approximation

AlgorithmChapterTimeUse Case
Gale-Shapley162O(n²)Stable matching
Held-Karp (TSP)149O(2^n · n²)Exact TSP
Karger’s Min Cut150O(n² log n) runsMin cut
Simplex151Exponential worstLinear programming
Hungarian170O(n³)Assignment problem

Data Structure Index

Basic Structures

StructureChapterInsertDeleteSearchSpace
Array4O(1) endO(1) endO(n)O(n)
Dynamic Array4O(1) amortO(1) endO(n)O(n)
Linked List12O(1) headO(1) given nodeO(n)O(n)
Doubly Linked List12O(1)O(1) given nodeO(n)O(n)
Stack10O(1)O(1) topO(n)O(n)
Queue11O(1)O(1) frontO(n)O(n)
Deque11O(1)O(1) both endsO(n)O(n)

Hash-Based Structures

StructureChapterInsertDeleteSearchSpace
Hash Map7O(1) avgO(1) avgO(1) avgO(n)
Hash Set7O(1) avgO(1) avgO(1) avgO(n)
Bloom Filter79O(k)N/AO(k)O(m bits)
Cuckoo Hashing7O(1) worstO(1) worstO(1) worstO(n)

Tree Structures

StructureChapterInsertDeleteSearchSpace
BST (unbalanced)14O(h)O(h)O(h)O(n)
AVL Tree14O(log n)O(log n)O(log n)O(n)
Red-Black Tree14O(log n)O(log n)O(log n)O(n)
B-Tree77O(log n)O(log n)O(log n)O(n)
Treap57O(log n)O(log n)O(log n)O(n)
Splay Tree98O(log n) amortO(log n) amortO(log n) amortO(n)
Skip List74O(log n)O(log n)O(log n)O(n)

Priority Queue Structures

StructureChapterInsertExtract-MinDecrease-KeySpace
Binary Heap15O(log n)O(log n)O(log n)O(n)
Fibonacci Heap15O(1) amortO(log n) amortO(1) amortO(n)
Binomial Heap15O(1) amortO(log n)O(log n)O(n)
Pairing Heap15O(1)O(log n) amortO(log n) amortO(n)

Range Query Structures

StructureChapterBuildUpdateQuerySpace
Segment Tree18O(n)O(log n)O(log n)O(n)
Lazy Segment Tree18O(n)O(log n)O(log n)O(n)
Fenwick Tree19O(n)O(log n)O(log n)O(n)
Sparse Table20O(n log n)N/AO(1)O(n log n)
Square Root Decomposition173O(n)O(√n)O(√n)O(n)
Mo’s Algorithm173O(n√n) totalO(n)

Specialized Structures

StructureChapterKey OperationTimeSpace
Trie16Insert/Search stringO(m)O(nm)
DSU17Union/FindO(α(n))O(n)
KD Tree78Nearest neighborO(log n) avgO(n)
Van Emde Boas100Successor/PredecessorO(log log U)O(U)
Link-Cut Tree157Path/Link/CutO(log n)O(n)
Persistent Segment Tree75Version-based queryO(log n)O(n log n)

Pattern Recognition Index

Problem Keywords → Technique

Keyword / PhrasePrimary TechniqueChapterSecondary Technique
“sorted array”Binary Search6Two Pointers
“top k” / “k-th largest”Heap15Quickselect
“shortest path”BFS (unweighted)24Dijkstra (weighted)
“minimum cost” / “minimum operations”DP30-31Greedy
“number of ways” / “count”DP30-31Combinatorics
“subarray” / “contiguous”Sliding Window35Prefix Sum
“subsequence”DP30-31Binary Search (LIS)
“connected components”DFS / BFS23-24Union-Find
“cycle detection”DFS with colors23Union-Find
“topological order”Topological Sort25DFS
“range query” / “range update”Segment Tree18Fenwick Tree
“parentheses” / “valid expression”Stack10DP
“anagram” / “frequency”Hash Map7Sorting
“palindrome”Two Pointers34Manacher
“permutation” / “combination”Backtracking9Next Permutation
“next greater” / “next smaller”Monotonic Stack37
“sliding window max/min”Monotonic Queue38
“median”Two Heaps15Binary Search
“LCA” (lowest common ancestor)Binary Lifting21Euler Tour + RMQ
“path on tree”HLD107Euler Tour
“count with digits”Digit DP85
“optimal k groups”Binary Search on Answer6Alien Trick
“matrix chain”Interval DP31
“bitmask states”Bitmask DP31
“interval scheduling”Greedy (sort by end)32DP
“minimum spanning tree”Kruskal / Prim27
“bipartite”BFS coloring24DFS
“strongly connected”Tarjan / Kosaraju81
“max flow” / “min cut”Dinic83
“matching”Hopcroft-Karp112Hungarian
“serialize” / “deserialize”BFS / DFS23-24
“LRU cache”Hash Map + DLL89
“sliding median”Two Heaps15Ordered Set
“string matching”KMP / Z-algo41-42Rabin-Karp
“multiple patterns”Aho-Corasick46Trie
“all palindromes”Manacher119Palindromic Tree
“suffix” queriesSuffix Array44Suffix Tree
“edit distance”DP (LCS-style)122
“regex” / “wildcard”DP123NFA

Complexity Index

Constraint → Maximum Complexity

Constraint on nMax ComplexityTypical ApproachExample Algorithms
n ≤ 10O(n!)Permutation brute forceGenerate all permutations
n ≤ 15O(2^n · n)Bitmask DPTSP, subset DP
n ≤ 20O(2^n)Backtracking, Meet-in-MiddleSubset sum, N-Queens
n ≤ 50O(n⁴)High-dimensional DP4D interval DP
n ≤ 100O(n³)Matrix-style DPFloyd-Warshall, Matrix Chain
n ≤ 200O(n³)Graph algorithmsFloyd-Warshall
n ≤ 500O(n³)Cubic algorithmsAll-pairs shortest path
n ≤ 1,000O(n²)Quadratic DPLIS, Edit Distance
n ≤ 5,000O(n²)Simple DPO(n²) DP solutions
n ≤ 10,000O(n²)Quadratic with small constantBubble sort variants
n ≤ 100,000O(n log n)Sort-based, treesMerge sort, Segment tree
n ≤ 1,000,000O(n)Linear scanHash map, two pointers
n ≤ 10,000,000O(n)Careful linearSieve, counting sort
n ≤ 10^9O(√n)Number theoryPrimality, factorization
n ≤ 10^18O(log n)Binary search, mathFast exponentiation

Complexity → Max Input Size (for 1 second)

ComplexityMax nNotes
O(1)Constant time
O(log n)10^18Binary search
O(√n)10^10Number theory
O(n)10^7Linear scan
O(n log n)10^6Sorting
O(n²)5,000Nested loops
O(n³)500Triple nested
O(n⁴)100Quadruple nested
O(2^n)20Exponential
O(3^n)15Triple exponential
O(n!)10Factorial
O(n · 2^n)18Bitmask DP

Formula Index

Combinatorics

FormulaExpressionChapterUse Case
PermutationP(n,r) = n!/(n-r)!71Ordered selection
CombinationC(n,r) = n!/(r!(n-r)!)71Unordered selection
Stars and BarsC(n+k-1, k-1)71Distribution problems
Catalan NumberC(2n,n)/(n+1)71Balanced parentheses, trees
Inclusion-Exclusion|A∪B| = |A|+|B|-|A∩B|71Counting with constraints
DerangementD(n) = (n-1)(D(n-1)+D(n-2))71No fixed points

Number Theory

FormulaExpressionChapterUse Case
Euler’s Totientφ(n) = n∏(1-1/p)60Coprime counting
Modular Inversea^{-1} ≡ a^{p-2} (mod p)60Division in modular arithmetic
Chinese Remainderx ≡ aᵢ (mod mᵢ)176System of congruences
Fermat’s Little Theorema^{p-1} ≡ 1 (mod p)60Modular exponentiation
Möbius Functionμ(n)172Inclusion-exclusion on divisors

Probability & Statistics

FormulaExpressionChapterUse Case
Bayes’ TheoremP(A|B) = P(B|A)P(A)/P(B)72Conditional probability
Birthday ParadoxP ≈ 1 - e^{-n²/2d}72Hash collision probability
Coupon CollectorE = n·H(n) ≈ n ln n72Expected coverage
Linearity of ExpectationE[X+Y] = E[X]+E[Y]72Expected value computation

Series & Sequences

FormulaExpressionChapterUse Case
Geometric Suma(r^n - 1)/(r - 1)2Series computation
Arithmetic Sumn(a₁ + aₙ)/22Series computation
Fibonacci (closed form)(φ^n - ψ^n)/√52Direct computation
Harmonic NumberH(n) ≈ ln n + γ2Sum of reciprocals

Algorithm-Specific

FormulaExpressionChapterUse Case
Master TheoremT(n) = aT(n/b) + O(n^d)3Divide & conquer recurrences
Expected hash chainO(1 + n/m)7Hash table analysis
Height of balanced BSTO(log n)14Tree operations
Max edges in graphV(V-1)/222Graph density

Algorithm Selection Quick Guide

By Problem Type

Problem TypeFirst ChoiceWhen It FailsFallback
Find element in sorted arrayBinary SearchUnsortedSort first, then BS
Shortest path (unweighted)BFSWeighted edgesDijkstra
Shortest path (weighted, no negative)DijkstraNegative edgesBellman-Ford
All-pairs shortest pathFloyd-WarshallToo large (n > 500)Dijkstra × n
Minimum spanning treeKruskalDense graphPrim
Maximum flowDinicEdmonds-Karp
Longest increasing subsequenceBinary SearchNeed actual sequenceDP O(n²)
Edit distanceDP O(nm)Space too largeHirschberg (linear space)
Range minimum querySparse Table (static)Dynamic updatesSegment Tree
Range sum with updatesFenwick TreeRange updates tooLazy Segment Tree
String matchingKMPMultiple patternsAho-Corasick
All palindromesManacherDistinct onlyPalindromic Tree
Connectivity (static)DFSDynamic edgesUnion-Find
Top k elementsMin-heap (size k)Need sorted outputSort
Median maintenanceTwo heapsNeed order statisticsOrder-statistic tree

By Data Size

Data SizeRecommended Structures
< 100Arrays, simple loops
100 – 10,000Hash maps, arrays, sorting
10,000 – 10^6Trees, heaps, binary search
10^6 – 10^7Linear algorithms, hash maps
> 10^7Streaming, sampling, approximation

Cross-Reference Summary

If You Need…Go To
Learn a topic from scratchMaster TOC (Ch 144) → specific chapter
Pick the right algorithmAlgorithm Selection (Ch 140)
Pick the right data structureDS Selection (Ch 141)
Look up a formulaFormula Handbook (Ch 138)
Check complexity limitsComplexity Handbook (Ch 139)
Match a problem patternPattern Recognition (Ch 97)
Prepare for a specific companyCompany Handbook (Ch 142)
Quick fact verificationKnowledge Aids (Ch 143)
Navigate the whole bookMaster TOC (Ch 144)