Skip to main content

Updated Sep 11, 2026

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​

ClassNameTypical source
O(1)O(1)ConstantDirect addressing, a fixed amount of work
O(log⁡n)O(\log n)LogarithmicHalving the search space each step
O(n)O(n)LinearOne pass over the input
O(nlog⁡n)O(n \log n)LinearithmicDivide-and-conquer with a linear combine step
O(n2)O(n^{2})QuadraticEvery pair; nested passes
O(n3)O(n^{3})CubicEvery triple
O(2n)O(2^{n})ExponentialEvery subset
O(n!)O(n!)FactorialEvery ordering

"n = 10⁶ takes…" — at roughly 10⁸–10⁹ simple operations per second​

ComplexityOperations at n = 10⁶Roughly
O(log⁡n)O(\log n)~20Instant
O(n)O(n)10⁶Under a millisecond to a few milliseconds
O(nlog⁡n)O(n \log n)~2×10⁷Milliseconds
O(n2)O(n^{2})10¹²Minutes to tens of minutes
O(n3)O(n^{3})10¹⁸Decades — not viable at this n
O(2n)O(2^{n})astronomically larger than atoms in the observable universeNever

The same table read the other way, "how large an n is affordable":

ComplexityComfortable n
O(n!)O(n!)≤ 10
O(2n)O(2^{n})≤ 25
O(n3)O(n^{3})≤ 500
O(n2)O(n^{2})≤ 10,000
O(nlog⁡n)O(n \log n)≤ 10,000,000
O(n)O(n)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 O(1)O(1) 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.