Memra

The one-page reference sheet (memorize cold)

◈ 4 cards

Every complexity, the growth hierarchy, the master-theorem card, and the proof-technique catalog on a single page — the facts you should be able to reproduce from memory before you walk in.

How to use this lesson

The exam is open-book, so you will not be graded on recall of a table. But if you have to look up the complexity of BUILD-MAX-HEAP mid-problem, you have already lost time you needed for the reasoning. Treat everything below as the layer you make automatic, so the open book is for the derivations, not the facts. Drill the recall questions until they are instant.

Complexity of every algorithm in the course

Sorting (n elements):

AlgorithmBestAverageWorstSpaceStable?In-place?
Insertion sortΘ(n)Θ(n²)Θ(n²)Θ(1)yesyes
Merge sortΘ(n lg n)Θ(n lg n)Θ(n lg n)Θ(n)yesno
HeapsortΘ(n lg n)Θ(n lg n)Θ(n lg n)Θ(1)noyes
QuicksortΘ(n lg n)Θ(n lg n)Θ(n²)Θ(lg n)noyes
Counting sortΘ(n+k)Θ(n+k)Θ(n+k)Θ(n+k)yesno
Radix sortΘ(d(n+k))Θ(d(n+k))Θ(d(n+k))Θ(n+k)yesno
Bucket sortΘ(n)Θ(n)Θ(n²)Θ(n)yesno

Selection: RANDOMIZED-SELECT expected Θ(n); median-of-medians SELECT worst-case Θ(n).

Data-structure operations:

StructureSearchInsertDeleteNotes
Sorted arrayΘ(lg n)Θ(n)Θ(n)binary search to find
Hash table (chaining)Θ(1+α) exp.Θ(1)Θ(1)worst Θ(n)
BST (unbalanced)Θ(h)Θ(h)Θ(h)h up to n−1
Red-black treeΘ(lg n)Θ(lg n)Θ(lg n)h ≤ 2 lg(n+1)
Binary heapΘ(lg n)Θ(lg n)MAX = Θ(1); BUILD = Θ(n)
Union-findm ops in Θ(m·α(n))

Graph algorithms (V vertices, E edges):

AlgorithmTimeHandlesNotes
BFS / DFSΘ(V+E)unweightedBFS = fewest edges; DFS = timestamps
Topological sortΘ(V+E)DAG onlyDFS by decreasing finish
Kruskal (MST)Θ(E lg V)undirectedsort edges + union-find
Prim (MST)Θ(E lg V)undirectedheap keyed by edge to tree
Bellman-FordΘ(VE)negative edgesdetects negative cycle
DAG shortest pathΘ(V+E)DAG, neg OKrelax in topo order
DijkstraΘ((V+E) lg V)nonneg onlygreedy + min-heap
Floyd-WarshallΘ(V³)all-pairs, negDP; k-loop outermost
Edmonds-KarpΘ(VE²)flowBFS augmenting paths

The growth hierarchy (rank cold)

Rules: any polylog loses to any positive polynomial (); any polynomial loses to any exponential (, ); and .

The master theorem card

For with watershed :

  • Case 1. (leaves win)
  • Case 2, . (tie, add a log)
  • Case 3 and , . (root wins)

Gap (no case): and differ by only a logarithmic factor (e.g. ).

The proof-technique catalog

TechniqueUsed forThe move
Loop invariantiterative correctnessinit / maintenance / termination
Substitutionprove a recurrence boundguess, then induct with a fixed constant
Recursion treeguess a recurrence boundsum cost per level
Exchange argumentgreedy is optimalswap OPT toward the greedy choice, no worse
Cut-and-pasteoptimal substructure (DP)a better subsolution would improve OPT ⇒ contradiction
Decision treecomparison-sort lower bound≥ n! leaves ⇒ height Ω(n lg n)
Reduction (≤ₚ)NP-hardnessmap a known-hard problem TO the new one
Lower-bound comparisonapproximation ratiobound OPT below, compare the algorithm to that bound
SortWorstSpaceStableIn-placeInsertionΘ(n²)Θ(1)yesyesMergeΘ(n lg n)Θ(n)yesnoHeapsortΘ(n lg n)Θ(1)noyesQuicksortΘ(n²)Θ(lg n)noyesCountingΘ(n+k)Θ(n+k)yesnoRadixΘ(d(n+k))Θ(n+k)yesnoMerge and heapsort are the only two worst-case guarantees; bucket sort degrades to Θ(n²) too.
Sorting, worst case only — the row you actually need under time pressure.
1lg n√nnn lg n2ⁿn!nⁿpolynomially boundedexponential — intractableAny polylog loses to any polynomial; any polynomial loses to any exponential.
Rank these cold. The bracket is the line between tractable and not.
NORMAL ~/memra/learn/comp-372/master-reference-sheet utf-8 LF