Big-O answers one question: how does the work grow as the input grows? Get the shape right and the constants stop mattering.
1 The race that matters
For n = 1,000: O(1) does 1 step, O(log n) about 10, O(n) 1,000, O(n²) 1,000,000. Same data, wildly different bills.
2 Counting steps
Big-O drops constants and small terms: 3n + 50 is written O(n). Only the fastest-growing piece survives.
3 Nested = multiplied
Two loops over the same n multiply: n × n. That is why 4 people need 6 pairwise handshakes, not 8.
4 Halving = logarithm
Cut the problem in half every step and you get O(log n) — 1,000,000 items take about 20 halvings.
5 Space counts too
Memory gets its own Big-O: a running total is O(1) extra; a full copy of the input is O(n) auxiliary space.
Counting the cost
The race that matters1For n = 1,000: O(1) does 1 step, O(log n) about 10, O(n) 1,000, O(n²) 1,000,000. Same data, wildly different bills. Counting steps2Big-O drops constants and small terms: 3n + 50 is written O(n). Only the fastest-growing piece survives. Nested = multiplied3Two loops over the same n multiply: n × n. That is why 4 people need 6 pairwise handshakes, not 8. Halving = logarithm4Cut the problem in half every step and you get O(log n) — 1,000,000 items take about 20 halvings. Space counts too5Memory gets its own Big-O: a running total is O(1) extra; a full copy of the input is O(n) auxiliary space. 5 building blocks make up Counting the cost
Four complexity classes, one shared scale. Double the input and watch who moves.
1 / 12Four algorithms on one shared scale. Input n = 4 — bar height is steps of work.
The nested double loop — i picks a person, j picks everyone they have not greeted yet.
process decision input / output start / end Count nested-loop iterations by hand, then watch halving collapse 1,000 into 9 steps.
modulen = 4 people at the orientation.
Console
output appears as the program runs…
Three algorithms, three input sizes — fill the grid and read the verdict across.
n = 8n = 100n = 1,000linear O(n)
binary O(log n)
pairs O(n²)
1 / 11A step-count table: three algorithms, three input sizes. Cells fill as we count the work.
The inner loop starts at i, not 0 — count carefully.
Your predicted output — one line per console line
Hint: The inner loop shrinks as i grows: 4 + 3 + 2 + 1. Triangular numbers, not squares.
Click a term, then click its meaning 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²)drops into place
?drop constantsdrops into place
?Ω vs Odrops into place
?amortised appenddrops into place
?auxiliary spacedrops into place
01Count the loops, not the lines: two nested loops over the same n usually mean O(n²).
02Doubling n doubles O(n) work but quadruples O(n²) work.
03O(log n) barely grows: 8 items → 4 probes, 1,000 → 10, 1,000,000 → 20.
04Big-O is the worst case, Ω the best; Θ names the tight band between them.
05list.append is amortised O(1) — Python over-allocates so most appends touch a single slot.
06Auxiliary space is a second bill: swapping in place is O(1), building a copy is O(n).