Professional Documents
Culture Documents
Definition
T (n): upper-bound of function at level n
Recurrance: expression of T (n) in terms of runtime of recursive calls.
Base case: T (1) k
n > 1 : T (n) (recursive work) + (current work)
O(nd log n) : a = bd
T (n) =
O(nd )
: a < bd
O(nlogb a )
: a > bd
(2)
Note: In case 1, the base of the logarithm doesnt matter because the
difference is a constant factor.
Proof
n
b
+ cnd
T (1) = f
(3)
(4)
(5)
(6)
(7)
(8)
Master Method
Let k = logb n be the number of iterations in the recurrence before T
reaches its base case.
T (n) = a f +
k1
X
ai c
i=0
= ak f + cnd
= ak f + cnd
n d
(9)
bi
k1 i
X
a
bid
i=0
(10)
k1
X
a i
bd
i=0
k
a
(11)
= ak f + cnd ba
1
d
b log n
a b
nd 1
= nlogb a f + cnd
a
1
bd
= nlogb a f +
calogb n cnd
a
1
bd
c
cnd
T (n) = a
+ f nlogb a a
1
1
bd
bd
(12)
(13)
(14)
(15)
Note that the geometric sum formula is not valid when a/bd = 1 so the
final formula doesnt work for that case, but it is a special case that makes
the original summation trivial to solve. The full definition of the Master
Theorem, accounting for all 3 possible cases, is as follows:
(nlogb a ) a > bd
cnd
nlogb a d
=
f + dc
(nd )
a < bd
T (n) =
ab 1
ab 1
d
n (f + c logb n) = (nd logb n)
a = bd
(16)
Superposition If the work done in each recursive call isnt perfectly
modeled by cnd because there are extra terms, use the theorem on each part
of the recurrence letting f = 0, add the solutions together, and then finally
add f nlogb a .
2