1 / 8

Recurrence: Master Theorem

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)

astra
Download Presentation

Recurrence: Master Theorem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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) + ]

  3. 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

  4. 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

  5. Derivation of Master Theorem nlogba Sum is a geometric series The sum = logbn if (bd == a) otherwise sum = (bd/a) Why this sum?

  6. 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

  7. 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)

  8. 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

More Related