Why the Constants Get Dropped
Last timeThe Shape of the Curve
Throwing away constant factors and smaller terms is what makes the comparison portable, and it is also what makes it occasionally wrong. Both halves of that are worth holding.
The last lesson placed procedures on a ladder of shapes and ignored
everything else about them. This lesson says why that is allowed, and then
says where it stops being allowed, because both halves get used.
- the true cost of the procedure on an input of size n
- the simple shape being claimed, such as n or n^2
- a constant that is never stated, which is why the claim says nothing about seconds
- a size beyond which the claim holds, which is why it says nothing about small inputs
Why the constant goes
A factor of a hundred is not small, and the plot still ends with the linear
procedure far ahead. That is the point. A constant shifts the crossing; it
cannot remove it.
It is also the wrong thing to attribute to the procedure in the first place.
The same algorithm in C and in Python differs by a factor of around fifty,
and nobody calls those two different algorithms.
| n squared over 2 | 3n | 40 | largest term as a share | |
|---|---|---|---|---|
| n = 5 | 12.50 | 15.00 | 40.00 | 0.19 |
| n = 50 | 1250.00 | 150.00 | 40.00 | 0.87 |
| n = 1000 | 500000.00 | 3000.00 | 40.00 | 0.99 |
| n = 1000000 | 500000000000.00 | 3000000.00 | 40.00 | 1.00 |
Where this goes wrong
Three situations, all common.
The input never grows. A list that is always under fifty items has no large
case, so the shapes do not matter and the constants are the entire story. A
thousand such lists per second makes the constants matter even more.
The constant is not small. Some procedures with better shapes carry setup
costs so large that no realistic input reaches the crossing point. Several
matrix multiplication methods with better exponents than the schoolbook one
are never used for this reason: the input sizes where they would win do not
fit in any machine.
The shapes are equal. If two procedures are both linear, the growth statement
is silent by construction, and the only remaining instrument is measurement.
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