Introduction to Algorithms Second Edition by

The master theorem for recurrences
 Let T(n) = a T(n/b) + f(n) where
 a  1, b > 1 are constants
 f(n) is an asymptotically positive function
 Then, T(n) can be bounded asymptotically as follows
 If
f ( n)  O ( n
logb a 
)
for some  > 0, then
 If
f (n)  (nlogb a )
then
 If
f (n)  (nlogb a  )
for some  > 0, and
T (n)  (n logb a )
T (n)  (nlogb a lg n)
if, for all sufficiently large n and a constant c < 1,
then
af (n / b)  cf (n)
T (n)  ( f (n))
ECOE 556, Fall 2006
The master theorem: Intuition
ECOE 556, Fall 2006
The master theorem: Examples
T(n) = a T(n/b) + f(n)
 If
f ( n)  O ( n
logb a 
)
for some  > 0, then
T (n)  (n logb a )
 Example: T(n) = 9T(n/3) + n
 If
f (n)  (nlogb a )
then
T (n)  (nlogb a lg n)
 Example: T(n) = T(2n/3) + 1
ECOE 556, Fall 2006
The master theorem: Examples
T(n) = a T(n/b) + f(n)
 If f (n)  (n log a  )
b
for some  > 0, and
if, for all sufficiently large n and a constant c < 1, af (n / b)  cf (n)
then
T (n)  ( f (n))
 Example: T(n) = 3T(n/4) + n lg n
 Example where the master theorem does not apply:
 T(n) = 2T(n/2) + n lg n
ECOE 556, Fall 2006
The master theorem: Intuition
ECOE 556, Fall 2006