There are 3 methods to work out a Recurrence.
Substitution method.
Steps:
- Guess the result.
- Prove it by induction.
Ex: T(n) = 4T(n/2) + n
- [Assume that T(1) = Θ(1)]
- Guess O(n3) . (Prove O and Ω separately.)
- Assume that T(k) ≤ ck3 for k < n .
- Prove T(n) ≤ cn3 by induction.
T (n) = 4T (n / 2) + n
≤ 4c ( n / 2 ) 3 + n
= ( c / 2) n 3 + n
desired – residual
= cn3 − ((c / 2)n3 − n)
≤ cn3
whenever (c/2)n3 – n ≥ 0, for example,
if c ≥ 2 and n ≥ 1.
residual
We first guess the result of a recurrence, and replace T(f(n)) with the result, and then just try to get the result.
Recursion-tree method
- A recursion tree models the costs (time) of a recursive execution of an algorithm.
- The recursion tree method is good for generating guesses for the substitution method.
- The recursion-tree method can be unreliable, just like any method that uses ellipses (...).
- The recursion-tree method promotes intuition, however.
Steps:
- Expond the recurrence into levels,like a tree.The body of the tree is some kind of f(n) while leaves are constant.
- Sum every node by level, and sum these level results then we get what we want.
Master method:
The master method applies to recurrences of the form
T(n) = a T(n/b) + f (n)
where a ≥ 1, b > 1, and f is asymptotically positive.
Three common cases:
1. f (n) = O(n^(logba – ε)) for some constant ε > 0.
Solution: T(n) = Θ(nlogba) .
2. f (n) = Θ(n^(logba) lgkn) for some constant k ≥ 0.
Solution: T(n) = Θ(n^(logba) lgk+1n) .
3. f (n) = Ω(n^(logba + ε)) for some constant ε > 0. and f (n) satisfies the regularity condition that a f (n/b) ≤ c f (n) for some constant c < 1.
Solution: T(n) = Θ( f (n)) .
The master method is theory,just use it a lot.