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...
-
Upload
junior-brown -
Category
Documents
-
view
225 -
download
7
Transcript of 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...
Recurrence: Master Theorem
T(n) = aT(n/b) + f (n) where f (n)=cnk
1. a < bk T(n) ~ nk
2. a = bk T(n) ~ nk logbn
3. 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) + ]
k
j
jj abf1
/)(
Derivation of Master Theorem
Since k = logbnak=alog
bn
Property of logs: logcx = logcd *logdxalog
bn = a (log
ba * log
an) = a (log
an * log
ba) = (alog
an) * log
ba = nlog
ba
Finally, by letting f(n) = nd and T(1) = constant, we get:
nlogba
nlogba
n
j
jdjb
ablog
1
/
n
j
jdb
ablog
1
)/(
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
nlogb
a
Sum is a geometric series
The sum = logbn if (bd == a)
otherwise sum = (bd/a)
Why this sum?
n
j
jdb
ablog
1
)/(
1)/(
1)/( log
ab
abd
nd b
1
)1(
11
)1(11
1
11)(
11
1
1
0
c
cc
c
cc
c
cc
c
ccc
nnnn
i
nn
i
ii
Derivation of Master Theorem
nlogb
a
Sum is a geometric series
The sum = logbn if (bd == a)
If (bd == a) nlogb
a*logbn
nlogb
a * logbn and since bd == a => nd * logbn
n
j
jdb
ablog
1
)/(
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)log
bn alog
bn (bd/a)log
bn O(bdlog
bn) O((blog
bn)d)=
O(nd)
If (bd < a), then bd/a < 1 and sum converges ~ O(1) nlog
ba * 1 = O(nlog
ba)
n
j
jdb
ablog
1
)/(
1)/(
1)/( log
ab
abd
nd b
Recurrence: Master Theorem
T(n) = aT(n/b) + f (n) where f (n)=cnk
1. a < bk T(n) ~ nk
2. a = bk T(n) ~ nk logbn
3. a > bk T(n) ~ nlog b a