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

Subtitles:

Tap a line to see its words.

  1. Way one: look at the names one by one. In the worst case n looks; for a million names, a million looks.
  2. Way two, on a sorted list: look in the middle, throw away the wrong half, repeat. About log₂ n looks.
  3. Since a million lies between 2¹⁹ and 2²⁰, the halving ends after exactly 20 looks.
  4. One method grows like n, the other like log n; the constant does not matter.
  5. Binary search is at most linear search up to a constant, and linear search is at least binary search.
  6. Much more: the ratio of the fast cost to the slow cost tends to zero.
  7. For n at least five the growth orders climb: n, n log n, n squared, 2ⁿ, n factorial.
  8. Trying every order of just 20 names means about 2.4 times ten to the eighteen orders: hopeless.
  9. Sorting by splitting: sort two halves, then merge them in n steps.
  10. 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.

2 Five relatives

Five comparisons of two growing functions. Pair each with what it says.

Tap a line, then its meaning.

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.

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.

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?

6 Unroll it

With T(1) = 0, how large is T(8)?

7 Doubling beats thousands

Doubling at every step: what is the smallest n for which 2ⁿ exceeds a thousand?

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.

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.

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.

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.

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.

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.

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?

15 Three claims, one true

Which of the three statements about this f is true?

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?

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.

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.

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.

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.