Lecture Notes for Algorithm Design
Mathematical Induction, 28 October 1999
These are provisional lecture notes, expect changes.
- a simple problem: show sum(i = 1 to n, i) = n(n + 1)/2
- simple induction
- if something is true for n, and also is true for n + 1, then
it is true for all j >= n
- the inductive hypothesis H(n) - n the parameter of the
induction
- the base case - show H(i) holds
- the inductive step - assume H(j) is true for some j >=
i and consider H(j + 1)
- example
- show for all natural numbers x and n, xn - 1 is divisible by x - 1
- hypothesis - H(n) = x - 1 div xn - 1
for n = 0
- the inductive step - assume H(j) holds for some j >= 0 and
consider H(j + 1)
- can also assume H(j - 1) and show H(j), but be careful
how you specify j.
- another example
- two-coloring regions formed by n planar lines
- hypothesis - H(n) = the regions formed by n lines can be
two colored
- base - H(1) is true
- induction - assume H(j) true for j >= 1 and consider
H(j + 1)
- what j things to induct over?
- an example
- show sum(i = 1 to n, 2-n) < 1
- hyp - H(n) = sum(i = 1 to n, 2-n) < 1
- bas - H(1) = sum(i = 1 to 1, 2-n) = 1/2 < 1
- ind - assume H(j) true for j >= 1 and consider
H(j + 1), from the right
- another example
- how many regions do n planer lines form
- subsidiary problem - how many regions does the nth line form
- hyp - H(n) = the nth line adds n regions
- bas - H(1), H(2), H(3) true by inspection
- ind - let H(j) be true for some j >= 1 and consider
H(j + 1)
- double induction, repeated induction
- Euler's formula V + F = E + 2 - notice that V + F = E + 2 implies that
V + (F - 1) = (E - 1) + 2, and that removing an edge can actually remove a
face.
- hyp - H(n) = V + n = E + 2
- bas = H(1) = (V + 1 = E + 2) = (V = E + 1)
- a one-faced, connected, planar graph is a tree
- hyp - H'(n) = an n-node tree has n - 1 edges
- bas = H'(1) = a 1-node tree has 1 - 1 = 0 edges
- ind = let H'(j be true for some j >= 1 and consider
H'(j + 1)
- notice that reducing V = E + 1 by one on each side reduces the
problem to the assumed hypothesis, if such a reduction makes sense.
Fortunately, the graph is a tree and the reduction does make sense (that
is, a tree always has at least one vertex connected to the tree by one
edge)
- ind - let H(j) be true for some j >= 1 and consider
H(j + 1)
- strong induction
- rather than assume H(j) true for some h >= 1, assume
H(1), H(2), . . ., H(j) true.
- example
- independent set, induced subgraph
- hyp - H(n) = any n-node directed graph has
a two-path-connected independent set
- bas - H(1), H(2), H(3) hold
- ind - assume H(j) holds for j >= 1 and consider
H(j + 1)
- extract a vertex and all its neighbors - unfortunately, the
resulting graph may not have j vertices
- strengthen the hypothesis to assume that all of H(1),
H(2), . . ., and H(j) are true
- hyp - H(n) = any graph with up to n nodes has a
two-path-connected independent set
- another example
- disjoint paths between odd-degree vertices
- hyp - H(n) = pairs of odd-degree vertices in an n-edge
connected, undirected graph can be connected by disjoint paths
- bas - H(1) is true
- ind - assume H(j) holds for j >= 1 and consider
H(j + 1)
- if there are two odd vertices, there is a path between them;
remove it and consider the remaining graph - but it may not be a
connected graph, and we can't use the inductive hypothesis
- strengthen the hypothesis by eliminating the connected part
- now consider a pair of odd-degree vertices in the same component
- loop invariants and program proofs
- the loop invariant method
- each loop gets an invariant (the hypothesis)
- show the invariant is true before the loop executes (the basis step)
- show the invariant is true after each iteration of the loop (the
inductive step)
- at loop termination, use the invariant and the negated guard to
prove the main theorem
- example
- convert n to binary in array
b
t <- n
k <- 0
do t > 0
k <- k + 1
b[k] <- t mod 2
t <- t div 2
od
- invariant
n
= t
*2k
+ m, where m is
the number represented by b[1..k]
.
- true before the start because
t
= n
and k
= 0.
- true on after each iteration -
t
even or odd
- after the loop
t
= 0 and so n
= m
This page last modified on 2 November 1999.