Big-O in Practice: The Only Complexity Cheat Sheet That Sticks
Stop memorizing a table you forget. Learn to see the shape of an algorithm — constant, log, linear, quadratic — and you'll never blank on complexity in an interview again.
Big-O isn't about how fast your code runs today. It's about how the work grows as the input grows. Get that one sentence and the table stops needing memorization.
The shapes, from heaven to the cliff
- O(1) — a hash lookup, an array index. Doesn't care how big the input is.
- O(log n) — binary search. Halve the problem each step.
- O(n) — one pass over the data.
- O(n log n) — a good sort; the ceiling for comparison sorting.
- O(n²) — nested loops over the same data. Fine at n=100, fatal at n=100,000.
- O(2ⁿ) — brute-force subsets. The cliff. Avoid.
The two rules that do all the work
- Drop constants and lower terms.
2n + 5is just O(n). - Count the dominant loop. Nested independent loops multiply; sequential loops add.
Why interviewers care
A tier-better algorithm wins at scale no matter how clever the slow one's code is. Ten thousand items will expose a quadratic loop instantly while the O(n log n) version shrugs.
Make it stick
Reading this once won't do it — using it will. Each problem in the arena tells you the machine's rating, which tracks difficulty; clearing harder ones means spotting the better complexity:
Think in growth, not seconds. The shape decides the ceiling.