CS 411 Fall 2025 > Outline for September 5, 2025
CS 411 Fall 2025
Outline
for September 5, 2025
Outline
Analyzing Recursive Algorithms [L 2.4, Appendix B]
- Recursion
- Algorithm or function (code) calling itself, perhaps indirectly.
- Must have base case, and must eventually reach base case.
- Simple analysis: recursive factorial function.
- Introductory example: analyze recursive factorial
- A recurrence relation—or recurrence—defines a (mathematical) function in terms of itself.
- Often there are one or more associated initial conditions, giving specific values of the function.
- Analysis of iterative algorithms usually involves summations; analysis of recursive algorithms usually involves recurrences.
- The recursive call gives the recurrence; base cases give initial conditions.
- To solve a recurrence is to find a (mathematical) function that makes the recurrence—and possibly initial conditions—true.
- Some recurrences can be solved using the method of forward substitutions: compute values of function, guess a formula (guess right!), verify that it solves the recurrence.
- Example: analyze recursive factorial function
- General Plan
- Plan for analyzing recursive algorithms
- Choose way of measuring size of input.
- Choose basic operation.
- Does # of basic ops depend only on the size of the input?
- Set up a recurrence.
- Solve the recurrence.
- Plan for analyzing recursive algorithms
- Example: analyze Binary Search
- Applying the Smoothness Rule
- Example: Binary Search
- Smoothness Rule
- Suppose \(T(n)\) is \(\Theta(f(n))\) for \(n\) a power of \(b ≥ 2\).
- Three conditions:
- \(T\) eventually nondecreasing.
- \(f\) eventually nondecreasing.
- \(f(2n)\) is \(\Theta(f(n))\).
- Conclusion: \(T(n)\) is \(\Theta(f(n))\) for all \(n\).
- The above also works for \(O\) and \(\Omega\).
- Example: number of bits in binary representation of a number