Master Method
Cookbook for recursions of the type:
T (n) = a T ( n/b ) + f (n) :: a ³ 1,
b > 1, f (n) asymptotically positive
T (n) = a T ( n/b ) + f (n)
Split into 'a' pieces, each piece of size
'n/b' overhead of divide and conquer is ' f (n)'
For example:
Merge-Sort T (n) = 2 T ( n/2 ) + Q
(n) :: so a = b = 2, and f (n) = Q
(n)
Master theorem has three cases
-
If f (n) = O ( n logb a-e
) for some constant e > 0, then T (n) = Q
( n logb a )
-
If f (n) = Q ( n logb
a ), then T (n) = ( n logb a lg n )
-
If f (n) = W ( n logb
a+e ) for some constant e
> 0, AND if a f (n/b) £ c f (n) for some
c < 1 and " n ³
n0 then:
T (n) = Q ( f
(n))
Note:: All three cases compare n logb
a to f (n).
-
f (n) £ c ( n logb
a-e )
-
c2 ( n logb a ) £
f (n) £ c1 ( n logb
a )**
-
f (n) ³ c ( n logb
a+e )
** Special case multiplies by lg n
Master theorem examples:
T (n) = 2 T ( n/2 ) + n
n log2 2 = n1
f (n) = Q (n) Þ
case 2
therefore T (n) = Q ( n lg n)
T (n) = 9 T (n/3) + n
n log3 9 = n2
f (n) = O ( n2-1) Þ case
1 ( e = 1 )
therefore T (n) = Q ( n2 )
T (n) = 3 T (n/4) + n lg n
n log4 3 » n0.8
n lg n = W (n) = W
( n log4 3+e ) Þ
case 3 ( e »
0.2 )
therefore T (n) = Q (n lg n)
|