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.
| step | items | what the procedure really costs | n squared, the shape claimed for it | multiples of n squared needed to cover that | what happened |
|---|---|---|---|---|---|
| 1 | 5 | 67.5 steps, being 12.5 and 15 and 40 | 25 | 2.7 times | At five items the real cost is nearly three times the shape claimed for it, so a ceiling of one n squared is simply false here. Every growth claim therefore comes with a size below which it is not being made at all. |
| 2 | 50 | 1,440 steps, being 1,250 and 150 and 40 | 2,500 | 0.58 times | One size up and the multiple has fallen below one. From here on, 0.58 of an n squared covers this procedure at every size there will ever be, which is the whole of what the claim promises. |
| 3 | 1,000 | 503,040 steps, being 500,000 and 3,000 and 40 | 1,000,000 | 0.503 times | The multiple is still falling and it is clearly going somewhere. Where it is going is the coefficient on the leading term, because the other two terms are on their way to nothing. |
| 4 | 1,000,000 | 500,003,000,040 steps, being 500,000,000,000 and 3,000,000 and 40 | 1,000,000,000,000 | 0.5 times | Half an n squared, to five places. The claim was true from fifty items onward with one fixed multiple, and that is the only thing it was ever asserting. |
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 of the total | |
|---|---|---|---|---|
| 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