210 likes | 1.44k Vues
Recurrence: Master Theorem. T(n) = aT(n/b) + f (n) where f (n)=c n k a < b k T(n) ~ n k a = b k T(n) ~ n k log b n a > b k T(n) ~ n log b a. Derivation of Master Theorem. Recurrence relation: T(n) = aT(n/b) + f(n)
E N D
Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cnk • a < bk T(n) ~ nk • a = bk T(n) ~ nk logbn • a > bk T(n) ~ nlog b a
Derivation of Master Theorem Recurrence relation: T(n) = aT(n/b) + f(n) Assume problem size is bk T(bk) = aT(bk/b) + f(bk) = aT(bk-1) + f(bk) = a(aT(bk-1/b)+f(bk-1)) + f(bk) = a2T(bk-2) + af(bk-1) + f(bk) = ak[T(1) + ]
Derivation of Master Theorem Since k = logbn ak=alogbn Property of logs: logcx = logcd *logdx alogbn = a (logba * logan) = a (logan * logba) = (alogan) * logba = nlogba Finally, by letting f(n) = nd and T(1) = constant, we get: nlogba nlogba
Some Useful Things To Remember • Logarithms: • loga(xy)= logax + logay (previous page) • loga(xy)= y logax (via rule 1, repeated multiplication) • loga(x/y) = logax-logay (via rule 1 and 2; loga(xy-1) = logax + logay-1= logax+(-1*logay) • logax = logab*logbx (base conversions) Let b = as and x = bt. Substituting x = (as)t. Take loga of both sides: logax = loga((as)t) RHS: t*loga(as) = t*s = logbx*logab
Derivation of Master Theorem nlogba Sum is a geometric series The sum = logbn if (bd == a) otherwise sum = (bd/a) Why this sum?
Derivation of Master Theorem nlogba Sum is a geometric series The sum = logbn if (bd == a) If (bd == a) nlogba*logbn nlogba * logbn and since bd == a => nd * logbn
Derivation of Master Theorem nlogba Sum is a geometric series otherwise sum = (bd/a) If (bd > a) then bd/a > 1 and sum ~ O((bd/a)logbn) nlogba* (bd/a)logbn alogbn (bd/a)logbn O(bdlogbn)O((blogbn)d)= O(nd) If (bd < a), then bd/a < 1 and sum converges ~ O(1) nlogba * 1 = O(nlogba)
Recurrence: Master Theorem T(n) = aT(n/b) + f (n) where f (n)=cnk • a < bk T(n) ~ nk • a = bk T(n) ~ nk logbn • a > bk T(n) ~ nlog b a