Skip to content

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 n2n^2 steps takes fewer than one costing 40n40n 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; nn is how many items the input holds. At 10 items, n2n^2 is 100 and 2n2^n 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.

growthits name10 items1001,000a million
1constant1111
log⁡2 n\log_2\, nlogarithmic3.36.610.019.9
nnlinear101001,0001,000,000
n log⁡2 nn \,\log_2\, nnn log nn336649,96619,931,569
n2n^2quadratic10010,0001,000,00013 digits
n3n^3cubic1,0001,000,00010 digits19 digits
2n2^nexponential1,02431 digits302 digits301,030 digits
n!n!factorial3,628,800158 digits2,568 digits5,565,709 digits
Eight ways a count can grow, at four sizes. Logs are rounded to one decimal place and other numbers to whole ones; n log⁡2 nn \,\log_2\, n uses the log unrounded. A number too long to print is given by how many digits it has. n!n!, read nn factorial, multiplies 1 to nn (question 7).

log⁡2 n\log_2\, n, read log to base 2 of nn, counts the halvings that take nn 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.

numberlog× 2+ 110214283164325103.32204.32
Doubling 10 to 20 moves one step right, and its log goes from about 3.32 to about 4.32.

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 multipliedthe numberits calculator log
120.30103
240.60206
380.90309
4161.20412
5321.50515
Each 2 multiplied in adds 0.30103 to the calculator's log.

Each way of growing is a growth class, named in the first table's second column. A class drops any fixed number in front: 40n40n is in the class nn, 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.

102104106108101010121014101610181020101102103104105106107101102103104105106107108109101010111012101310141015101610171018101910201021101102103104105106107
  • log⁡2 n\log_2\, n
  • nn
  • n log⁡2 nn \,\log_2\, n
  • n2n^2
  • n3n^3
Five rungs on a log-log plot, whose scales go up in tens. A higher rung climbs more steeply. 2n2^n and n!n! are too steep to draw: past the top from 70 items and from 22.

