E N D
1. Recurrence, Summations Reading: Chap 4
2. Recurrence
Solve for n=2k: T(n)=lg n + 1=T(lg n)
3. Boundary condition Solve: T(n)=(T(n/2))2
T(1)=2 ? T(n)=T(2n)
T(1)=3 ? T(n)=T(3n)
T(1)=1 ? T(n)=T(1)
Different B.C. ? different solution.
4. Solving recurrences Substitution method
Iterating the recurrence
Recursion tree
Master method
Generating function
5. Changing variables
Let m = lg n, i.e. 2m=n.? T(2m)=2T(2m/2)+m
Let S(m)=T(2m).? S(m)=2S(m/2)+m
By recursion tree method:S(m)=O(m lg m)
T(n)=T(2m)=S(m)=O(m lg m)=O(lg n lglg n)
6. Substitution method (4.1) Guess the solution
Verify by induction and solve for const
eg. T(n)=4T(n/2)+n
Guess T(n)=O(n3)
Assume T(k)=ck3 for k<n
Prove T(n)=cn3 by induction.
But O(n3) is not a tight bound!Can show O(n2)!
7. Fallacious argument Assume T(k)=ck2 for k<n
8. Correct Solution Substract a lower-order term.
Assume T(k)=c1k2-c2k for k<n
9. Iterating the recurrence (4.2)
10. Recursion tree Visualizing iterating method
eg. T(n)=T(n/4)+T(n/2)+n2
11. Recursion tree (cont.)
12. Master Method For T(n)=aT(n/b)+f(n), T(1)=T(1)
Total :
13. Case 1: nlogba/f(n)=O(ne), for some const e>0.
weight of each level increases geometrically from root to leaves.
Leaves contain constant fraction of total weight.
T(n)=(nlogba)
14. Case 2: f(n)/nlogba=T(logkn), for some k=0.
I.e. f(n) and are within a polylogarithmic factor.
Weight decreases
T(n)=T(nlogbalogk+1n)
15. Case 3: f(n)/nlogba=O(ne), for some const e>0.
Weight is geometrically decreasing.
Root contains constant fraction of total weight.
T(n)=T(f(n))
Note: the above cases doesnt cover all possible cases!
16. Master method examples Merge sort: T(n)=2T(n/2)+T(n)
a=b=2, f(n)=n
nlog22=n
f(n)/n=T(1)=T(log0n), case 2.
T(n)= T(nlog22log0+1n)= T(n log n)
T(n)=4T(n/2)+n3
n3/nlog24=n, case 3.
T(n)=T(n3)
17. An Exception T(n)=4T(n/2)+n2/lg n
No case applies!
Sol: T(n)=(n2lglg n) ~ by substitution method!
18. Generating function Fibonacci numbers:
F0=0, F1=1, Fi=Fi-1+Fi-2 for i = 2.
0, 1, 1, 2, 3, 5, 8,
(1-z-z2)G(z)=z, G(z)=z/(1-z-z2)