growth and the growth ladder
counting the cost
what it is
How fast a count grows can matter more than a fixed number in front of it. A method costing steps takes fewer than one costing up to 39 items, and more for good past 40.
Cost here is a count of basic steps, as on the page counting basic steps; is how many items the input holds. At 10 items, is 100 and is 1,024; at 100 items, 10,000 and a number 31 digits long. The table shows eight ways a count can grow, slowest first.
| growth | its name | 10 items | 100 | 1,000 | a million |
|---|---|---|---|---|---|
| 1 | constant | 1 | 1 | 1 | 1 |
| logarithmic | 3.3 | 6.6 | 10.0 | 19.9 | |
| linear | 10 | 100 | 1,000 | 1,000,000 | |
| log | 33 | 664 | 9,966 | 19,931,569 | |
| quadratic | 100 | 10,000 | 1,000,000 | 13 digits | |
| cubic | 1,000 | 1,000,000 | 10 digits | 19 digits | |
| exponential | 1,024 | 31 digits | 302 digits | 301,030 digits | |
| factorial | 3,628,800 | 158 digits | 2,568 digits | 5,565,709 digits |
, read log to base 2 of , counts the halvings that take down to 1. 16 is four 2s multiplied, 2 to the power 4. Halving gives 8, 4, 2 and 1, one 2 fewer each time: four halvings, so its log is 4. Doubling a number adds one halving, so it adds 1 to its log.
Halving 24 leaves 1.5 after 4 halvings and 0.75 after 5 (question 1). So its log, the power of 2 that makes 24, lies between 4 and 5.
A calculator's log key gives the power of 10 instead: 2 for 100, which is 10 times 10, and about 0.30103 for 2. Multiplying powers of 10 adds the powers: 10 times 100 is 10 to the power 3. So each 2 multiplied in adds 0.30103, as the table below shows, and 100 needs 2 divided by 0.30103 of them: about 6.64, the first table's 6.6. Powers between whole numbers follow the same rules; take that on trust.
| 2s multiplied | the number | its calculator log |
|---|---|---|
| 1 | 2 | 0.30103 |
| 2 | 4 | 0.60206 |
| 3 | 8 | 0.90309 |
| 4 | 16 | 1.20412 |
| 5 | 32 | 1.50515 |
Each way of growing is a growth class, named in the first table's second column. A class drops any fixed number in front: is in the class , and 5 steps whatever the input, 5 times 1, is in the constant class, written 1. In order, the classes make the growth ladder, each a rung. A higher rung grows faster: a row further down the table.
Put 300 in place of the 40 in , and still passes it, only later: past 300 items, not 40 (question 9). A slower part added on, as in , keeps the rung of (question 8).
where the formulas come from
Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about , or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.
the move: start from twice the input
the line:Each halving hops one power down. Four hops take 16 to 1, and its log from 4 to 0. halvings from 16 from 24 0 16 24 1 8 12 2 4 6 3 2 3 4 1 1.5 5 0.75 16 reaches 1 after 4 halvings; 24 passes 1 between the 4th and the 5th. why it is allowed: counts the halvings that take down to 1. Let be the halvings that take down to 1.
the move: one more halving
the line:why it is allowed: Halving once gives , so takes one halving more than . 16 takes 4, and 8 takes 3.
guess it, thenthe move: read it
the line:why it is allowed: By line 2, twice the input costs one step more.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: put in twice the input
the line:why it is allowed: Let be at twice the input, with in place of each .
the move: use question 1
the line:why it is allowed: By line 2 of question 1, is .
guess it, thenthe move: multiply out the bracket
the line:items twice that at twice the items 4 8 16 8 24 1,000 9,966 19,932 2,000 21,932 a million 19,931,569 39,863,137 2,000,000 41,863,137 Twice , and more, each cell rounded from the unrounded value. The is half of twice at 4 items, about a tenth at 1,000 and about a twentieth at a million. why it is allowed: times 1 is , and times is . At 4 items, 8 and 16 make 24.
guess it, thenthe move: read it
the line:why it is allowed: By line 3, twice and more; the table at line 3 shows the 's share falling as the log grows.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: put in twice the input
the line:items 5 25 10 100 1,000 1,000,000 2,000 4,000,000 Twice the items, four times the work. 25 becomes 100, and 1,000,000 becomes 4,000,000. why it is allowed: Let be the square of twice the input.
the move: a square is a number times itself
the line:why it is allowed: Squaring multiplies a number by itself.
guess it, thenthe move: multiply the parts
the line:why it is allowed: The two 2s make 4, and times is .
guess it, thenthe move: read it
the line:why it is allowed: By line 3, twice the input costs four times as much.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: put in twice the input
the line:items 5 125 10 1,000 1,000 1,000,000,000 2,000 8,000,000,000 Twice the items, eight times the work. 125 becomes 1,000. why it is allowed: Let be the cube of twice the input.
the move: a cube is three of a number multiplied
the line:why it is allowed: Cubing multiplies three of a number together.
guess it, thenthe move: multiply the parts
the line:why it is allowed: The three 2s make 8, and three s multiplied make .
guess it, thenthe move: read it
the line:why it is allowed: By line 3, twice the input costs eight times as much, against four times for .
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: put in twice the input
the line:items 7 128 14 16,384 28 268,435,456 56 72,057,594,037,927,936 Each doubling of the items squares the work. 128 times 128 is 16,384, and 16,384 times 16,384 is 268,435,456. why it is allowed: multiplies twos together. Let be it for twice the input, twos.
the move: split the twos into two runs
the line:why it is allowed: Split the twos into two runs of twos; each run multiplies out to .
guess it, thenthe move: a number times itself is its square
the line:why it is allowed: Line 2 multiplies by itself.
guess it, thenthe move: read it
the line:why it is allowed: By line 3, twice the input squares the work.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: start from one more item
the line:why it is allowed: Let be for one item more, twos multiplied together.
the move: take one 2 out of the run
the line:Read each log as the items and its number as the work, . So 2, 3 and 4 items cost 4, 8 and 16. One item more is one step right: twice the work. items 10 1,024 11 2,048 12 4,096 20 1,048,576 One item more, twice the work. Ten items more, 1,024 times the work. why it is allowed: Set one of the twos aside. The other multiply out to , and the one set aside doubles that.
guess it, thenthe move: read it
the line:why it is allowed: By line 2, each item more doubles the work.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: start from one more item
the line:why it is allowed: , read factorial, multiplies every whole number from 1 to : 4 factorial is 1 times 2 times 3 times 4, which is 24. Let be it for one item more.
the move: take out the last number
the line:items 3 6 4 24 5 120 9 362,880 10 3,628,800 11 39,916,800 One item more multiplies by the new count of items. 6 times 4 is 24, and 3,628,800 times 11 is 39,916,800. why it is allowed: multiplies the same numbers as , and as well.
guess it, thenthe move: read it
the line:why it is allowed: By line 2, one item more multiplies the work by , a bigger number each time.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: name the count
the line:why it is allowed: Let be the count of a method that looks at all items once for each item, then passes over them ten times. At 10 items, 100 and 100 make 200.
the move: a fact for the ceiling
the line:items 5 50 25 10 100 100 20 200 400 100 1,000 10,000 Below 10 items, is the bigger part. From 10 items on, is at least as big. why it is allowed: From 10 items on, 10 is at most . Multiplying both by , which is above zero, keeps 'at most'.
guess it, thenthe move: a ceiling
the line:why it is allowed: By line 2, swap the in line 1 for , which is no smaller.
guess it, thenthe move: add like with like
the line:why it is allowed: and make . At 10 items both sides are 200.
guess it, thenthe move: read it as a bound
the line:why it is allowed: Big O of is a ceiling: from some size on, at most a fixed number above zero times . By line 4, 2 serves from 10 items on. Read as is in big O of .
guess it, thenthe move: a floor
the line:- the count,
- the ceiling of line 4,
- the floor of this line,
The count against its ceiling and its floor, 1 to 12 items. Below 10 items it is above the ceiling; from 10 items on it stays between the two. why it is allowed: Line 1 without the , which is above zero. What is left is smaller.
guess it, thenthe move: read it as a bound
the line:why it is allowed: Big omega of is a floor of the same kind, at least a fixed number above zero times . By line 6, as is 1 times , 1 serves.
guess it, thenthe move: a ceiling and a floor together
the line:why it is allowed: Theta of is such a ceiling and floor together, and lines 5 and 7 give both from 10 items on. So grows like .
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: name the difference
the line:items 10 400 100 minus 300 20 800 400 minus 400 40 1,600 1,600 0 80 3,200 6,400 3,200 200 8,000 40,000 32,000 Below 40 items is below zero. At 40 it is 0, and past 40 it is above zero and growing. why it is allowed: Let be how many more steps the method costing takes than the one costing .
the move: take out the common part
the line:- the dearer for long inputs,
- the dearer for short inputs,
- a bigger number in front, 300 times
and cross at 40 items, and 300 times crosses at 300. Past each crossing the gap keeps widening. why it is allowed: Both parts of line 1 are times something, times and times 40.
guess it, thenthe move: read the sign
the line:why it is allowed: is above zero, so by line 2 is below zero when is, under 40 items, and above zero past 40. At 10 items, 10 times minus 30 is minus 300.
guess it, thenthe move: read the crossing
the line:why it is allowed: At 40 items is 0, so by line 2 is 0: both cost 1,600 steps. By line 3, is the cheaper below 40 and the dearer past it.
guess it, thenthe move: read what comes after
the line:why it is allowed: Past 40 items, and are both above zero and grow with each item more. So their product, , grows too: the gap only widens.
guess it, thenthe move: read it for any number in front
the line:why it is allowed: Put 300 for 40 in lines 1 and 2, and line 2's bracket holds less 300: below zero up to 299 items, 0 at 300, above zero past it. At 20 items, 20 times minus 280 is minus 5,600. Whatever the number, passes it in the end.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
a worked example
Work out what each count does when 10 items become 20.
- Constant: 1 stays 1.
- : about 3.3 to about 4.3, one more.
- : 10 to 20, twice.
- : about 33 to about 86, twice 33 and 20 more, as question 2 says.
- : 100 to 400, four times.
- : 1,000 to 8,000, eight times.
- : 1,024 to 1,048,576, squared.
- : 3,628,800 to 2,432,902,008,176,640,000. 3,628,800 squared is only 13,168,189,440,000, so does more than square.
the trap
check yourself
A count is 5,000 steps at 500 items and about 20,000 at 1,000 items. How is it most likely growing?
the answer
Like : twice the items made four times the work, as question 3 works out. The count is divided by 50, which is times one fiftieth, a number in front, set aside.
Which costs fewer steps for 20 items, a method costing or one costing ? And for 100 items?
the answer
For 20 items, the one costing , 400 steps against 800. For 100 items, the one costing , 4,000 against 10,000. They cross at 40 items.
Which is bigger at 20 items, or , and what does one item more do to each?
the answer
, 1,048,576 against 600. At 21 items is 651, only 51 more, while doubles to 2,097,152, as question 6 works out.