Put 300 in place of the 40 in 40n40n, and n2n^2 still passes it, only later: past 300 items, not 40 (question 9). A slower part added on, as 10n10n in n2+10nn^2 + 10n, keeps the rung of n2n^2 (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 nn, 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.

question 1Double the input to 2n2n items. How big is log⁡2(2n)\log_2 (2n)?
  1. the move: start from twice the input

    the line:
    G=log⁡2(2n)G = \log_2 (2n)
    numberlog× 2+ 11644833422211100
    Each halving hops one power down. Four hops take 16 to 1, and its log from 4 to 0.
    halvingsfrom 16from 24
    01624
    1812
    246
    323
    411.5
    50.75
    16 reaches 1 after 4 halvings; 24 passes 1 between the 4th and the 5th.

    why it is allowed: log⁡2 n\log_2\, n counts the halvings that take nn down to 1. Let GG be the halvings that take 2n2n down to 1.

  2. the move: one more halving

    the line:
    G=1+log⁡2 nG = 1 + \log_2\, n

    why it is allowed: Halving 2n2n once gives nn, so 2n2n takes one halving more than nn. 16 takes 4, and 8 takes 3.

  3. the move: read it

    the line:
    twice the inputadds one\begin{gathered} \text{twice the input} \\ \text{adds one} \end{gathered}

    why it is allowed: By line 2, twice the input costs one step more.

try it with a small nn: at n=4n = 4, line 1 gives G=3G = 3, which you can work out by hand

question 2Double the input. How big is n log⁡2 nn \,\log_2\, n then?
  1. the move: put in twice the input

    the line:
    N=2n log⁡2(2n)N = 2n \,\log_2 (2n)

    why it is allowed: Let NN be n log⁡2 nn \,\log_2\, n at twice the input, with 2n2n in place of each nn.

  2. the move: use question 1

    the line:
    N=2n(1+log⁡2 n)N = 2n (1 + \log_2\, n)

    why it is allowed: By line 2 of question 1, log⁡2(2n)\log_2 (2n) is 1+log⁡2 n1 + \log_2\, n.

  3. the move: multiply out the bracket

    the line:
    N=2n+2n log⁡2 nN = 2n + 2n \,\log_2\, n
    itemsn log⁡2 nn \,\log_2\, ntwice that2n2nat twice the items
    4816824
    1,0009,96619,9322,00021,932
    a million19,931,56939,863,1372,000,00041,863,137
    Twice n log⁡2 nn \,\log_2\, n, and 2n2n more, each cell rounded from the unrounded value. The 2n2n is half of twice n log⁡2 nn \,\log_2\, n at 4 items, about a tenth at 1,000 and about a twentieth at a million.

    why it is allowed: 2n2n times 1 is 2n2n, and 2n2n times log⁡2 n\log_2\, n is 2n log⁡2 n2n \,\log_2\, n. At 4 items, 8 and 16 make 24.

  4. the move: read it

    the line:
    for a big input, a littlemore than twice\begin{gathered} \text{for a big input, a little} \\ \text{more than twice} \end{gathered}

    why it is allowed: By line 3, twice n log⁡2 nn \,\log_2\, n and 2n2n more; the table at line 3 shows the 2n2n's share falling as the log grows.

try it with a small nn: at n=4n = 4, line 1 gives N=24N = 24, which you can work out by hand

question 3Double the input. How big is n2n^2 then?
  1. the move: put in twice the input

    the line:
    Q=(2n)2Q = (2n)^2
    itemsn2n^2
    525
    10100
    1,0001,000,000
    2,0004,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 QQ be the square of twice the input.

  2. the move: a square is a number times itself

    the line:
    Q=2n×2nQ = 2n \times 2n

    why it is allowed: Squaring multiplies a number by itself.

  3. the move: multiply the parts

    the line:
    Q=4n2Q = 4n^2

    why it is allowed: The two 2s make 4, and nn times nn is n2n^2.

  4. the move: read it

    the line:
    four times the work\text{four times the work}

    why it is allowed: By line 3, twice the input costs four times as much.

try it with a small nn: at n=4n = 4, line 1 gives Q=64Q = 64, which you can work out by hand

question 4Double the input. How big is n3n^3 then?
  1. the move: put in twice the input

    the line:
    K=(2n)3K = (2n)^3
    itemsn3n^3
    5125
    101,000
    1,0001,000,000,000
    2,0008,000,000,000
    Twice the items, eight times the work. 125 becomes 1,000.

    why it is allowed: Let KK be the cube of twice the input.

  2. the move: a cube is three of a number multiplied

    the line:
    K=2n×2n×2nK = 2n \times 2n \times 2n

    why it is allowed: Cubing multiplies three of a number together.

  3. the move: multiply the parts

    the line:
    K=8n3K = 8n^3

    why it is allowed: The three 2s make 8, and three nns multiplied make n3n^3.

  4. the move: read it

    the line:
    eight times the work\text{eight times the work}

    why it is allowed: By line 3, twice the input costs eight times as much, against four times for n2n^2.

try it with a small nn: at n=4n = 4, line 1 gives K=512K = 512, which you can work out by hand

question 5Double the input. How big is 2n2^n then?
  1. the move: put in twice the input

    the line:
    E=22nE = 2^{2n}
    items2n2^n
    7128
    1416,384
    28268,435,456
    5672,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: 2n2^n multiplies nn twos together. Let EE be it for twice the input, 2n2n twos.

  2. the move: split the twos into two runs

    the line:
    E=2n×2nE = 2^n \times 2^n

    why it is allowed: Split the 2n2n twos into two runs of nn twos; each run multiplies out to 2n2^n.

  3. the move: a number times itself is its square

    the line:
    E=(2n)2E = (2^n)^2

    why it is allowed: Line 2 multiplies 2n2^n by itself.

  4. the move: read it

    the line:
    the work is squared\text{the work is squared}

    why it is allowed: By line 3, twice the input squares the work.

try it with a small nn: at n=4n = 4, line 1 gives E=256E = 256, which you can work out by hand

question 6Add one item to the input. How big is 2n2^n then?
  1. the move: start from one more item

    the line:
    P=2n+1P = 2^{n + 1}

    why it is allowed: Let PP be 2n2^n for one item more, n+1n + 1 twos multiplied together.

  2. the move: take one 2 out of the run

    the line:
    P=2×2nP = 2 \times 2^n
    numberlog× 2+ 110213254283164
    Read each log as the items and its number as the work, 2n2^n. So 2, 3 and 4 items cost 4, 8 and 16. One item more is one step right: twice the work.
    items2n2^n
    101,024
    112,048
    124,096
    201,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 nn multiply out to 2n2^n, and the one set aside doubles that.

  3. the move: read it

    the line:
    one item more doubles the work\text{one item more doubles the work}

    why it is allowed: By line 2, each item more doubles the work.

try it with a small nn: at n=4n = 4, line 1 gives P=32P = 32, which you can work out by hand

question 7Add one item to the input. How big is n!n! then?
  1. the move: start from one more item

    the line:
    F=(n+1)!F = (n + 1)!

    why it is allowed: n!n!, read nn factorial, multiplies every whole number from 1 to nn: 4 factorial is 1 times 2 times 3 times 4, which is 24. Let FF be it for one item more.

  2. the move: take out the last number

    the line:
    F=(n+1)×n!F = (n + 1) \times n!
    itemsn!n!
    36
    424
    5120
    9362,880
    103,628,800
    1139,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: (n+1)!(n + 1)! multiplies the same numbers as n!n!, and n+1n + 1 as well.

  3. the move: read it

    the line:
    one item more multipliesthe work by n+1\begin{gathered} \text{one item more multiplies} \\ \text{the work by } n + 1 \end{gathered}

    why it is allowed: By line 2, one item more multiplies the work by n+1n + 1, a bigger number each time.

try it with a small nn: at n=4n = 4, line 1 gives F=120F = 120, which you can work out by hand

question 8A count of n2+10nn^2 + 10n steps. Which part decides how it grows?
  1. the move: name the count

    the line:
    C=n2+10nC = n^2 + 10n

    why it is allowed: Let CC be the count of a method that looks at all nn items once for each item, then passes over them ten times. At 10 items, 100 and 100 make 200.

  2. the move: a fact for the ceiling

    the line:
    10n≤n210n \le n^2
    items10n10nn2n^2
    55025
    10100100
    20200400
    1001,00010,000
    Below 10 items, 10n10n is the bigger part. From 10 items on, n2n^2 is at least as big.

    why it is allowed: From 10 items on, 10 is at most nn. Multiplying both by nn, which is above zero, keeps 'at most'.

  3. the move: a ceiling

    the line:
    C≤n2+n2C \le n^2 + n^2

    why it is allowed: By line 2, swap the 10n10n in line 1 for n2n^2, which is no smaller.

  4. the move: add like with like

    the line:
    C≤2n2C \le 2n^2

    why it is allowed: n2n^2 and n2n^2 make 2n22n^2. At 10 items both sides are 200.

  5. the move: read it as a bound

    the line:
    C∈O(n2)C \in O(n^2)

    why it is allowed: Big O of n2n^2 is a ceiling: from some size on, at most a fixed number above zero times n2n^2. By line 4, 2 serves from 10 items on. Read C∈O(n2)C \in O(n^2) as CC is in big O of n2n^2.

  6. the move: a floor

    the line:
    C≥n2C \ge n^2
    stepsitems0100200300051015stepsitems0100200300051015
    • the count, n2+10nn^2 + 10n
    • the ceiling of line 4, 2n22n^2
    • the floor of this line, n2n^2
    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 10n10n, which is above zero. What is left is smaller.

  7. the move: read it as a bound

    the line:
    C∈Ω(n2)C \in \Omega(n^2)

    why it is allowed: Big omega of n2n^2 is a floor of the same kind, at least a fixed number above zero times n2n^2. By line 6, as n2n^2 is 1 times n2n^2, 1 serves.

  8. the move: a ceiling and a floor together

    the line:
    C∈Θ(n2)C \in \Theta(n^2)

    why it is allowed: Theta of n2n^2 is such a ceiling and floor together, and lines 5 and 7 give both from 10 items on. So CC grows like n2n^2.

try it with a small nn: at n=10n = 10, line 1 gives C=200C = 200, which you can work out by hand

question 9One method costs 40n40n steps and another n2n^2. From what size does the second cost more?
  1. the move: name the difference

    the line:
    X=n2−40nX = n^2 - 40n
    items40n40nn2n^2XX
    10400100minus 300
    20800400minus 400
    401,6001,6000
    803,2006,4003,200
    2008,00040,00032,000
    Below 40 items XX is below zero. At 40 it is 0, and past 40 it is above zero and growing.

    why it is allowed: Let XX be how many more steps the method costing n2n^2 takes than the one costing 40n40n.

  2. the move: take out the common part

    the line:
    X=n(n−40)X = n(n - 40)
    10210410610810101012101410110210310410510610710110210310410510610710810910101011101210131014101102103104105106107
    • the dearer for long inputs, n2n^2
    • the dearer for short inputs, 40n40n
    • a bigger number in front, 300 times nn
    40n40n and n2n^2 cross at 40 items, and 300 times nn crosses n2n^2 at 300. Past each crossing the gap keeps widening.

    why it is allowed: Both parts of line 1 are nn times something, nn times nn and nn times 40.

  3. the move: read the sign

    the line:
    below 40 items X is below zero,past 40 it is above\begin{gathered} \text{below 40 items } X \text{ is below zero,} \\ \text{past 40 it is above} \end{gathered}

    why it is allowed: nn is above zero, so by line 2 XX is below zero when n−40n - 40 is, under 40 items, and above zero past 40. At 10 items, 10 times minus 30 is minus 300.

  4. the move: read the crossing

    the line:
    they cross at 40 items\text{they cross at 40 items}

    why it is allowed: At 40 items n−40n - 40 is 0, so by line 2 XX is 0: both cost 1,600 steps. By line 3, n2n^2 is the cheaper below 40 and the dearer past it.

  5. the move: read what comes after

    the line:
    once and for good\text{once and for good}

    why it is allowed: Past 40 items, nn and n−40n - 40 are both above zero and grow with each item more. So their product, XX, grows too: the gap only widens.

  6. the move: read it for any number in front

    the line:
    the number in front sets where,never whether\begin{gathered} \text{the number in front sets where,} \\ \text{never whether} \end{gathered}

    why it is allowed: Put 300 for 40 in lines 1 and 2, and line 2's bracket holds nn 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, nn passes it in the end.

try it with a small nn: at n=4n = 4, line 1 gives X=−144X = -144, which you can work out by hand

a worked example

Work out what each count does when 10 items become 20.

  1. Constant: 1 stays 1.
  2. log⁡2 n\log_2\, n: about 3.3 to about 4.3, one more.
  3. nn: 10 to 20, twice.
  4. n log⁡2 nn \,\log_2\, n: about 33 to about 86, twice 33 and 20 more, as question 2 says.
  5. n2n^2: 100 to 400, four times.
  6. n3n^3: 1,000 to 8,000, eight times.
  7. 2n2^n: 1,024 to 1,048,576, squared.
  8. n!n!: 3,628,800 to 2,432,902,008,176,640,000. 3,628,800 squared is only 13,168,189,440,000, so n!n! does more than square.

the trap

check yourself

  1. 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 n2n^2: twice the items made four times the work, as question 3 works out. The count is n2n^2 divided by 50, which is n2n^2 times one fiftieth, a number in front, set aside.

  2. Which costs fewer steps for 20 items, a method costing 40n40n or one costing n2n^2? And for 100 items?

    the answer

    For 20 items, the one costing n2n^2, 400 steps against 800. For 100 items, the one costing 40n40n, 4,000 against 10,000. They cross at 40 items.

  3. Which is bigger at 20 items, n2+10nn^2 + 10n or 2n2^n, and what does one item more do to each?

    the answer

    2n2^n, 1,048,576 against 600. At 21 items n2+10nn^2 + 10n is 651, only 51 more, while 2n2^n doubles to 2,097,152, as question 6 works out.