Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cn k 1.a < b k T(n) ~ n k 2.a = b k T(n) ~ n k log b n 3.a > b k T(n) ~ n log b a.

Similar presentations


Presentation on theme: "Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cn k 1.a < b k T(n) ~ n k 2.a = b k T(n) ~ n k log b n 3.a > b k T(n) ~ n log b a."— Presentation transcript:

1 Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cn k 1.a < b k T(n) ~ n k 2.a = b k T(n) ~ n k log b n 3.a > b k T(n) ~ n log b a

2 Derivation of Master Theorem Recurrence relation: T(n) = aT(n/b) + f(n) Assume problem size is b k T(b k ) = aT(b k /b) + f(b k ) = aT(b k-1 ) + f(b k ) = a(aT(b k-1 /b)+f(b k-1 )) + f(b k ) = a 2 T(b k-2 ) + af(b k-1 ) + f(b k ) = a k [T(1) + ]

3 Derivation of Master Theorem Since k = log b n a k =a log b n Property of logs: log c x = log c d *log d x a log b n = a (log b a * log a n) = a (log a n * log b a) = (a log a n ) * log b a = n log b a Finally, by letting f(n) = n d and T(1) = constant, we get: n log b a

4 Some Useful Things To Remember Logarithms: –log a (xy) = log a x + log a y (previous page) –log a (x y ) = y log a x (via rule 1, repeated multiplication) –log a (x/y) = log a x-log a y (via rule 1 and 2; log a (xy -1 ) = log a x + log a y -1 = log a x+(-1*log a y) –log a x = log a b*log b x (base conversions) Let b = a s and x = b t. Substituting x = (a s ) t. Take log a of both sides: log a x = log a ((a s ) t ) RHS: t*log a (a s ) = t*s = log b x*log a b

5 Derivation of Master Theorem n log b a Sum is a geometric series The sum = log b n if (b d == a) otherwise sum = (b d /a) Why this sum?

6 Derivation of Master Theorem n log b a Sum is a geometric series The sum = log b n if (b d == a) If (b d == a) n log b a *log b n n log b a * log b n and since b d == a => n d * log b n

7 Derivation of Master Theorem n log b a Sum is a geometric series otherwise sum = (b d /a) If (b d > a) then b d /a > 1 and sum ~ O((b d /a) log b n)  n log b a* (b d /a) log b n  a log b n (b d /a) log b n  O(b dlog b n ) O((b log b n ) d )= O(n d ) If (b d < a), then b d /a < 1 and sum converges ~ O(1)  n log b a * 1 = O(n log b a )

8 Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cn k 1.a < b k T(n) ~ n k 2.a = b k T(n) ~ n k log b n 3.a > b k T(n) ~ n log b a


Download ppt "Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cn k 1.a < b k T(n) ~ n k 2.a = b k T(n) ~ n k log b n 3.a > b k T(n) ~ n log b a."

Similar presentations


Ads by Google