Big-O is a vocabulary for cost: it counts operations instead of seconds, and keeps only the term that dominates as n grows.
1 Operations, not seconds
Never time code with a stopwatch — machines lie. Count steps: a loop over n does n units of work.
2 Constants get dropped
3n + 20 steps is just O(n). As n grows, only the fastest-growing term survives.
3 The growth ladder
O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ). Each rung dwarfs the one below it.
4 Best vs worst
Linear search finds item 1 instantly (best) or scans everything (worst). Big-O quotes the worst case.
5 Amortized push_back
vector doubling looks expensive, but averaged over many pushes each push costs O(1).
Counting cost
Operations, not seconds1Never time code with a stopwatch — machines lie. Count steps: a loop over n does n units of work. Constants get dropped23n + 20 steps is just O(n). As n grows, only the fastest-growing term survives. The growth ladder3O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ). Each rung dwarfs the one below it. Best vs worst4Linear search finds item 1 instantly (best) or scans everything (worst). Big-O quotes the worst case. Amortized push_back5vector doubling looks expensive, but averaged over many pushes each push costs O(1). 5 building blocks make up Counting cost
A nested loop counts every pair (i, j) with j ≤ i — the grid fills row by row, 1 + 2 + 3 + 4 = 10 cells.
j = 0j = 1j = 2j = 3i = 0
i = 1
i = 2
i = 3
1 / 9The inner loop runs from j = 0 up to j = i. Four rows, four columns — how many cells get touched?
Three questions turn any code snippet into a Big-O class.
process decision input / output start / end A loop that adds up its own steps, then a halving loop that shows why log n is so cheap.
mainn = 4 — the problem size.
Console
output appears as the program runs…
Five bars — one per growth class — as n doubles from 8 to 1,024. Watch the last bar swallow the stage.
1 / 9n = 8. Linear is 8 steps, quadratic is 64 — a gap, but not yet a disaster.
One doubling loop plus one fixed loop — count each pass before you answer.
Your predicted output — one line per console line
Hint: i *= 2 visits 1, 2, 4, 8, 16, 32, 64 and stops at 128. The second loop always adds 10 five times.
Click a class, then click its signature behavior to lock the pair.
8 conceptsTap a card to expand ?O(1)drops into place
?O(log n)drops into place
?O(n)drops into place
?O(n log n)drops into place
?O(n²)drops into place
?two loops in a rowdrops into place
?Ω (Big-Omega)drops into place
?amortized O(1)drops into place
01Count operations, never seconds — hardware changes, step counts do not.
02Big-O keeps only the dominant term: 3n + 20 is O(n).
03Nested loops multiply; sequential loops add.
04A loop that halves n each pass runs about log₂(n) times.
05O(n²) at n = 1,024 is over a million steps — the growth class matters more than clever constants.
06vector push_back is amortized O(1) thanks to doubling.