Skip to content

log-log plots and slopes

counting the cost

what it is

Each mark on a log-log plot is ten times the last. A count of n2n^2 climbs 2 marks for each mark across, slope 2, its power. Doubling the input multiplies it by 4, 2 × 2.

Counts run from a few steps to trillions. On ordinary scales the small ones lie along the floor, as below. So the learn pages' plots space 10, 100, 1,000 and on evenly, across for nn, the items, and up for the count. Each is a mark, and such a plot is log-log.

countitems0200,000400,000600,000800,0001,000,00002004006008001,000countitems0200,000400,000600,000800,0001,000,00002004006008001,000
  • n2n^2
  • nn
n2n^2 and nn on ordinary scales, to 1,000 items. nn lies along the floor.
10210410610810101012101410110210310410510610710110210310410510610710810910101011101210131014101102103104105106107
  • n2n^2, slope 2
  • nn, slope 1
The same two counts, log-log, 10 items to ten million: 6 marks across, n2n^2 climbs 12 and nn climbs 6. A mark up is drawn shorter, and a narrow plot labels every other one.

A number stands at its log to base 10, written log⁡10\log_{10}: the power you raise 10 to, to make it. 1,000 is 10 × 10 × 10, so it stands at mark 3, and 1 at 0, as 10 to the power 0 is 1. 2 stands about 0.301 up, as 10 to the power 0.301 is about 2. A calculator's log key gives logs like this one; take powers between whole numbers on trust. Log means base 10 here, unless it says log⁡2\log_2.

numberlog1010110021,000320.301201.3012002.301
Logs to base 10. 2, 20 and 200 each stand 0.301 past a mark.

Multiply by 10 and a number moves one mark, wherever it starts: 2 to 20, then 200. Multiply by 2 and it moves about 0.301; by 4, twice that, about 0.602. Equal distances mean equal multiples (question 1).

The slope of a line is the marks it climbs for each mark across. A count of n2n^2 is 100 at 10 items, 10,000 at 100 and 1,000,000 at 1,000: 2, 4 and 6 marks up, for 1, 2 and 3 across. That is a straight line of slope 2 (question 2). The power, how many nns are multiplied together, is its slope: nn climbs 1 and n3n^3 climbs 3 (question 4).

The doubling test measures a count at some size and at twice it, and divides: the doubling ratio. For n2n^2, 10 items to 20 moves 0.301 across, and 100 to 400 climbs 0.602, twice as far: slope 2. For any ratio, divide its log by the log of 2 (question 3).

the countat 10 itemsat 20 itemsthe doubling ratiothe slope
nn102021
n2n^210040042
n3n^31,0008,00083
Ratios of one, two and three 2s give slopes 1, 2 and 3.

A number in front above 1, as in 10n210n^2, lifts the line by the same distance all the way, here one mark: parallel, slope 2 (question 5). A slower part, as the 10n10n in n2+10nn^2 + 10n, bends it where inputs are small; by 1,000 items its slope is within 0.01 of 2 (question 6).

102104106108101010121014101102103104105106107101102103104105106107108109101010111012101310141015101102103104105106107
  • n2n^2
  • 10n210n^2, one mark higher
  • n2+10nn^2 + 10n, bent at first
10n210n^2 runs one mark above n2n^2. n2+10nn^2 + 10n starts twice n2n^2 at 10 items, then joins it.

