CS 411 Fall 2025 > Outline for September 8, 2025
CS 411 Fall 2025
Outline
for September 8, 2025
Outline
Analysis Examples [L 2.5, Appendix B]
- More on Recurrences
- Given a recurrence and initial conditions, the general solution consists of all functions that satisfy the recurrence, ignoring initial conditions.
- Procedure for solving recurrences:
- Find general solution of the recurrence. This will usually involve unknown constants.
- Use initial conditions to determine the values of these constants. Result: specific solution to the recurrence and initial conditions.
- Fibonacci Numbers
- Sequence \(0,1,1,2,3,5,8,13,21,34,55,89,144,\dots\). Property: sum of two consecutive values is next value.
- Recurrence: \(F(0) = 0\), \(F(1) = 1\), and \(F(n) = F(n-1)+F(n-2)\) for \(n\ge 2\).
- Slow algorithm, based on recurrence.
- Second-order linear homogeneous recurrences
- Order of a recurrence:
how far back its dependence on previous values goes.
- First-order recurrence: \(x(n) = 5 \bigl[x(n-1)\bigr]^2\).
- Second-order recurrence: \(x(n) = 5 \left[x(n-1)\right]^2 - \sin\bigl[x(n-2)\bigr]\).
- Linear recurrence: constants times values,
added up, is equal to ...
- Example linear recurrence: \(x(n) - 2 x(n-1) + 3 x(n-2) = 15\).
- Equivalently: \(x(n) = 2 x(n-1) - 3 x(n-2) + 15\).
- A linear recurrence is homogeneous
if the right-hand side (in the first form, above)
is the constant zero.
- Example linear homogeneous recurrence: \(6 x(n) - 2 x(n-1) + 3 x(n-2) = 0\).
- Finding the general solution of a second-order
linear homogeneous recurrence
- Recurrence: \(a\,x(n) + b\,x(n-1) + c\,x(n-2) = 0\), where \(a\), \(b\), \(c\) are constants.
- Characteristic equation: \(ar^2 + br + c = 0\).
- Find general solution to recurrence based on
roots of characteristic equation:
- 2 real roots \(r_1\), \(r_2\). General solution: \(x(n) = \alpha r_1^n + \beta r_2^n\), where \(\alpha\), \(\beta\) are real numbers.
- 1 real root \(r\). General solution: \(x(n) = \alpha r^n + \beta n r^n\), where \(\alpha\), \(\beta\) are real numbers.
- No real roots (we will not need to use this case). Roots are distinct complex numbers \(r_1, r_2 = u \pm vi\). General solution: \(x(n) = \gamma^n\left[\alpha \cos n\theta + \beta \sin n\theta\right]\), where \(\alpha\), \(\beta\), \(\gamma\) are real numbers.
- Order of a recurrence:
how far back its dependence on previous values goes.
- Analyze Slow Fibonacci
- Size: given \(n\). Basic operation: base-case return. Result: second-order linear homogeneous recurrence.
- Basic operations required to compute \(F(n)\): \(\Theta\left(\left[\frac{1+\sqrt{5}}{2}\right]^n\right)\). Exponential time!
- Fast Fibonacci
- Fibonacci number \(F(n)\) can easily be computed using \(\Theta(n)\) integer arithmetic operations.
- Both recursive and iterative algorithms demonstrated.
- Super-Fast Fibonacci
- The text mentions that there is an algorithm based on matrix multiplication that computes \(F(n)\) using only \(\Theta(\log n)\) integer arithmetic operations.
- This allows for the computation of very large Fibonacci numbers, if such numbers can be represented by the numeric types used.
- Python implementation demonstrated.