T(n)=aT(n/b)+f(n)
여기에서 "n/b"는 ⌈n/b⌉ 혹은 ⌊n/b⌋를 의미함.
(a≥1,b>1,and f(n)>0)
Case 1
f(n)=O(nlogba−ϵ) for some constant ϵ>0
f(n) is pollynomially smaller than nlogba
Soluion: T(n)=Θ(nlogba)
Intuitively: Cost is dominated by leaves.
Case 2
f(n)=Θ(nlogba lgkn),where k≥0
f(n) is within a polylog factor of nlogba, but not smaller.
Solution: T(n)=Θ(nlogbalgk+1n)
Intuitively: Cost is nlogbalgkn at each level, and there are Θ(lgn) levels.
Case 3
f(n)=Θ(nlogba+ϵ) for some constant ϵ>0 and f(n) satisfies the regularity condition af(n/b)≤cf(n) for some constant c<1 and all sufficiently large n.
f(n) is polynomially greater than nlogba
Solution: T(n)=Θ(f(n))
Intuitively: Cost is dominated by root.
Example
- T(n)=9T(n/3)+n
- f(n)=n
- nlog39=n2→Case 1→T(n)=Θ(n2)
- T(n)=T(2n/3)+1
- f(n)=1
- nlog3/21=n0=1→Case 2→T(n)=Θ(logn)
- T(n)=2T(n/2)+Θ(n)
- f(n)=Θ(n)
- nlog22=n1→Case 2→T(n)=Θ(nlogn)
- T(n)=5T(n/2)+Θ(n3)
- nlog25 vs. n3
- af(n/b)=5(n/2)3=5n3/8≤cn3for c=5/8<1
- Case 3→T(n)=Θ(n3)