Induction and Recursion
Induction proves infinitely many statements by showing how each case follows from earlier cases. Recursion defines objects or algorithms by reducing them to smaller objects or inputs. The two ideas fit together: recursive definitions give objects step by step, and induction proves facts about every step.
The connection is practical. A recursive algorithm is trustworthy only when it has a base case, makes progress toward that base case, and combines smaller answers correctly. An induction proof has exactly the same shape: verify the base case, assume smaller or previous cases, and prove the next case.
Definitions
The principle of mathematical induction proves statements for all integers by showing:
- Base case: is true.
- Inductive step: for every , .
The statement assumed in the inductive step is the inductive hypothesis. The statement is the inductive conclusion. A proof is not complete until both the base case and the inductive step have been shown.
Strong induction replaces the single inductive hypothesis with all earlier statements:
Strong induction is often cleaner when the next object may depend on several previous objects, as in prime factorization, recurrence relations, tilings, and recursive algorithms that split an input into uneven pieces.
The well-ordering principle says every nonempty set of nonnegative integers has a least element. It is equivalent in strength to induction. Many contradiction proofs over integers secretly use well-ordering: assume counterexamples exist, choose the smallest counterexample, and show it leads to a smaller one.
A recursive definition gives initial values and a rule that builds later values from earlier ones. A recursive algorithm solves a problem by calling itself on smaller inputs. A structural induction proof works over recursively built objects such as strings, trees, formulas, and lists.
Key results
For all positive integers ,
Base case : both sides are .
Inductive step: assume
Then
This is the desired formula with , so the formula holds for every positive integer .
Strong induction proves that every integer can be written as a product of primes. Assume the claim holds for all integers . If is prime, it is already a product of one prime. If is composite, then with , and both and are products of primes by the strong inductive hypothesis. Multiplying those prime products gives a prime factorization of .
A recursive algorithm terminates when each recursive call decreases a well-founded measure. For nonnegative integers, the measure is often the input itself. For lists, it may be length. For trees, it may be the number of nodes. Correctness then follows by induction on that measure.
Visual
| Method | Hypothesis allowed | Best for | Typical proof obligation |
|---|---|---|---|
| ordinary induction | formulas depending on previous case | prove | |
| strong induction | factorization, tilings, recurrences | prove all earlier cases imply next | |
| structural induction | property for smaller built objects | trees, strings, formulas | prove constructors preserve property |
| loop invariant | property after iterations | iterative programs | initialization, maintenance, termination |
Worked example 1: Prove a closed form by induction
Problem. Prove that for every integer ,
Method.
- Define to be the statement .
- Base case :
So is true.
- Inductive hypothesis: assume is true for some arbitrary :
- Prove :
Checked answer. The base case is true and the inductive step proves for arbitrary . Therefore the sum of the first positive odd integers is for every .
Worked example 2: Use strong induction for postage
Problem. Prove that every integer amount of postage cents can be formed using only -cent and -cent stamps.
Method.
- Strong induction is natural because adding one stamp changes the amount by or , not by .
- Establish enough base cases:
- Inductive hypothesis: assume every amount from through can be formed, where .
- To form , observe that
- Since , we have . Also , so the inductive hypothesis applies.
- Form cents using - and -cent stamps, then add one more -cent stamp.
Checked answer. The base cases cover , and the strong inductive step constructs from . Therefore every amount cents can be formed.
Code
from functools import lru_cache
def factorial(n):
if n < 0:
raise ValueError("n must be nonnegative")
if n == 0:
return 1
return n * factorial(n - 1)
@lru_cache(maxsize=None)
def can_make_postage(n):
if n == 0:
return True
if n < 0:
return False
return can_make_postage(n - 4) or can_make_postage(n - 5)
print(factorial(6))
print([(n, can_make_postage(n)) for n in range(8, 21)])
The recursive postage function mirrors the inductive proof: a target amount is possible if subtracting one legal stamp leaves a smaller possible amount.
Common pitfalls
- Omitting the base case. The inductive step alone proves only that truth would propagate if it ever started.
- Assuming in the inductive step. The hypothesis is , or earlier cases for strong induction.
- Proving the inductive step only for a few values of . The step must work for arbitrary in the range.
- Using ordinary induction when the construction depends on more than one previous case.
- Writing recursive code without a decreasing measure. A recursive call must move toward a base case.
- Confusing a recursive definition with an efficient algorithm. The naive recursive Fibonacci definition is mathematically clear but computationally wasteful without memoization.
When writing an induction proof, name the proposition explicitly. This prevents the inductive hypothesis from drifting. If the target statement has several variables, decide which variable is being inducted on and which are fixed or arbitrary. For example, proving a formula for all and all may require "fix and induct on " or a different strategy.
Base cases must cover the recurrence or construction. Ordinary induction often needs one base case. Strong induction or recurrences of order two may need two or more. In the postage example, four base cases are needed because the inductive step reaches back by . If the base range has a gap, the proof may only cover one congruence class of integers.
Strong induction is not a license to assume the conclusion for every number. The hypothesis covers only earlier cases. In a proof for , you may use for , but not . Writing the allowed range explicitly helps avoid circular reasoning.
Recursive programs should be checked with the same structure as recursive proofs. Identify a measure, prove each recursive call decreases that measure, prove the base case returns the right answer, and prove the recursive combination is correct assuming smaller calls are correct. This is induction phrased as program correctness.
Structural induction uses constructors instead of integers. To prove a property of all binary trees, prove it for the empty tree or one-node tree, then show that combining left and right subtrees under a root preserves the property. The proof follows the way the objects are built, not necessarily a numeric sequence.
A useful editing pass for induction proofs is to highlight every place the inductive hypothesis is used. If it is never used, the proof may be a direct proof rather than an induction proof. If it is used on an index not allowed by the hypothesis, the proof is invalid. If the base case does not connect to the step, the proof may leave early values uncovered.
For recursive algorithms, test the base cases first, then test the smallest non-base input. The smallest non-base input exercises the recursive call and the combine step with minimal complexity. If factorial works for but fails for , or a tree traversal works for a leaf but fails for a root with one child, the recursive structure is wrong.
In strong induction, make sure the base cases extend far enough for the first use of the step. If the step for uses , then the proof cannot start from a single base case. The base interval must cover all values before the recurrence or construction can feed itself.
Connections
- Proof techniques gives the general proof framework used by induction.
- Functions, sequences, and sums supplies the formulas and sequences often proved by induction.
- Recurrence relations turns recursive definitions into equations and closed forms.
- Number theory basics uses strong induction for prime factorization and integer representations.
- Trees uses structural induction over recursively defined graph objects.