Mastering Recurrence Relations: The Substitution Method
In computer science, analyzing the execution time of recursive algorithms requires solving a recurrence relation . A classic example is the recurrence:
This equation frequently arises in divide-and-conquer algorithms, such as Mergesort, where a problem of size is split into two equal subproblems of size , alongside a linear cost for splitting and recombining the subproblems .
To establish an asymptotic upper bound for , we can use the substitution method . This method leverages mathematical induction to prove that a guessed bound holds true for all inputs larger than a baseline value .
Visualizing the Recurrence Tree
To formulate a strong initial guess, we can visualize how the recurrence splits. The total work is the sum of the work done at each level of the recursion tree:
Summing the costs across any level yields a constant cost of per level. Since the tree has a depth of levels, the total complexity is visually estimated to be .
Footnotes
-
Introduction to Algorithms (CLRS) - Chapter 4: Divide-and-Conquer and Recurrences. ↩ ↩2 ↩3
-
Mathematical Induction for Recurrences - Stanford CS161 Lecture Notes on solving recurrences using the substitution method. ↩ ↩2
Formulating a Good Guess
Before starting the [substitution method]{def='A method for solving recurrences by guessing the form of the solution and then using mathematical induction to prove it.'}, always sketch a quick recursion tree. If the tree reveals that every level does work and there are levels, your guess should be . This ensures you do not waste algebraic effort proving a bound that is too tight or too loose.
Mathematical Induction Walkthrough
- 1Step 1
Based on our visual analysis, we guess that for some constant and all . This formulation represents our inductive hypothesis.
- 2Step 2
We assume the inductive hypothesis holds true for all positive numbers smaller than , which specifically includes . Thus, we substitute the hypothesis into the recurrence relation: . Inserting this into the original equation yields: .
- 3Step 3
Simplify the substituted inequality using the laws of logarithms. We know that . Expanding the expression gives: .
- 4Step 4
To complete the induction, we must show that our simplified inequality is less than or equal to our target bound: . This inequality holds true if and only if , which simplifies directly to .
- 5Step 5
Show that the boundary condition holds. If we assume a base case , our inductive hypothesis yields , which contradicts the base case. Because asymptotic bounds only require the inequality to hold for , we can choose and as our base cases. With , we choose large enough (e.g., ) to satisfy the base cases.
The Base Case Trap
A common pitfall in [mathematical induction]{def='A technique for proving a statement, theorem, or formula is true for every non-negative integer.'} is neglecting the base case. If your base case is , evaluates to , which is impossible for positive running times. Always remember that asymptotic notation only requires the bound to hold for . You can freely choose or as your base cases for induction [(https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/)].
Footnotes
-
Mathematical Induction for Recurrences - Stanford CS161 Lecture Notes on solving recurrences using the substitution method. ↩
A rigorous mathematical technique where we guess the form of the solution and prove it using mathematical induction. Highly precise but requires a good initial guess.
Advanced Substitution Strategies & Edge Cases
Knowledge Check
Which of the following is the correct inductive hypothesis to prove that is ?
Explore Related Topics
Short Notes on Cook's Theorem, Randomized Algorithms, and Bin Packing
The notes cover Cook’s theorem establishing SAT as NP‑complete, the design and analysis of randomized (Las Vegas and Monte Carlo) algorithms, and the NP‑hard bin‑packing problem with its common heuristics and approximation guarantees.
- Cook’s theorem shows every language reduces to SAT via a polynomial‑time function such that , making SAT the first NP‑complete problem.
- Randomized algorithms: Las Vegas algorithms are always correct with expected runtime (e.g., for randomized quicksort); Monte Carlo algorithms run in fixed time with error ≤½, which can be reduced by amplification to after repetitions.
- Bin packing: the decision version is NP‑complete and the optimization version NP‑hard; heuristics like First Fit Decreasing guarantee .
- Together they illustrate three core CS themes: proving hardness via reductions, leveraging randomness for efficient algorithm design, and using heuristics/approximation to tackle intractable optimization problems.
Solving the Recurrence $T(n)=T(n-1)+n$ by Substitution Method
The course shows how to solve the decrease‑by‑one recurrence (T(n)=T(n-1)+n) (with (T(1)=1)) using the substitution method.
- Repeatedly substitute (T(n-i)=T(n-i-1)+(n-i)) until reaching the base case, yielding (T(n)=T(1)+2+3+\dots+n).
- The resulting sum is the triangular number (\frac{n(n+1)}{2}).
- The dominant term (\frac{1}{2}n^{2}) gives a tight asymptotic bound (\Theta(n^{2})).
- For recurrences of the form (T(n)=T(n-1)+f(n)), expanding to a summation quickly reveals the closed form.
