_______ is often used to prove the correctness of a recursive function.
2013
_______ is often used to prove the correctness of a recursive function.
- A.
Diagonalization
- B.
Communitivity
- C.
Mathematical Induction
- D.
Matrix Multiplication
Attempted by 166 students.
Show answer & explanation
Correct answer: C
Answer: Mathematical Induction
Why this is used:
Mathematical induction directly matches the structure of many recursive definitions: you prove the property for a base case, then assume it holds for smaller inputs and show it holds for the next case using the recursive step.
Base case: Prove the property for the simplest input(s) where the recursion stops.
Inductive step: Assume the property holds for smaller inputs (induction hypothesis). Using the recursive definition of the function, prove the property for a general input.
Short example (factorial):
Claim: A recursive factorial function returns n! for all n ≥ 0.
Base case: n = 0. By definition the function returns 1, which equals 0!.
Inductive step: Assume for some k ≥ 0 the function returns k! for input k. For input k+1, the recursive definition computes (k+1) * factorial(k). By the induction hypothesis factorial(k) = k!, so the result is (k+1) * k! = (k+1)!.
Note: For proofs about recursive data structures (like linked lists or trees), structural induction is the analogous technique: prove the property for the base structure and show that if it holds for the components, it holds for the composed structure.