TAOCP Vol 1: Fundamental Algorithms · Week 30

TAOCP 1.2.1 Mathematical Induction

Updated

About 6 hours15 exercises, rated 05 to 50

Summary

TAOCP 1.2.1 Mathematical Induction: Induction as the main tool for proving things about integers and about programs. Budget about 6 hours; do exercises 1, 2 and 3.

Knuth goes further than a typical math class by showing how to prove an algorithm correct by attaching assertions to each step of a flowchart, using an extended version of Euclid's algorithm as the worked example.

Flashcards 15 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §1.2.1 Mathematical Induction

    Read the basic induction material quickly if you have seen it before.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 2, Ex 3; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 15 exercises, rated 05 to 50, and Knuth marks three of them with the triangle for recommended. Do the 00 to 20 ones quickly, then grind out the recommended 8 and 13. Number 14 is rated 50, Knuth's mark for an open research problem; just read it. Always read the answers, even for exercises you got, because they often teach a second technique.

Worth your time

  • Exercise 105

    Adapt induction to start from zero. Checks you know what the base case is actually for.

    Discuss

  • Exercise 215

    Find the hole in a bogus induction proof. Great training for code review.

    Discuss

  • Exercise 318

    Another plausible proof that fails at a specific n. Subtler than the last one.

    Discuss

  • Exercise 521

    Prove every integer above 1 factors into primes, using strong induction.

    Discuss

  • Exercise 620

    Check that the extended Euclid invariants survive one step. This is the core technique of the section in miniature.

    Discuss

  • Exercise 825▶ Recommended

    Prove a pattern about odd numbers summing to cubes, then use it to get the closed form for the sum of cubes.

    Discuss

  • Exercise 13M23▶ Recommended

    Add a step counter to extended Euclid and prove a bound on it with assertions. Program proofs meet running time.

    Discuss

  • Exercise 15HM28▶ Recommended

    Work out how induction should go for statements about two integers. The stretch, and it leads to well-ordering.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 105No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 215No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 318No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 521No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 620No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 825No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 13M23No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 15HM28No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

Loop invariants, the thing that makes binary search and in-place algorithms correct, are induction in disguise. Once you can write the invariant, debugging off-by-one errors gets a lot less random.

Before you start
  • 1.1 Algorithms
  • Basic induction proofs (week 0)
How to approach it

Read the basic induction material quickly if you have seen it before. Slow way down for the flowchart-with-assertions proof of the extended Euclid algorithm: copy the flowchart onto paper and check every assertion yourself, step by step. That technique is the payoff of the section.

Common traps
  • Forgetting the base case or proving the step only for large n.
  • Strengthening the hypothesis is often the trick: if the induction step will not go through, try proving something stronger.
  • Reading the assertion proof without actually checking each arrow. You will not absorb it passively.

Spot a mistake? Report it

Back to week 30