Download presentation
Presentation is loading. Please wait.
1
Using The Master Method Case 1
T(n) = 9T(n/3) + n a=9, b=3, f(n) = n nlogb a = nlog3 9 = (n2) Since f(n) = O(nlog3 9 - ) = O(n2-0.5) = O(n1.5) where =0.5 case 1 applies: Thus the solution is T(n) = (n2)
2
Using The Master Method Case 2
T(n) = T(2n/3) + 1 a=1, b=3/2, f(n) = 1 nlogba = nlog3/21 = n0 = 1 Since f(n) = (nlogba) = (1) case 2 applies: Thus the solution is T(n) = (lg n)
3
Using The Master Method Case 3
T(n) = 3T(n/4) + n lg n a=3, b=4, f(n) = n lg n nlogba = nlog43 = n0.793 = n0.8 Since f(n) = W(nlog43+) = W(n )= W(n) where 0.2, and for sufficiently large n, a . f(n/b) = 3(n/4) lg(n/4) < (3/4) n lg n for c = 3/4 case 3 applies: Thus the solution is T(n) = (n lg n)
4
When the Master Method does not apply to recurrence
T(n) = 2T(n/2) + n lg n a = 2, b = 2, f(n) = n lg n, and nlogba = n Note that f(n) = n lg n is asymptotically larger than nlogba = n …. It might seem that case 3 should apply. The problem is that it is not polynomially larger. The ratio f(n) / nlogba = (n lg n) / n = lg n is asymptotically less than nε for any positive constant ε. The recurrence falls into the gap between case 2 and case 3.
5
Recursion tree view f(n) f(n/b) f(n) a … af(n/b) f(n/b2) a2f(n/b2)
Θ(1) f(n) f(n/b) f(n/b2) a … f(n) af(n/b) a2f(n/b2)
6
Examples Ex. T(n) = 4T(n/2) + n Ex. T(n) = 4T(n/2) + n2
a = 4, b = 2, f (n) = n nlogba = n2 f Since f (n) = O(n2 – ) for = 1 Case 1 applies T(n) = Θ(n2). Ex. T(n) = 4T(n/2) + n2 a = 4, b = 2, f(n) = n2 nlogba = n2 Since f (n) = Θ(n2). Case 2 applies T(n) = Θ(n2lgn).
7
Examples Ex. T(n) = 4T(n/2) + n3 Ex. T(n) = 4T(n/2) + n2/lgn
a = 4, b = 2, f (n) = n3 nlogba = n2 case 3: f (n) = Ω(n2 + ) for = 1 and 4(n/2)3 ≤ cn3 for c = 1/2. T(n) = Θ(n3). Ex. T(n) = 4T(n/2) + n2/lgn a = 4, b = 2, f (n) = n2/lgn Master method does not apply.
8
Master Method – Examples
T(n) = 16T(n/4)+n a = 16, b = 4, nlogba = nlog416 = n2. f(n) = n = O(nlogba-) = O(n2- ), where = 1 Case 1. Hence, T(n) = (nlogba ) = (n2). T(n) = T(3n/7) + 1 a = 1, b=7/3, and nlogba = nlog 7/3 1 = n0 = 1 f(n) = 1 = (nlogba) Case 2. Therefore, T(n) = (nlogba lg n) = (lg n)
9
Simplified Master Theorem
Let a 1 and b > 1 be constants and let T(n) be the recurrence T(n) = a T(n/b) + c nk defined for n 0. 1. If a > bk, then T(n) = ( nlogba ). 2. If a = bk, then T(n) = ( nk lg n ). 3. If a < bk, then T(n) = ( nk ).
10
Examples T(n) = 16T(n/4) + n T(n) = T(3n/7) + 1 a = 16, b = 4, k=1
T(n) = ( nlogba ) = ( nlog416 ) T(n) = (n2) T(n) = T(3n/7) + 1 a = 1, b=7/3, k = 0 1 = (7/3)0 1 = 1 a = bk T(n) = ( nk lg n ) = ( n0 lg n ) T(n) = ( lg n ).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.