n log⁡2 nn \,\log_2\, n has no single power: at 4 items it is 4 × 2, at 16 items 16 × 4. Its second factor grows, far more slowly than nn. Its slope falls toward 1 so slowly that it is still 1.07 at about a million items (question 7).

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 1Multiply a number by 10, or by 2. How far does it move?
  1. the move: name the distance

    the line:
    M=log⁡10(10n)−log⁡10 nM = \log_{10} (10n) - \log_{10}\, n
    a numberwhere it standsten times itwhere that stands
    10101
    20.301201.301
    40.602401.602
    80.903801.903
    501.6995002.699
    Logs to three places. Each doubling adds about 0.301; ten times adds exactly 1.

    why it is allowed: Here nn is any number above zero, standing at log⁡10 n\log_{10}\, n. Let MM be how far 10n10n stands from it.

  2. the move: multiplying adds the logs

    the line:
    log⁡10(10n)=log⁡10 10+log⁡10 n\log_{10} (10n) = \log_{10}\, 10 + \log_{10}\, n

    why it is allowed: With numbers: 10 times 100 is 1,000, and the logs 1 and 2 add to 3, its log. Every number above zero is 10 to the power of its log, so multiplying two adds their powers, their logs.

  3. the move: use line 2

    the line:
    M=log⁡10 10+log⁡10 n−log⁡10 nM = \log_{10}\, 10 + \log_{10}\, n - \log_{10}\, n

    why it is allowed: Line 2 put into line 1.

  4. the move: cancel

    the line:
    M=log⁡10 10M = \log_{10}\, 10

    why it is allowed: log⁡10 n\log_{10}\, n added and taken away leaves nothing.

  5. the move: one ten

    the line:
    M=1M = 1

    why it is allowed: 10 is 10 to the power 1.

  6. the move: the same rule with 2

    the line:
    log⁡10(2n)=log⁡10 2+log⁡10 n\log_{10} (2n) = \log_{10}\, 2 + \log_{10}\, n

    why it is allowed: Line 2, for 2 times nn. log⁡10 2\log_{10}\, 2 is about 0.301.

  7. the move: read it

    the line:
    one mark for ten times,about 0.301 of one for twice\begin{gathered} \text{one mark for ten times,} \\ \text{about 0.301 of one for twice} \end{gathered}

    why it is allowed: Line 5 has no nn: times 10 moves any number one mark. By line 6, times 2 moves it about 0.301. Any fixed multiple moves a fixed distance, its log. And back: a number one mark higher is ten times it, since each place holds one number.

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

question 2Where does a count of n2n^2 stand?
  1. the move: name the height

    the line:
    H=log⁡10 n2H = \log_{10}\, n^2
    itemsthe countmarks acrossmarks up
    1010012
    10010,00024
    1,0001,000,00036
    Each row down is one mark across and two up.

    why it is allowed: The input stands log⁡10 n\log_{10}\, n across, and the count at its own log, up. Let HH be that height, the log of the whole square.

  2. the move: write the square out

    the line:
    H=log⁡10(n×n)H = \log_{10} (n \times n)

    why it is allowed: Two nns multiplied together.

  3. the move: multiplying adds the logs

    the line:
    H=log⁡10 n+log⁡10 nH = \log_{10}\, n + \log_{10}\, n

    why it is allowed: Line 2 of question 1, for nn times nn.

  4. the move: add like with like

    the line:
    H=2 log⁡10 nH = 2 \,\log_{10}\, n

    why it is allowed: Two lots of log⁡10 n\log_{10}\, n.

  5. the move: read it

    the line:
    twice as far up as across:a straight line of slope 2\begin{gathered} \text{twice as far up as across:} \\ \text{a straight line of slope 2} \end{gathered}

    why it is allowed: By line 4, twice as far up as across at every size. So the points lie on one straight line, 2 marks up for each mark across.

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

