Master Method

James·2023년 2월 14일
0
post-custom-banner

T(n)=aT(n/b)+f(n)T(n)=aT(n/b) + f(n)

여기에서 "n/bn/b"는 n/b\lceil{n/b}\rceil 혹은 n/b\lfloor{n/b}\rfloor를 의미함.
(a1,b>1,and f(n)>0)(a\geq1, b>1, and\ f(n) > 0)

Case 1

f(n)=O(nlogbaϵ)f(n)=O(n^{log_b a-\epsilon}) for some constant ϵ>0\epsilon>0

f(n) is pollynomially smaller than nlogban^{log_b a}
Soluion: T(n)=Θ(nlogba)T(n)=\Theta(n^{log_b a})
Intuitively: Cost is dominated by leaves.

Case 2

f(n)=Θ(nlogba lgkn),where k0f(n)=\Theta(n^{log_b a\ lg^{k}n}), where\ k\geq0

f(n)f(n) is within a polylog factor of nlogban^{log_b a}, but not smaller.
Solution: T(n)=Θ(nlogbalgk+1n)T(n)=\Theta(n^{log_b a}lg^{k+1}n)
Intuitively: Cost is nlogbalgknn^{log_b a}lg^k n at each level, and there are Θ(lgn)\Theta(lgn) levels.

Case 3

f(n)=Θ(nlogba+ϵ)f(n) = \Theta(n^{log_b a+\epsilon}) for some constant ϵ>0\epsilon > 0 and f(n)f(n) satisfies the regularity condition af(n/b)cf(n)af(n/b)\leq cf(n) for some constant c<1c<1 and all sufficiently large n.

f(n) is polynomially greater than nlogban^{log_b a}
Solution: T(n)=Θ(f(n))T(n) = \Theta(f(n))
Intuitively: Cost is dominated by root.

Example

  • T(n)=9T(n/3)+nT(n)=9T(n/3)+n
    - f(n)=nf(n)=n
    - nlog39=n2Case 1T(n)=Θ(n2)n^{log_3 9}=n^2 \rightarrow Case\ 1\rightarrow T(n)=\Theta(n^2)
  • T(n)=T(2n/3)+1T(n)=T(2n/3)+1
    - f(n)=1f(n)=1
    - nlog3/21=n0=1Case 2T(n)=Θ(logn)n^{log_{3/2}1}=n^0=1 \rightarrow Case\ 2\rightarrow T(n)=\Theta(logn)
  • T(n)=2T(n/2)+Θ(n)T(n)=2T(n/2)+\Theta(n)
    - f(n)=Θ(n)f(n)=\Theta(n)
    - nlog22=n1Case 2T(n)=Θ(nlogn)n^{log_2 2}=n^1 \rightarrow Case\ 2\rightarrow T(n)=\Theta(nlogn)
  • T(n)=5T(n/2)+Θ(n3)T(n)=5T(n/2)+\Theta(n^3)
    - nlog25n^{log_2 5} vs. n3n^3
    - af(n/b)=5(n/2)3=5n3/8cn3for c=5/8<1af(n/b)=5(n/2)^3 = 5n^3/8 \leq cn^3 for\ c=5/8 < 1
    - Case 3T(n)=Θ(n3)Case\ 3 \rightarrow T(n)=\Theta(n^3)
profile
System Software Engineer
post-custom-banner

0개의 댓글