Complexity Cheat Sheet
This page is a reference, not a tutorial — each numbered page in this section explains the reasoning behind the table it summarises here.
Growth-rate table
| Class | Name | Typical source |
|---|---|---|
| Constant | Direct addressing, a fixed amount of work | |
| Logarithmic | Halving the search space each step | |
| Linear | One pass over the input | |
| Linearithmic | Divide-and-conquer with a linear combine step | |
| Quadratic | Every pair; nested passes | |
| Cubic | Every triple | |
| Exponential | Every subset | |
| Factorial | Every ordering |
"n = 10⁶ takes…" — at roughly 10⁸–10⁹ simple operations per second
| Complexity | Operations at n = 10⁶ | Roughly |
|---|---|---|
| ~20 | Instant | |
| 10⁶ | Under a millisecond to a few milliseconds | |
| ~2×10⁷ | Milliseconds | |
| 10¹² | Minutes to tens of minutes | |
| 10¹⁸ | Decades — not viable at this n | |
| astronomically larger than atoms in the observable universe | Never |
The same table read the other way, "how large an n is affordable":
| Complexity | Comfortable n |
|---|---|
| ≤ 10 | |
| ≤ 25 | |
| ≤ 500 | |
| ≤ 10,000 | |
| ≤ 10,000,000 | |
| limited by memory bandwidth, not CPU |
Choosing an analysis method
Loop counting handles the common case directly. Recursive code that shares one structure across many calls — not one recursive tree per call, but state that persists between top-level calls — is an amortized-analysis question, not a recursion-tree one. Recursive code with the exact divide-and-conquer shape gets the master theorem's shortcut; anything the theorem's conditions do not cover falls back to a recursion tree, drawn by hand, or full substitution with induction.
Recall
References
- Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms, 4th ed. — Ch. 3 (asymptotics), Ch. 4 (divide-and-conquer and the master theorem), Ch. 17 (amortized analysis), Ch. 34 (NP-completeness): the chapters each row on this page's decision flow points back to.
- Sedgewick & Wayne, Algorithms, 4th ed., §1.4 — the empirical-plus-theoretical treatment this section's individual pages expand on one method at a time.
Related Pages
- Big-O Notation — what O, Ω and Θ formally assert.
- Common Complexities — the growth classes above, with the problem shapes that produce each explained in full.
- Amortized Analysis — the aggregate, accounting and potential methods this page's decision flow points to.
- Recurrences & the Master Theorem — the three cases and their exact conditions, worked on mergesort and Karatsuba.
- Space Complexity — auxiliary space and the recursion-stack cost this page's table does not cover.
- P, NP & Intractability — what to do once loop counting or a recurrence points to an exponential bound.