Design and Analysis of Algorithms: CSE 5311 Lecture 4 Master Theorem
Design and Analysis of Algorithms: CSE 5311 Lecture 4 Master Theorem
CSE 5311
Lecture 4 Master Theorem
• T(n) = 9T(n/3)+n;
– a=9,b=3, f(n) =n
– nlogba = nlog39 = Θ (n2)
– f(n)=O(nlog39-ε) for ε=1
– By case 1, T(n) =Θ (n2).
• T(n) = T(2n/3)+1
– a=1,b=3/2, f(n) =1
– nlogba = nlog3/21 = Θ (n0) = Θ (1)
– By case 2, T(n)= Θ(lg n).
6
Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 6
Application of Master Theorem
• T(n) = 3T(n/4)+nlg n;
– a=3,b=4, f(n) =nlg n
– nlogba = nlog43 = Θ (n0.793)
– f(n)= Ω(nlog43+ε) for ε≈0.2
– Moreover, for large n, the “regularity” holds for c=3/4.
af(n/b) =3(n/4)lg (n/4) ≤ (3/4)nlg n = cf(n)
– By case 3, T(n) =Θ (f(n))=Θ (nlg n).
7
Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 7
Exception to Master Theorem
• T(n) = 2T(n/2)+nlg n;
– a=2,b=2, f(n) =nlg n
– nlogba = nlog22 = Θ (n)
– f(n) is asymptotically larger than nlogba , but not polynomially
larger because
– f(n)/nlogba = lg n, which is asymptotically less than nε for any
ε>0.
– Therefore, this is a gap between 2 and 3.
8
Dept. CSE, UT Arlington CSE5311 Design and Analysis of Algorithms 8
Where Are the Gaps
• Proof:
– By iterating the recurrence
– By recursion tree (See figure 4.3)
• Lemma 4.3:
– Let constants a ≥ 1, b>1, f(n) be a nonnegative function
defined on exact power of b, then
logbn-1
– g(n)= ∑ ajf(n/bj) can be bounded asymptotically for exact
j=0
power of b as follows:
=O(f(n))
– Thus, g(n)=Θ(f(n))
logbn -1
– T(n) =
j=0
∑
Θ(nlogba)+ ajf(nj)
logbn -1
g(n) = ∑
j=0
aj f(nj)