question 3Double the input for n2n^2. What slope does that show?
  1. the move: name the slope

    the line:
    P=log⁡10((2n)2)−log⁡10 n2log⁡10(2n)−log⁡10 nP = \frac{\log_{10} \left((2n)^2\right) - \log_{10}\, n^2}{\log_{10} (2n) - \log_{10}\, n}
    itemswhere they standthe countwhere it stands
    1011002
    201.3014002.602
    the move0.301 across4 times0.602 up
    10 items to 20, logs to three places. The count climbs twice as far.

    why it is allowed: From nn items to 2n2n, the count climbs from n2n^2 to (2n)2(2n)^2, while the input moves from nn to 2n2n. Let PP be the climb over the move.

  2. the move: write the square out

    the line:
    (2n)2=2n×2n(2n)^2 = 2n \times 2n

    why it is allowed: To square is to multiply a number by itself.

  3. the move: multiply the parts

    the line:
    2n×2n=4n22n \times 2n = 4n^2

    why it is allowed: 2 times 2 times nn times nn, in any order.

  4. the move: use lines 2 and 3

    the line:
    P=log⁡10(4n2)−log⁡10 n2log⁡10(2n)−log⁡10 nP = \frac{\log_{10} (4n^2) - \log_{10}\, n^2}{\log_{10} (2n) - \log_{10}\, n}

    why it is allowed: By lines 2 and 3, (2n)2(2n)^2 is 4n24n^2.

  5. the move: multiplying adds the logs

    the line:
    P=log⁡10 4+log⁡10 n2−log⁡10 n2log⁡10 2+log⁡10 n−log⁡10 nP = \frac{\log_{10}\, 4 + \log_{10}\, n^2 - \log_{10}\, n^2}{\log_{10}\, 2 + \log_{10}\, n - \log_{10}\, n}

    why it is allowed: On top, line 2 of question 1, for 4 times n2n^2; below, line 6 of question 1.

  6. the move: cancel

    the line:
    P=log⁡10 4log⁡10 2P = \frac{\log_{10}\, 4}{\log_{10}\, 2}

    why it is allowed: log⁡10 n2\log_{10}\, n^2 and log⁡10 n\log_{10}\, n are each added and taken away.

  7. the move: 4 is 2 times 2

    the line:
    P=log⁡10(2×2)log⁡10 2P = \frac{\log_{10} (2 \times 2)}{\log_{10}\, 2}

    why it is allowed: The same number, written another way.

  8. the move: multiplying adds the logs

    the line:
    P=log⁡10 2+log⁡10 2log⁡10 2P = \frac{\log_{10}\, 2 + \log_{10}\, 2}{\log_{10}\, 2}

    why it is allowed: Line 2 of question 1, for 2 times 2.

  9. the move: add like with like

    the line:
    P=2 log⁡10 2log⁡10 2P = \frac{2 \,\log_{10}\, 2}{\log_{10}\, 2}

    why it is allowed: Two lots of log⁡10 2\log_{10}\, 2.

  10. the move: divide

    the line:
    P=2P = 2
    numberlog2s1010120.301140.602280.9033
    Ratios 2, 4 and 8, their logs, and each log over 0.301 in blue, the slope.

    why it is allowed: log⁡10 2\log_{10}\, 2 is about 0.301, not zero, and goes into twice itself twice.

  11. the move: read it for any count

    the line:
    the slope: the log of the doublingratio, over the log of 2\begin{gathered} \text{the slope: the log of the doubling} \\ \text{ratio, over the log of 2} \end{gathered}

    why it is allowed: At twice the input, a count is the ratio times its count at nn, so it climbs the log of the ratio (line 2 of question 1). The input moves log⁡10 2\log_{10}\, 2 (line 6 of question 1). The slope is the climb over the move: a ratio of 8, 2 × 2 × 2, gives slope 3, as lines 6 to 10 do for 4.

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

question 4Where does a count of n3n^3 stand, and any power?
  1. the move: name the height

    the line:
    E=log⁡10 n3E = \log_{10}\, n^3

    why it is allowed: Let EE be its height at nn items.

  2. the move: write the cube out

    the line:
    E=log⁡10(n×n×n)E = \log_{10} (n \times n \times n)

    why it is allowed: Three nns multiplied together.

  3. the move: multiplying adds the logs

    the line:
    E=log⁡10 n+log⁡10 n+log⁡10 nE = \log_{10}\, n + \log_{10}\, n + \log_{10}\, n

    why it is allowed: Line 2 of question 1, used twice.

  4. the move: add like with like

    the line:
    E=3 log⁡10 nE = 3 \,\log_{10}\, n
    102104106108101010121014101610181020101102103104105106107101102103104105106107108109101010111012101310141015101610171018101910201021101102103104105106107
    • n3n^3, slope 3
    • n2n^2, slope 2
    • nn, slope 1
    Each climbs its power in marks for each mark across; from 10 items to ten million, n3n^3 climbs 18.

    why it is allowed: Three lots of log⁡10 n\log_{10}\, n.

  5. the move: write the cube out

    the line:
    (2n)3=2n×2n×2n(2n)^3 = 2n \times 2n \times 2n

    why it is allowed: To cube is to multiply three of a number together.

  6. the move: multiply the parts

    the line:
    2n×2n×2n=8n32n \times 2n \times 2n = 8n^3

    why it is allowed: Three 2s make 8, and three nns make n3n^3. At 10 items, 1,000; at 20, 8,000.

  7. the move: read it

    the line:
    three times as far up as across:slope 3\begin{gathered} \text{three times as far up as across:} \\ \text{slope 3} \end{gathered}

    why it is allowed: By line 4, a straight line of slope 3, as in question 2. By line 6, a doubling ratio of 8, three 2s, so slope 3 by question 3 too.

  8. the move: read it for any power

    the line:
    each poweris its own slope\begin{gathered} \text{each power} \\ \text{is its own slope} \end{gathered}

    why it is allowed: Each nn multiplied in adds one log⁡10 n\log_{10}\, n to the height, as in lines 2 to 4. So the power is the slope.

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

