ABSTRACT
A Recursive Proof is a formal verification method used to guarantee that a recursive algorithm produces the correct output for all valid inputs. It relies on the mathematical symmetry between recursion and induction: the base cases of the recursion serve as the base cases of the induction.
The Big Picture: Induction vs. Recursion
While they look similar, they serve different purposes in computer science:
- Recursion is a computational strategy for solving a problem by breaking it into smaller instances.1
- Induction is a logical strategy for proving a statement is true for an infinite set of cases.
To prove a recursive algorithm is correct, we use Strong Induction on the size of the input .
The Formal Proof Structure
When writing a proof for a recursive algorithm, follow these four distinct steps:
Example Code:
countDoubleRec(string, n):
if n < 2:
// Base Case
return 0
if string[0,1] == "00":
// Recursive Call A
return 1 + countDoubleRec(string[1:], n-1)
else:
// Recursive Call B
return countDoubleRec(string[1:], n-1)1. The Claim
State clearly what the algorithm is supposed to do.
- Example: “Claim:
countDoubleRec(S)returns the total number of occurrences of the substring ‘00’ in string for all lengths .“
2. Base Case(s)
Identify the smallest possible inputs where the recursion stops.
- Action: State what the algorithm does for these inputs and explain why that is the correct answer.
- Note: If the algorithm calls , you likely need two base cases ( and ).
3. Inductive Hypothesis (Strong)
Assume the algorithm works correctly for all “smaller” inputs.
- Formulation: “Assume that for some , the algorithm is correct for all inputs of size , where .”
- Why Strong? Recursive calls don’t always go to . In Divide and Conquer, the call might be to . Strong induction covers all possible smaller sizes.
4. Inductive Step (The Goal)
Show that if the algorithm is correct for size , it must be correct for size .
- Trace the Logic: Look at the recursive case in the code.
- Apply Hypothesis: Replace the recursive calls with “the correct answer according to the problem” (since our hypothesis says the calls work).
- Algebraic/Logical Wrap-up: Show that the current step + the result of the recursive calls equals the expected total for size .
Applied Example: FindMax Proof
Algorithm: FindMax(A, n) returns if , otherwise it returns .
- Base Case (): The algorithm returns . Since a list of length 1 only has one element, that element is the maximum. Correct.
- Inductive Hypothesis: Assume
FindMaxcorrectly returns the maximum of any array of size . - Inductive Step ():
- The algorithm computes and returns .
- By our Hypothesis, is the true maximum of the first elements.
- The maximum of the first elements must be either the maximum of the first elements OR the new element.
- Since the algorithm compares these two specific values and returns the larger one, it correctly finds the maximum for . → Verified.
Regular vs. Strong Induction in Proofs
| Feature | Regular Induction | Strong Induction |
|---|---|---|
| Logic | Uses to prove . | Uses any/all values to prove . |
| Use Case | Linear recursion (). | Divide and Conquer (, ) or HRRCC. |
| Stability | Easier to write but limited. | Required for almost all non-trivial algorithms. |