Big-O Playground
Never heard of Big-O? Perfect — start here. A tiny story, then count steps with the computer, then watch real curves grow. No math degree required. 🙌
The big idea
Imagine finding one name in a phone book with 1,000,000 names. You could do it two very different ways — and they are not remotely equally hard.
Here they are, racing through a shorter book of 24 names so you can watch the whole thing:
Both are hunting the same name — 🎯 Tanaka — in the same book, and the book is in alphabetical order (A → Y below).
Read every name
Start at the first name and work down the list, one at a time.
Ready…
Open the middle, drop half
Read the middle name, decide which half the target must be in, and throw the other half away.
Ready…
Why is ⚡ allowed to skip? Because the names are sorted. If the middle name is Lindqvist and you want Tanaka, then every name from A to L is guaranteed to be wrong — no need to read a single one. 🐢 never uses that fact, so it earns nothing from the ordering.
🎯 dashed box = the name we're hunting · 🟨 reading it now · 🟪 read and paid for · ⬜ thrown away unread
The gap only widens. With 24 names it's 20 checks against 5. With 1,000,000 names it's 1,000,000 against ~20.
A race through an alphabetical 24-name phone book, from Abbott to Yilmaz, both searches looking for Tanaka. Reading every name in turn finds it in 20 checks. Repeatedly reading the middle name and discarding the half that cannot contain Tanaka finds it in 5 checks. At 1,000,000 names the same two strategies take 1,000,000 checks and about 20 checks.
Same phone book, same goal — wildly different amounts of work. Big-O is simply the label we put on that difference: it says how the number of steps grows when your data grows.
And n? Nothing scary — n just means “how many items you have”: 10 photos, 1,000 songs, 1,000,000 users.
Say it like this: O(n) reads “oh of en” — the O stands for order of, i.e. “roughly n steps”. That's the whole notation.
Count the steps yourself
Count the steps — with the computer
A step is one tiny action the computer takes. Press play and count along — this is all Big-O ever measures.
Visit every box once — the most honest loop there is.
🟨 where the computer is now · 🟩 already visited · 🟪 the box doing the greeting
The loop
?Try all three — same idea (visit boxes), wildly different step counts. That difference is the whole story of this page. Play each one to the end to unlock its official name 🔓
Put names on the speeds
The speed classes
⚡ Instant — the dream
Same work no matter how big the input.
🧠 Grabbing a book off a shelf when you already know its slot number.
⚙️ What the computer does: Jumps straight to one memory address and reads it — the size of the data never matters.
Seen in: Array index a[k], hash-map lookup, stack push / pop.
🚀 Blazing — barely notices growth
Throws away half the problem every step.
🧠 Finding a word in a dictionary by repeatedly splitting it in half.
⚙️ What the computer does: Each step doubles its reach, so a million items are covered in only ~20 steps.
Seen in: Binary search, balanced-tree lookup, the i *= 2 loop.
🏃 Quick — grows, but lazily
Grows — but far slower than the input does.
🧠 Checking only up to the square root to find a number's factors.
⚙️ What the computer does: Stops at √n because factors pair up: find the small one and the big partner comes free.
Seen in: Trial-division factorisation, primality tests, sqrt decomposition.
🙂 Fair — an honest day's work
Touch each item a constant number of times.
🧠 Reading every name on a guest list once.
⚙️ What the computer does: Walks the data from start to end. Double the data and you double the work.
Seen in: Sum / scan, linear search, counting, a single loop.
✨ Great — the sorting sweet spot
A little work, n times — the sweet spot for sorting.
🧠 Sorting a deck by repeatedly merging already-sorted piles.
⚙️ What the computer does: Does one linear pass at each of the log n levels of splitting.
Seen in: Merge sort, heap sort, quicksort (avg), the digit-print loop.
😬 Risky — fine for small n only
For every item, revisit every item.
🧠 Everyone in a room shaking hands with everyone else.
⚙️ What the computer does: Two nested loops → n × n steps. 10× the data becomes 100× the work.
Seen in: Bubble / selection / insertion sort, all-pairs, nested loops.
💀 Explosive — avoid beyond tiny n
Every new item doubles the total work.
🧠 Trying every on/off combination of n light switches.
⚙️ What the computer does: Branches into two calls at each level — 60 items outlast the age of the universe.
Seen in: Naïve recursive Fibonacci, subset enumeration, brute force.
Play in the sandbox
The sandbox — measure it for real
You just counted steps by hand. Now let your computer do it thousands of times: pick loops below, and each one really runs — we count its steps, or time it with the browser's built-in stopwatch (performance.now()) — and draw the curve.
▸Show the numbers
Want to see an O(n²) algorithm actually move? Step through a sort in the Sorting Visualizer →