question 510n210n^2 against n2n^2. How far apart are their lines?
  1. the move: name the gap

    the line:
    G=log⁡10(10n2)−log⁡10 n2G = \log_{10} (10n^2) - \log_{10}\, n^2
    itemsn2n^210n210n^2marks apart
    101001,0001
    10010,000100,0001
    1,0001,000,00010,000,0001
    Each 10n210n^2 is ten times the n2n^2 beside it, so one mark higher.

    why it is allowed: Each line stands at its count's log. Let GG be the marks between them.

  2. the move: multiplying adds the logs

    the line:
    G=log⁡10 10+log⁡10 n2−log⁡10 n2G = \log_{10}\, 10 + \log_{10}\, n^2 - \log_{10}\, n^2

    why it is allowed: Line 2 of question 1, with n2n^2 for nn.

  3. the move: cancel

    the line:
    G=log⁡10 10G = \log_{10}\, 10

    why it is allowed: log⁡10 n2\log_{10}\, n^2 added and taken away leaves nothing.

  4. the move: one ten

    the line:
    G=1G = 1

    why it is allowed: As in line 5 of question 1.

  5. the move: read it

    the line:
    one mark apart at every size,so parallel lines\begin{gathered} \text{one mark apart at every size,} \\ \text{so parallel lines} \end{gathered}

    why it is allowed: Line 4 has no nn: one mark apart all along, so parallel, both slope 2. With 5 in front, the gap is the log of 5, about 0.699.

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

question 6Double the input for n2+10nn^2 + 10n. How does the slope change?
  1. the move: name the doubling ratio

    the line:
    D=(2n)2+10×2nn2+10nD = \frac{(2n)^2 + 10 \times 2n}{n^2 + 10n}
    102104106108101010121014101102103104105106107101102103104105106107108109101010111012101310141015101102103104105106107
    • the count, n2+10nn^2 + 10n
    • n2n^2
    • the slower part, 10n10n
    The count starts above n2n^2 and joins it as 10n10n falls behind.
    itemsn2n^210n10nthe count
    10100100200
    10010,0001,00011,000
    1,0001,000,00010,0001,010,000
    10n10n is all of n2n^2 at 10 items, a tenth at 100, a hundredth at 1,000.

    why it is allowed: Let DD be the count at 2n2n items over the count at nn. At 10 items it is 200, at 20 it is 600, so DD is 3.

  2. the move: multiply out the top

    the line:
    D=4n2+20nn2+10nD = \frac{4n^2 + 20n}{n^2 + 10n}

    why it is allowed: (2n)2(2n)^2 is 4n24n^2 by lines 2 and 3 of question 3, and 10 times 2n2n is 20n20n.

  3. the move: fit the bottom into the top

    the line:
    D=4(n2+10n)−20nn2+10nD = \frac{4(n^2 + 10n) - 20n}{n^2 + 10n}

    why it is allowed: Write the top of line 2 as 4 times the bottom, less something. 4(n2+10n)4(n^2 + 10n) is 4n24n^2 and 40n40n, so take 20n20n away. At 10 items, 4 × 200 less 20 × 10 is 600.

  4. the move: divide each part

    the line:
    D=4(n2+10n)n2+10n−20nn2+10nD = \frac{4(n^2 + 10n)}{n^2 + 10n} - \frac{20n}{n^2 + 10n}

    why it is allowed: A difference over a number is each part over it, one less the other.

  5. the move: cancel

    the line:
    D=4−20nn2+10nD = 4 - \frac{20n}{n^2 + 10n}

    why it is allowed: n2+10nn^2 + 10n is above zero, so it cancels, leaving 4.

  6. the move: divide top and bottom by n

    the line:
    D=4−20n+10D = 4 - \frac{20}{n + 10}
    itemsthe doubling ratiothe slope
    52.671.42
    1031.58
    1003.821.93
    1,0003.981.99
    10,0003.9981.999
    Line 6 at five sizes, rounded; each slope by question 3.

    why it is allowed: Top and bottom over nn, above zero. 20n20n becomes 20, and n2+10nn^2 + 10n becomes n+10n + 10.

  7. the move: a ceiling

    the line:
    D≤4D \le 4

    why it is allowed: By line 6, 4 less something above zero.

  8. the move: read it

    the line:
    the slope climbstoward 2\begin{gathered} \text{the slope climbs} \\ \text{toward 2} \end{gathered}

    why it is allowed: As nn grows, 20 over n+10n + 10 shrinks toward zero. So by line 6 DD climbs toward 4, and the slope toward 2 (question 3): 1.58 at 10 items, 1.99 at 1,000.

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

