When Counting Explodes
Last timeMore Things Than Places
Polynomial, exponential and factorial counts separate so violently that the gap decides what can be computed at all, and no faster machine closes it.
Every count in this course has been a number. This lesson is about what those
numbers rule out, which turns counting from arithmetic into a statement about
what can be done at all.
| n cubed | two to the n | n factorial | feasible to enumerate? | |
|---|---|---|---|---|
| n = 5 | 2.1 | 1.5 | 2.1 | 1.0 |
| n = 10 | 3.0 | 3.0 | 6.6 | 1.0 |
| n = 20 | 3.9 | 6.0 | 18.4 | 0.0 |
| n = 30 | 4.4 | 9.0 | 32.4 | 0.0 |
| n = 50 | 5.1 | 15.1 | 64.5 | 0.0 |
| n = 100 | 6.0 | 30.1 | 157.9 | 0.0 |
The ceiling, in numbers worth remembering
A fast machine checks something like a thousand million simple possibilities a
second. A year has about three times ten to the seven seconds. So a year of
computation gets through about ten to the sixteen possibilities, and that is
the honest ceiling with a generous machine and no cleverness.
Three anchors follow from that, and they are worth memorising because they turn
a count into a decision.
Up to about ten to the twelve is routine, meaning minutes to hours. Around ten
to the sixteen is a serious project needing real hardware and patience. Beyond
about ten to the eighteen, enumeration is finished, and no budget changes that.
So the judgement is: take the logarithm of the count, compare against twelve,
sixteen and eighteen, and decide whether to write the loop at all. That is a
five second calculation and it is the most useful thing in this course.
| step | the search | items done in a day now | with a machine a thousand times faster | what the speedup bought |
|---|---|---|---|---|
| 1 | n cubed | about 44000 items | about 440000 items | ten times the items |
| 2 | two to the n | about 46 items | about 56 items | ten more items |
| 3 | n factorial | about 18 items | about 21 items | three more items |
The three remaining moves
Once a space cannot be enumerated, there are exactly three things to do, and
the rest of the library is largely about them.
Exploit structure. Prove that most of the space cannot contain the answer and
never visit it. Finding a name in a sorted list of a million does not examine a
million entries, it examines twenty, because sortedness lets each comparison
discard half the space. That halving is the logarithm again, and it is the
single most profitable structure in computing.
Settle for good rather than best. Accept an answer that is provably within some
distance of the best one, or merely one that works, in exchange for finishing.
Most routing, packing and scheduling in production is this, and the honest
version of it always states what it gave up.
Sample. Look at a random part of the space and accept a statistical answer.
This is what training a model on a sample of data is, what a randomised
algorithm is, and what every poll is. It is also why the course on samples
exists, since a sampled answer needs a statement about how wrong it might be.
The lesson stops here
1 more paragraph to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents