Skip to content

proof by induction

why it works

what it is

To prove a claim for every whole number, prove it for the first, then show that whenever it holds (is true) for one number, it holds for the next.

A claim about every whole number cannot be checked one number at a time, since the numbers never run out. The page on doubling sums adds terms each twice the one before: 1 + 2 + 4 + 8 is 15, one less than the next term, 16. The last term is 2 to the power nn, so for 1 + 2 + 4 + 8, nn is 3. After 8, 2 to the power 3, comes 16, 2 to the power 4, so one less than the next term is 2n+1−12^{n + 1} - 1. Is that true for every nn?

and on, for every nnthe sumthe formula011equal133equal277equal31515equal43131equal56363equalchecked by hand+ 2the step+ 4+ 8+ 16+ 32
Each rung is one value of nn, from 0 to 5: the doubling sum beside its formula, 2n+1−12^{n + 1} - 1. Each arrow adds the next term to both sides, so equal stays equal.

Climb it like a ladder. The start: check by hand the first number the claim covers, 0 here. The step: show that whenever one rung holds, so does the next. Then the claim holds at 0 by the start, at 1 by the step, then at 2, and on. This is proof by induction. Books call the start the base case, and the step the inductive step.

and on, for every nnthe sumthe claim012not equal134not equal278not equal31516not equal43132not equalchecked by hand+ 2the step+ 4+ 8+ 16
Without a start: a claim with no 1 taken off, for nn from 0 to 4. Every rung is false by 1, and the bottom rung, the start, shows it.

In the step you suppose the claim holds one size down, at n−1n - 1 (for 3, at 2), then show it holds at nn. At 3: if 1 + 2 + 4 is 8 less 1, then 1 + 2 + 4 + 8 is 7 + 8, which is 16 less 1. Books call the supposing the inductive hypothesis.

1, 2, 4, 8 and 16, a row at a time: blue the terms before, yellow the new term, hollow the 1 the total is short of the next doubling. In the fourth row the total, 7 + 8, is 15; with the hollow 1 it makes 16, 2 × 8, so the total is 2 × 8 less 1.

Sometimes one rung down is not enough to stand on. Count the halvings from 13 to 1, rounding down: one halving to 6, then 6's own count. 6 is far below 12, one size down. So suppose the claim for every smaller number, since each is reached before nn. This is strong induction.

rounding down136.5 → 631.5 → 13 halvings
Rounding down, 13 halves to 6, 3 and 1, 3 halvings, 1 more than 6's 2.

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 1Add 1+2+4+⋯+2n1 + 2 + 4 + \dots + 2^n, the dots standing for the terms between. Prove the total is 2n+1−12^{n + 1} - 1 for every nn, from a start and a step.
  1. the move: check the first case

    the line:
    1=20+1−11 = 2^{0 + 1} - 1

    why it is allowed: At nn as 0 the last term is 2 to the power 0, which is 1, so the sum is the one term 1. 2 to the power 1, less 1, is 1 too. This is the start.

  2. the move: name the sum

    the line:
    S=1+2+4+⋯+2nS = 1 + 2 + 4 + \dots + 2^n

    why it is allowed: Let SS be the sum. nn as 0 is the start, line 1; the step needs n−1n - 1 to be 0 or more, so it covers 1, 2, 3 and on. For 3, SS is 1 + 2 + 4 + 8.

  3. the move: split off the last term

    the line:
    S=(1+2+⋯+2n−1)+2nS = (1 + 2 + \dots + 2^{n - 1}) + 2^n
    nnthe sum one size downthe new term, 2n2^nthe total, SS2n+1−12^{n + 1} - 1
    11233
    23477
    3781515
    415163131
    Line 3 for nn from 1 to 4. Each total matches the formula.

    why it is allowed: The bracket is the same sum one size down, n−1n - 1 in place of nn. At nn as 1 the bracket is just 1; for 3 it is 1 + 2 + 4, so the line reads 7 + 8.

  4. the move: suppose it holds one size down

    the line:
    S=(2(n−1)+1−1)+2nif the claim holds for n−1\begin{gathered} S = (2^{(n - 1) + 1} - 1) + 2^n \\ \text{if the claim holds for } n - 1 \end{gathered}

    why it is allowed: The step. Suppose the claim holds at n−1n - 1: it is the claim with n−1n - 1 in place of nn, so the bracket is 2 to the power (n−1)+1(n - 1) + 1, less 1. For 3, at 2: 2 to the power 3 (that is, 2 + 1) is 8, and 8 less 1 is 7.

  5. the move: tidy the power

    the line:
    S=(2n−1)+2nS = (2^n - 1) + 2^n

    why it is allowed: (n−1)+1(n - 1) + 1 is nn. So the sum one size down is 2n−12^n - 1, one less than the new term. For 3, 7 is 8 less 1.

  6. the move: collect the two

    the line:
    S=2×2n−1S = 2 \times 2^n - 1

    why it is allowed: Two lots of 2n2^n, less 1. For 3, 16 less 1.

  7. the move: twice a power of 2 is the next

    the line:
    S=2n+1−1S = 2^{n + 1} - 1

    why it is allowed: One more 2 multiplied. For 3, 2 × 8 is 16, which is 2 to the power 4, so 15, as line 2 adds up.

  8. the move: read it

    the line:
    true at 0, and passed fromeach n−1 to n:true for every n\begin{gathered} \text{true at 0, and passed from} \\ \text{each } n - 1 \text{ to } n \text{:} \\ \text{true for every } n \end{gathered}

    why it is allowed: Line 1 is the start. Lines 3 to 7 are the step, carrying the claim from n−1n - 1 to nn for any nn from 1.

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

question 2This site's Shell sort uses the gaps 1, 4, 13, 40, a list Donald Knuth suggested. Each is three times the one before, plus 1: 4 is 3 × 1 + 1, 13 is 3 × 4 + 1. Is gap number kk always at least 2k−12^{k - 1}?
  1. the move: check the first gap

    the line:
    gap number 1 is 1,which is 20\begin{gathered} \text{gap number 1 is 1,} \\ \text{which is } 2^0 \end{gathered}
    the gap 4 pass: 2 comparisons, 1 move852617startthe gap 1 pass: 7 comparisons, 2 moves152687after gap 4125678after gap 1a pair compareda pair tradedmoved by the pass beforethe row at the end
    Shell sort on 8, 5, 2, 6, 1, 7: the gap 4 pass compares 8 with 1 and 5 with 7, and trades 8 and 1. Then gap 1 finishes.

    why it is allowed: Shell sort first sorts numbers a gap apart, then a smaller gap, down to 1, as the picture shows. Gap number 1 is 1, and 2 to the power 0 is 1, so it is at least that. This is the start.

  2. the move: a gap from the one before

    the line:
    G=3g+1G = 3g + 1
    the gapgap number050100150012345the gapgap number050100150012345
    • the gaps
    • 2k−12^{k - 1}
    The gaps and the powers of 2 for gap numbers 1 to 5. The gaps pull away.

    why it is allowed: Each gap is three times the one before, plus 1, as the question says. Let GG be gap number kk, from 2, since gap number 1 is the start, and gg the gap before it. For kk as 3, 3 × 4 + 1 is 13.

  3. the move: suppose it holds one gap down

    the line:
    g≥2(k−1)−1if the claim holdsfor gap number k−1\begin{gathered} g \ge 2^{(k - 1) - 1} \\ \text{if the claim holds} \\ \text{for gap number } k - 1 \end{gathered}

    why it is allowed: The step. ≥\ge reads is at least. Suppose the claim holds for gap number k−1k - 1, which is gg: it is the claim with k−1k - 1 in place of kk. For 3, gap number 2 is 4, at least 2.

  4. the move: tidy the power

    the line:
    g≥2k−2g \ge 2^{k - 2}

    why it is allowed: 2(k−1)−12^{(k - 1) - 1} is 2k−22^{k - 2}, as (k−1)−1(k - 1) - 1 is k−2k - 2.

  5. the move: three times both sides of line 4

    the line:
    3g≥3×2k−23g \ge 3 \times 2^{k - 2}

    why it is allowed: Multiplying both sides by 3, a positive number, keeps the at least. For 3, 12 is at least 6.

  6. the move: add 1 to both sides

    the line:
    3g+1≥3×2k−2+13g + 1 \ge 3 \times 2^{k - 2} + 1

    why it is allowed: Adding the same to both sides keeps the at least. For 3, 13 is at least 7.

  7. the move: put line 2 in

    the line:
    G≥3×2k−2+1G \ge 3 \times 2^{k - 2} + 1
    kkgap number kkline 7 gives at least2k−12^{k - 1}
    2442
    31374
    440138
    51212516
    Each gap, the least value line 7 allows it, and 2k−12^{k - 1}, for kk from 2 to 5. Each is at least the one to its right.

    why it is allowed: Line 2 says 3g+13g + 1 is GG. For 3, 13 is at least 7.

  8. the move: drop the 1

    the line:
    G≥3×2k−2G \ge 3 \times 2^{k - 2}

    why it is allowed: Taking 1 off the right side makes it smaller, so GG is still at least it. For 3, 13 is at least 6.

  9. the move: two lots are no more than three

    the line:
    G≥2×2k−2G \ge 2 \times 2^{k - 2}

    why it is allowed: 2k−22^{k - 2} is positive, so two lots are no more than three. For 3, 13 is at least 6, and 6 at least 4.

  10. the move: twice a power of 2

    the line:
    G≥2k−1G \ge 2^{k - 1}

    why it is allowed: Two times 2k−22^{k - 2} is one more 2 multiplied. For 3, 2 × 2 is 4.

  11. the move: read it

    the line:
    every gap number kis at least 2k−1\begin{gathered} \text{every gap number } k \\ \text{is at least } 2^{k - 1} \end{gathered}

    why it is allowed: Line 1 is the start. Lines 2 to 10 are the step, carrying the claim from each gap to the next. An at least passes along a step just as an equals does. So gap number 11 is at least 1,024. Shell sort uses only gaps smaller than the row, and the gaps only grow, so a row of 1,000 needs at most 10 gaps. It uses 6: 1, 4, 13, 40, 121 and 364.

try it with a small kk: at k=3k = 3, line 2 gives G=13G = 13, which you can work out by hand

question 3Halve nn again and again, rounding down. Prove it takes ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor halvings to reach 1, supposing the claim for every smaller number. The brackets mean round down: 6.5 becomes 6.
  1. the move: check the first case

    the line:
    1 needs no halving, andits log rounded down is 0\begin{gathered} \text{1 needs no halving, and} \\ \text{its log rounded down is } 0 \end{gathered}
    number2s multipliedlog to base 2
    1none0
    221
    42 × 22
    82 × 2 × 23
    162 × 2 × 2 × 24
    The powers of 2 up to 16, each with its log. 13 sits between 8 and 16.

    why it is allowed: The log to base 2 of a number counts the 2s multiplied to make it, as the table shows. 13 lies between 8 and 16, so its log is between 3 and 4 (about 3.70), and rounded down, 3. The log of 1 is 0. This is the start.

  2. the move: count the halvings

    the line:
    H=halvings, rounding down,that take n to 1\begin{gathered} H = \text{halvings, rounding down,} \\ \text{that take } n \text{ to 1} \end{gathered}

    why it is allowed: Let HH be that count, for nn from 2, since 1 is the start. For 13, the halvings go 6, 3, 1, so 3.

  3. the move: halve once

    the line:
    H=1+the halvingsthat take ⌊n/2⌋ to 1\begin{gathered} H = 1 + \text{the halvings} \\ \text{that take } \lfloor n/2 \rfloor \text{ to 1} \end{gathered}
    numberlog× 2+ 1214283164133.70362.58231.581100
    13 halves, rounding down, to 6, 3 and 1. Each tick to the right doubles the number and adds 1 to its log. Under each, in blue, its log rounded down: 3, 2, 1 and 0, so each halving takes off 1.

    why it is allowed: The first halving gives ⌊n/2⌋\lfloor n/2 \rfloor, half of nn rounded down. The rest is the same job on that. For 13, one halving to 6, then 2 more.

  4. the move: suppose it holds for every smaller number

    the line:
    H=1+⌊log⁡2 ⌊n/2⌋⌋if the claim holds below n\begin{gathered} H = 1 + \lfloor \log_2\, \lfloor n/2 \rfloor \rfloor \\ \text{if the claim holds below } n \end{gathered}
    nnhalf, rounded downhalvings to 1log rounded down
    13633
    6322
    3111
    1none00
    13, and below it the numbers line 4 supposes the claim for. In every row the two counts match.

    why it is allowed: The step. ⌊n/2⌋\lfloor n/2 \rfloor is a whole number from 1, and below nn. Suppose the claim holds for every number below nn, so for that one. For 13, 6 needs 2 halvings, its log rounded down.

  5. the move: halving takes 1 off the log

    the line:
    ⌊log⁡2 ⌊n/2⌋⌋=⌊log⁡2 n⌋−1\begin{gathered} \lfloor \log_2\, \lfloor n/2 \rfloor \rfloor \\ = \lfloor \log_2\, n \rfloor - 1 \end{gathered}
    numberlog× 2+ 110214283164133.7062.58
    13 lies between 8 and 16, and 6 between 4 and 8, one band lower, so its log rounded down is 1 less.

    why it is allowed: This is line 18 of question 2 of the page halving and logarithms; the fold at line 6 opens that proof, if you want it.

  6. the move: put line 5 in

    the line:
    H=1+⌊log⁡2 n⌋−1H = 1 + \lfloor \log_2\, n \rfloor - 1
    where does this come from?
    question 2 of the page halving and logarithmsHalve nn, rounding down each time. How many halvings reach 1?
    1. the move: name the log rounded down

      the line:
      K=⌊log⁡2 n⌋K = \lfloor \log_2\, n \rfloor
      numberlog× 2+ 14283164113.46352.322211100
      Rounding down, 11 halves to 5, 2 and 1. In blue, each log rounded down: 3, 2, 1, 0, one less at each halving.

      why it is allowed: Here nn is the number halved, from 2 up; for 11, KK is 3.

    2. the move: rounding down never adds

      the line:
      ⌊log⁡2 n⌋≤log⁡2 n\lfloor \log_2\, n \rfloor \le \log_2\, n

      why it is allowed: For 11, 3 is at most 3.46.

    3. the move: rounding down takes off less than 1

      the line:
       log⁡2 n<⌊log⁡2 n⌋+1\begin{gathered} \,\log_2\, n \\ < \lfloor \log_2\, n \rfloor + 1 \end{gathered}

      why it is allowed: For 11, 4 is above 3.46.

    4. the move: raise 2 to each side of line 2

      the line:
      2⌊log⁡2 n⌋≤2log⁡2 n2^{\lfloor \log_2\, n \rfloor} \le 2^{\log_2\, n}

      why it is allowed: 2 raised to a bigger power gives a bigger number. For 11, 8 is at most about 11.

    5. the move: 2 to the log of n is n

      the line:
      2⌊log⁡2 n⌋≤n2^{\lfloor \log_2\, n \rfloor} \le n

      why it is allowed: By what a log is. For 11, 8 is at most 11.

    6. the move: raise 2 to each side of line 3

      the line:
      2log⁡2 n<2⌊log⁡2 n⌋+12^{\log_2\, n} < 2^{\lfloor \log_2\, n \rfloor + 1}

      why it is allowed: As in line 4. For 11, about 11 is below 16.

    7. the move: 2 to the log of n is n

      the line:
      n<2⌊log⁡2 n⌋+1n < 2^{\lfloor \log_2\, n \rfloor + 1}

      why it is allowed: As in line 5. For 11, 11 is below 16.

    8. the move: halve both sides of line 5

      the line:
      2⌊log⁡2 n⌋/2≤n/22^{\lfloor \log_2\, n \rfloor} / 2 \le n / 2

      why it is allowed: For 11, 4 is at most 5.5, which is not whole.

    9. the move: write the half as a power

      the line:
      2⌊log⁡2 n⌋−1≤n/22^{\lfloor \log_2\, n \rfloor - 1} \le n / 2

      why it is allowed: Half a power of 2 has one 2 fewer. Half of 8 is 4.

    10. the move: round the half down

      the line:
      2⌊log⁡2 n⌋−1≤⌊n/2⌋2^{\lfloor \log_2\, n \rfloor - 1} \le \lfloor n / 2 \rfloor

      why it is allowed: ⌊n/2⌋\lfloor n / 2 \rfloor is the half rounded down, 5 for 11. A whole number at most 5.5 is at most 5. The left side, 4 for 11, is whole, as KK is at least 1 for nn from 2 up.

    11. the move: halve both sides of line 7

      the line:
      n/2<2⌊log⁡2 n⌋+1/2n / 2 < 2^{\lfloor \log_2\, n \rfloor + 1} / 2

      why it is allowed: For 11, 5.5 is below 8.

    12. the move: write the half as a power

      the line:
      n/2<2⌊log⁡2 n⌋n / 2 < 2^{\lfloor \log_2\, n \rfloor}

      why it is allowed: As in line 9. Half of 16 is 8.

    13. the move: round the half down

      the line:
      ⌊n/2⌋<2⌊log⁡2 n⌋\lfloor n / 2 \rfloor < 2^{\lfloor \log_2\, n \rfloor}

      why it is allowed: Rounding down never adds. For 11, 5 is below 8.

    14. the move: take the log of line 10

      the line:
       log⁡2 2⌊log⁡2 n⌋−1≤log⁡2 ⌊n/2⌋\begin{gathered} \,\log_2\, 2^{\lfloor \log_2\, n \rfloor - 1} \\ \le \log_2\, \lfloor n / 2 \rfloor \end{gathered}

      why it is allowed: A bigger number has a bigger log. For 11, the log of 4 is at most the log of 5.

    15. the move: the log of a power of 2 is the power

      the line:
      ⌊log⁡2 n⌋−1≤log⁡2 ⌊n/2⌋\begin{gathered} \lfloor \log_2\, n \rfloor - 1 \\ \le \log_2\, \lfloor n / 2 \rfloor \end{gathered}

      why it is allowed: For 11, the log of 4 is 2, at most about 2.32.

    16. the move: take the log of line 13

      the line:
       log⁡2 ⌊n/2⌋<log⁡2 2⌊log⁡2 n⌋\begin{gathered} \,\log_2\, \lfloor n / 2 \rfloor \\ < \log_2\, 2^{\lfloor \log_2\, n \rfloor} \end{gathered}

      why it is allowed: As in line 14. For 11, the log of 5 is below the log of 8.

    17. the move: the log of a power of 2 is the power

      the line:
       log⁡2 ⌊n/2⌋<⌊log⁡2 n⌋\begin{gathered} \,\log_2\, \lfloor n / 2 \rfloor \\ < \lfloor \log_2\, n \rfloor \end{gathered}

      why it is allowed: For 11, about 2.32 is below 3.

    18. the move: round the log down

      the line:
      ⌊log⁡2 ⌊n/2⌋⌋=⌊log⁡2 n⌋−1\begin{gathered} \lfloor \log_2\, \lfloor n / 2 \rfloor \rfloor \\ = \lfloor \log_2\, n \rfloor - 1 \end{gathered}
      the numberat leastbelowits log rounded down
      118163
      5482
      2241
      1120
      Each halving takes 1 off the log rounded down.

      why it is allowed: By lines 15 and 17, the log of the half is at least one less than KK and below KK, so it rounds down to one less. For 11, about 2.32 rounds down to 2.

    19. the move: use line 18 again and again

      the line:
      after K halvings,rounding down,the log roundeddown is 0\begin{gathered} \text{after } K \text{ halvings,} \\ \text{rounding down,} \\ \text{the log rounded} \\ \text{down is 0} \end{gathered}

      why it is allowed: While the log rounded down is 1 or more, the number is at least 2 to the power 1, which is 2. So line 18 takes 1 off each halving, down to 0 after KK. For 11, 3, 2, 1, 0.

    20. the move: a log rounded down to 0 belongs to 1

      the line:
      K halvings,rounding down,bring n to 1\begin{gathered} K \text{ halvings,} \\ \text{rounding down,} \\ \text{bring } n \text{ to 1} \end{gathered}

      why it is allowed: Such a log is at least 0 and below 1, so its number is at least 1 and below 2. It is 1.

    the whole page: halving and logarithms

    why it is allowed: Line 5 takes the place of the log of the half.

  7. the move: tidy

    the line:
    H=⌊log⁡2 n⌋H = \lfloor \log_2\, n \rfloor

    why it is allowed: 1 less 1 is nothing. For 13, 3, as line 2 counts.

  8. the move: read it

    the line:
    true at 1, and each n leans ona smaller one already reached:true for every n\begin{gathered} \text{true at 1, and each } n \text{ leans on} \\ \text{a smaller one already reached:} \\ \text{true for every } n \end{gathered}

    why it is allowed: Line 1 is the start. Lines 3 to 7 carry the claim to nn from a smaller number.

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

a worked example

If each number is at least its left neighbour, then each is at least every number to its left. Try it on 2, 4, 4, 7, 9.

  1. The claim for each place: the number there is at least every number before it.
  2. The start, place 1: no number stands before it, so the claim holds. Place 2 is the step used once: 4 is at least 2.
  3. The step: the next number is at least its neighbour, and the neighbour is at least every number before it, by the claim. So the next number is at least them all.
  4. On 2, 4, 4, 7, 9: 7 is at least its neighbour 4, which is at least 4 and 2. So 7 is at least 4, 4 and 2.
  5. By the start and the step every place holds, so every pair is in order.
  6. Bubble sort walks the row, swapping neighbours out of order. A walk with no swap finds every pair it compares in order. The numbers past its end are already in place, as each earlier walk carried the biggest left to the end. So the whole row is in order, and bubble sort may stop.
placenumberat least every number before itpairs with those
12nothing before it0
2421
344, 22
474, 4, 23
597, 4, 4, 24
Each row leans on the row above. 1 + 2 + 3 + 4 is 10 pairs, from 4 neighbour checks.

the trap

check yourself

  1. 1 + 2 + 4 and on up to 64 adds to 127. Take the step of question 1 once more. What does 1 + 2 + 4 and on up to 128 add to?

    the answer

    Add the next term to 127. 127 + 128 is 255, one less than 256, as question 1 says for nn as 7.

  2. Shell sort's gap number 6 is 364. What does question 2 say it is at least?

    the answer

    2 to the power 5, which is 32. 364 is well above it.

  3. Halve 150 again and again, rounding down. How many halvings reach 1?

    the answer

    75, 37, 18, 9, 4, 2, 1, so seven. 150 lies between 128 and 256, so its log rounded down is 7, as question 3 says.