question 7Double the input for n log⁡2 nn \,\log_2\, n. What is the doubling ratio?
  1. the move: name the doubling ratio

    the line:
    K=2n log⁡2(2n)n log⁡2 nK = \frac{2n \,\log_2 (2n)}{n \,\log_2\, n}

    why it is allowed: Let KK be the count at 2n2n items over the count at nn. At 4 items it is 8, at 8 it is 24, so KK is 3. From 2 items on, log⁡2 n\log_2\, n is above zero, so dividing by it is safe.

  2. the move: use the growth ladder

    the line:
    K=2n+2n log⁡2 nn log⁡2 nK = \frac{2n + 2n \,\log_2\, n}{n \,\log_2\, n}
    where does this come from?
    question 2 of the page growth and the growth ladderDouble 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 of the page growth and the growth ladder, 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.

    the whole page: growth and the growth ladder

    why it is allowed: On the page growth and the growth ladder, question 2 works out 2n log⁡2(2n)2n \,\log_2 (2n) as 2n+2n log⁡2 n2n + 2n \,\log_2\, n.

  3. the move: divide top and bottom by n

    the line:
    K=2+2 log⁡2 nlog⁡2 nK = \frac{2 + 2 \,\log_2\, n}{\log_2\, n}

    why it is allowed: Top and bottom over nn, above zero.

  4. the move: divide each part

    the line:
    K=2log⁡2 n+2 log⁡2 nlog⁡2 nK = \frac{2}{\log_2\, n} + \frac{2 \,\log_2\, n}{\log_2\, n}

    why it is allowed: A sum over a number is each part over it, added.

  5. the move: cancel

    the line:
    K=2log⁡2 n+2K = \frac{2}{\log_2\, n} + 2

    why it is allowed: log⁡2 n\log_2\, n is above zero, so it cancels, leaving 2.

  6. the move: put the 2 first

    the line:
    K=2+2log⁡2 nK = 2 + \frac{2}{\log_2\, n}
    102104106108101102103104105106107101102103104105106107108109101102103104105106107
    • n log⁡2 nn \,\log_2\, n
    • nn
    The gap to nn is about 0.5 marks at 10 items, 1 at 1,000 and 1.3 at a million: still widening, ever more slowly, so the slope falls toward 1.
    itemslog⁡2 n\log_2\, nthe doubling ratiothe slope
    4231.58
    1642.51.32
    1,024102.21.14
    about a million202.11.07
    Line 6, rounded, and each slope by question 3. About a million is 1,048,576.

    why it is allowed: Either order makes the same total.

  7. the move: read it

    the line:
    the slope falls toward 1,but slowly\begin{gathered} \text{the slope falls toward 1,} \\ \text{but slowly} \end{gathered}

    why it is allowed: As nn grows, log⁡2 n\log_2\, n grows without end, so 2 over it shrinks toward zero. By line 6 KK falls toward 2, and the slope toward 1, that of nn (question 3). But slowly, as line 6's table shows: only many doublings show it.

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

a worked example

A method takes 2,004,000 steps on 1,000 items and 8,008,000 on 2,000. What is its slope?

  1. 8,008,000 over 2,004,000 is about 3.996, the doubling ratio.
  2. It is close to 4, two 2s, so the slope is close to 2 (question 3).
  3. A calculator's log key gives log 3.996 as about 0.6016, and 0.6016 over 0.301 is about 1.999, by the last line of question 3.
  4. At 4,000 items it takes 32,016,000 steps: a ratio of about 3.998, a slope of about 1.999 again. So the count likely grows like n2n^2; only how it works can prove it.

the trap

check yourself

  1. Doubling the input takes a count from 3,000 steps to 24,000. What slope does its line have?

    the answer

    24,000 over 3,000 is 8, three 2s, so slope 3, pointing to n3n^3 (question 4). Measure another size before you trust one doubling.

  2. Two methods draw parallel straight lines, the second one mark above. What does that say about their costs?

    the answer

    The same slope. If both are a number times a power of nn, the powers match (questions 4 and 5). One mark up is ten times as much, so the second costs ten times the first.

  3. Why is the line of n log⁡2 nn \,\log_2\, n not quite straight?

    the answer

    A straight line keeps one slope. Its doubling ratio, 2+2log⁡2 n2 + \frac{2}{\log_2\, n} by question 7, changes with nn, 2.5 at 16 items and 2.1 at about a million. So its slope keeps falling, slowly.