Speak Maths · University
Big-O: how fast does the work grow?
Big-O notation compares how fast two quantities grow when n gets large, ignoring constant factors. It is how computer scientists say that one method is hopelessly slower than another.
Draft: written by an AI helper and not yet checked by a teacher.
The alphabet
Read each sign aloud, the way it is written under it.
- Say: f of n is big-O of g of nMeans: f grows no faster than g, up to a constant factor, once n is large.
- Say: f of n is big-theta of g of nMeans: f and g grow at the same rate: f stays between two constant multiples of g.
- Say: f of n is big-omega of g of nMeans: f grows at least as fast as g, up to a constant factor.
- Say: f of n is little-o of g of nMeans: f becomes negligible next to g: the ratio of f to g tends to 0.
- Say: f of n is asymptotic to g of nMeans: f and g are almost equal for large n: the ratio of f to g tends to 1.
- Say: log base two of n, and n times log base two of nMeans: The number of times n can be halved, and that number multiplied by n.
- Say: two to the n, and n factorialMeans: Two fast-growing kinds: doubling at every step, and multiplying by every number up to n.
- Say: T of n equals two times T of n over two, plus nMeans: A recurrence: the cost for size n is two jobs of half the size, plus n extra steps.
The story: Two ways to find a name
Tap a line to see its words.
- Way one: look at the names one by one. In the worst case n looks; for a million names, a million looks.
- Way two, on a sorted list: look in the middle, throw away the wrong half, repeat. About log₂ n looks.
- Since a million lies between 2¹⁹ and 2²⁰, the halving ends after exactly 20 looks.
- One method grows like n, the other like log n; the constant does not matter.
- Binary search is at most linear search up to a constant, and linear search is at least binary search.
- Much more: the ratio of the fast cost to the slow cost tends to zero.
- For n at least five the growth orders climb: n, n log n, n squared, 2ⁿ, n factorial.
- Trying every order of just 20 names means about 2.4 times ten to the eighteen orders: hopeless.
- Sorting by splitting: sort two halves, then merge them in n steps.
- This recurrence solves to a cost of the order n log n, between linear and quadratic.
In words this story is 870 letters long; in symbols, 187.
Read it
What does it say?
Write it
Which notation says this?
f grows at least as fast as g, up to a constant factor.
For large n, f and g are almost equal: their ratio tends to 1.
Binary search on a list of n items needs about log base two of n looks.
n log n grows no faster than n squared, up to a constant.
The costs of the two methods are of the same order.
Binary search: the cost for size n is the cost for half the size, plus one step.
Halving a million down to one takes about twenty steps.
Trying every order of n items costs of the order n factorial.
log n is negligible next to n.
The cost doubles whenever n goes up by one: exponential growth.
For large n the number of steps is almost exactly n squared over two.
Every method for this task needs at least of the order n log n steps.
Build it
Tap the tiles in order. One tile does not belong.
The cost T of n is of the same order as n log n.
The cost for size n is two costs for half the size, plus n.
The cost for size n is the cost for size n minus one, plus n more steps.
n is negligible next to n squared.
The ratio of f to g tends to 1: f and g are asymptotically equal.
Twenty factorial is about 2.4 times ten to the eighteenth.
Challenges
Creative puzzles that use every sign of this chapter. Take your time; there is no clock.
1 The ladder of growth
Six growth rates, each tested against each. Judge each sentence about them.
| ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| ✓ | ✓ | ✓ | ✓ | ✓ | ||
| ✓ | ✓ | ✓ | ✓ | |||
| ✓ | ✓ | ✓ | ||||
| ✓ | ✓ | |||||
| ✓ |
A tick means the row’s function is big-O of the column’s function.
Each rate is O of every rate at or above it on the ladder, and o of every rate strictly above. No rate falls below the bottom rung, log n, so nothing is o of it.
2 Five relatives
Five comparisons of two growing functions. Pair each with what it says.
Tap a line, then its meaning.
They are five different strengths: at most, same rate, at least, negligible, almost equal. Almost equal (ratio tends to 1) is stronger than same rate (ratio stays bounded).
3 The splitting cost
Sorting by splitting costs: two sorts of half the size, plus n steps to merge. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
The two sub-jobs are each of size n/2. Writing 2T(n) would mean two jobs as large as the original, which would never end.
4 Smaller, truly smaller
This should say that n is negligible next to n log n. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
Omega would say n grows at least as fast as n log n, which is false. The ratio of n to n log n tends to 0, which is exactly little-o.
5 Looks in a million
Binary search needs at most this many looks in a sorted list of a million names. What is the number?
Halving a million 19 times still leaves more than one name (2¹⁹ = 524 288 is less than a million); the 20th halving finishes, and 2²⁰ = 1 048 576.
6 Unroll it
With T(1) = 0, how large is T(8)?
T(2) = 2·0 + 2 = 2, T(4) = 2·2 + 4 = 8, T(8) = 2·8 + 8 = 24, which is 8 · log₂ 8, as n log n predicts.
7 Doubling beats thousands
Doubling at every step: what is the smallest n for which 2ⁿ exceeds a thousand?
2⁹ = 512 is too small and 2¹⁰ = 1024 is enough: ten doublings pass a thousand, twenty pass a million.
8 Say who wins
T₁ is the cost of the slow way and T₂ the cost of the fast way. Write that the fast way’s cost is negligible next to the slow way’s.
One way:
Little-o says more than big-O: not just “no worse” but “eventually far better”. The ratio form says the same thing with a limit.
9 What finishes in a second?
A fast computer does about a billion steps a second. Four costs (columns) at four input sizes (rows). The letter n runs over the four sizes. Judge each sentence in this grid.
| ✓ | ✓ | ✓ | ✓ | |
| ✓ | ✓ | ✓ | ||
| ✓ | ✓ | |||
| ✓ |
A tick means that cost, at that n, is at most a billion steps: it finishes within about a second.
Only n log n survives a million. 2ⁿ passes a billion between 20 and 40 (2³⁰ is just above 10⁹), n factorial already at 13. And n² never beats 2ⁿ at these sizes: n² is little-o of 2ⁿ.
10 Almost equal
Six functions, each tested against each. The letters f and g run over the six. Judge each sentence about them.
| ✓ | ✓ | |||||
| ✓ | ✓ | |||||
| ✓ | ||||||
| ✓ | ✓ | ✓ | ||||
| ✓ | ✓ | ✓ | ||||
| ✓ | ✓ | ✓ |
A tick means the row’s function is asymptotic to the column’s: their ratio tends to 1.
Adding a lower-order term keeps the ratio at 1, so n ∼ n + 1 and n² + n ∼ n² ∼ (n + 1)². A constant factor spoils ∼ but not Θ, which is why 2n stands alone in the grid: it is Θ(n) yet asymptotic to nothing else here.
11 Five recurrences
Five ways a cost can depend on smaller cases. Pair each with the order it solves to.
Tap a line, then its meaning.
Shrinking by one gives a chain of n levels; halving gives log n levels. What is added at each level decides the rest: a constant, n, or a doubling.
12 Doubling loses to factorial
This should say that 2 to the n is negligible next to n factorial. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
n factorial multiplies by n at each step, 2 to the n only by 2, so the ratio tends to 0: little-o. Theta would claim the same rate, Omega the reverse, and ∼ a ratio tending to 1; all three are false.
13 Halving a million
This should say how many times a million can be halved before one item is left: about twenty. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
2²⁰ is about 1.05 million, so log₂ of a million is about 19.9. Six would be the logarithm to base 10, and half a million is a single halving, not a count.
14 Looks in a thousand
Binary search: one look, then the same job on half the list; a single item takes one look. How many looks for 1024 items?
T(2) = 2, T(4) = 3, and in general T(2ᵏ) = k + 1. Since 1024 = 2¹⁰, the answer is 11: one more than log₂ n, because the last look at a single item counts too.
15 Three claims, one true
Which of the three statements about this f is true?
The ratio of f to n² tends to 3: bounded above and below, so Θ(n²); not 0, so not little-o; not 1, so not ∼ n². The true asymptotic statement would be f ∼ 3n².
16 Comparing with everyone before
Placing each new card among the cards already sorted takes up to 1 + 2 + … + n comparisons. What order of growth is that sum?
n(n + 1)/2 = n²/2 + n/2, and the n²/2 term wins: the sum stays between two constant multiples of n², so Θ(n²); in fact it is ∼ n²/2.
17 Every pair
Checking every pair among n items for a clash costs about n squared over two checks: of the order n squared. Write it in notation, then compare.
One way:
The number of pairs is n choose 2, which is n(n − 1)/2. Its leading term is n²/2, so the cost is Θ(n²) and, more precisely, asymptotic to n²/2.
18 Never gets harder
Looking up a word in a hash table costs about the same however many words are stored: the cost stays below some fixed bound. Write it in notation, then compare.
One way:
Big-O of a constant says the cost is at most a constant times 1: bounded, whatever n is. Spelled out: there is a bound c that T(n) never exceeds.
19 Say what big-O means
The definition: f is big-O of g when, beyond some starting point, f is never more than a fixed multiple of g. Write it with quantifiers, then compare.
One way:
Two things exist, a constant c and a threshold n₀, and then for all larger n the inequality holds. The order matters: c and n₀ are chosen once and must work for every n after that.
Chapter finished. The symbols are yours.
Tell your own
Describe two ways to do one chore (find a card in a pile, tidy a shelf) with their costs in n, and say which is little-o of the other.
Kept on this device only.