You are on page 1of 3
Master Theorem: Practice Problems and Solutions Master Theorem The Master Theorem applies to recurrences of the following form: T(n) = aT(n/b) + f(r) where a > 1 and b> 1 are constants and f(n) is an asymptotically positive function, ‘There are 3 eases 1. If f(n) = O(n! 4-4) for some constant € > 0, then T(n) = O(n!™*), 2. If fn) = O(n!" log n) with! & > 0, then T(n) = @(n" tog! n). 3. If F(n) = Onl +4*) with € > 0, and f(n) satisfies the regularity condition, then T(n) = @(F(n)). Regularity condition: af(/b) < ef(n) for some constant ¢ <1 and all sufficiently lange n. Practice Problems For each of the following recurrences, give an expression for the runtime T(x) if the recurrence can be solved with the Master Theorem, Otherwise, indicate that the Master Theorem does not apply. 1, P(n) = 30 (n/2) +n? 2. P(n) = AP (n/2) +n? 3. Tn) =T(n/2) +2" 4. T(n) T(n/2) +n" 5. T(n) = 16T (n/a) +0 6. T(n) = 27(n/2) + nlogn T(n) = 2T(n/2) + n/logn T(n) = 20 (n/4) + 005 T(n) = O.5T(n/2) + 1/n T(n) = 167 (n/4) +n! _ P(n) = VEE(n/2) + logn T(n) = 37 (n/2) +n T(n) = 3T(n/3)+ vn T(n) = AT(n/2)-+en T(n) = 37(n/4) + mlogn T(n) = 7 (n/3) + n/2 T(n) = 6T(n/3) + n*logn T(n) = AT(n/2)+n/ logn T(x) = 64T(n/8) ~ n®logn |. T(n) = TP (n/3) +n? . T(n) = AT (n/2) + logn, . T(n) = T(n/2) + n(2 — cosn) Solutions 1. Tn) = 37 (n/2) +n? =+ T(n) = O(n?) (Case 3) T(n) = 4T(n/2) +n? + T(n) = O(n? logn) (Case 2) 1(n) = T(n/2) +2" = @(2") (Case 3) T(n) = 2° (n/2) +n" —+ Does not apply (a is not constant) T(n) = 167(n/4) +n = T(n) = O(n?) (Case 1) T(n) = 27 (n/2) + mlogn =+ T(n) = nlog? n (Case 2) T(n) = 27 (n/2) +n/ logn —+ Does not apply (non-polynomial difference between f(n) and mn!) T(n) = 27(n/4) +0! => Tin) = O(n!) (Case 3) Tn) = 0.5E(n/2) + 1) => Does not apply (a <1) T(n) = 167(n/4) +n! = T(n) = O(n!) (Case 3) . P(n) = VEE(n/2)-+ logn => T(n) = OV) (Case 1) T(n) = 3T(n/2)-+n => Tin) = @(nl8%) (Case 1) T(n) = 31 (n/3) + V8 = T(n) = O(n) (Case 1) 14, T(n) = AT (n/2) +n = T(n) = O(n?) (Case 1) . T(n) = 87 (n/4) + nlogn => T(n) = @(nlogn) (Case 3) T(n) = 81 (n/3) + 0/2 => T(n) = O(n logn) (Case 2) 17. T(n) = 6T(n/3) +n? logn => T(n) = (n* logn) (Case 3) T(n) = AP(n/2) + nf logn = T(n) = O(n?) (Case 1) |. T(n) = GAT (n/8) — n®logn =+ Does not apply ({(n) is not positive) T(n) = 70 (n/3) +n? = T(n) = O(n?) (Case 3) T(n) = AP(n]2) + logn = T(n) = O(n®) (Case 1) 22, T(n) = T(n/2) + n(2—cosn) —+ Does not apply. We are in Case 3, but the regularity condition is, violated. (Consider n= 2rk, where k is odd and arbitrarily large. For any such choice of rn, you can show that ¢ > 8/2, thereby violating the regularity condition.)

You might also like