Notes on Better Master Theorems
-
Upload
na-nasakol -
Category
Documents
-
view
219 -
download
0
Transcript of Notes on Better Master Theorems
-
8/12/2019 Notes on Better Master Theorems
1/9
N o t e s o n B e t t e r M a s t e r T h e o r e m s
f o r D i v i d e - a n d - C o n q u e r R e c u r r e n c e s
T o m L e i g h t o n
M a t h e m a t i c s D e p a r t m e n t a n d
L a b o r a t o r y f o r C o m p u t e r S c i e n c e
M a s s a c h u s e t t s I n s t i t u t e o f T e c h n o l o g y
C a m b r i d g e , M a s s a c h u s e t t s 0 2 1 3 9
O c t o b e r 9 , 1 9 9 6
A b s t r a c t
T e c h n i q u e s f o r s o l v i n g d i v i d e - a n d - c o n q u e r r e c u r r e n c e s a r e r o u t i n e l y t a u g h t t o t h o u s a n d s o f
C o m p u t e r S c i e n c e s t u d e n t s e a c h y e a r . T h e d o m i n a n t a p p r o a c h t o s o l v i n g s u c h r e c u r r e n c e s i s
k n o w n a s t h e M a s t e r M e t h o d 2 . R e c e n t l y , A k r a a n d B a z z i 1 d i s c o v e r e d a s u r p r i s i n g l y e l e g a n t
g e n e r a l i z a t i o n o f t h e M a s t e r M e t h o d t h a t y i e l d s a v e r y s i m p l e f o r m u l a f o r s o l v i n g m o s t d i v i d e -
a n d - c o n q u e r r e c u r r e n c e s . I n t h e s e n o t e s , w e p r o v i d e a s i m p l e i n d u c t i v e p r o o f o f t h e A k r a - B a z z i
r e s u l t a n d w e e x t e n d t h e r e s u l t t o h a n d l e v a r i a t i o n s o f d i v i d e - a n d - c o n q u e r r e c u r r e n c e s t h a t
c o m m o n l y a r i s e i n p r a c t i c e .
1 I n t r o d u c t i o n
D i v i d e - a n d - c o n q u e r r e c u r r e n c e s a r e u b i q u i t o u s i n t h e a n a l y s i s o f a l g o r i t h m s . M a n y m e t h o d s a r e
k n o w n f o r s o l v i n g r e c u r r e n c e s s u c h a s
T n =
1 i f n = 1
2 T d n = 2 e + O n i f n 1 ;
b u t p e r h a p s t h e m o s t w i d e l y t a u g h t a p p r o a c h i s t h e M a s t e r M e t h o d t h a t i s d e s c r i b e d i n t h e s e m i n a l
a l g o r i t h m s t e x t b y C o r m e n , L e i s e r s o n a n d R i v e s t 2 .
T h e M a s t e r M e t h o d i s f a i r l y p o w e r f u l a n d r e s u l t s i n a c l o s e d f o r m s o l u t i o n f o r d i v i d e - a n d - c o n q u e r
r e c u r r e n c e s w i t h a s p e c i a l b u t c o m m o n l y - o c c u r r i n g f o r m . R e c e n t l y A k r a a n d B a z z i 1 d i s c o v e r e d
a f a r m o r e g e n e r a l s o l u t i o n t o d i v i d e - a n d - c o n q u e r r e c u r r e n c e s . T h e A k r a - B a z z i a n a l y s i s i s b a s e d
o n a s p e c i a l f u n c t i o n a l t r a n s f o r m t h a t t h e y c a l l t h e o r d e r t r a n s f o r m . "
I n t h e s e n o t e s , w e g i v e a s i m p l e i n d u c t i v e p r o o f o f t h e A k r a - B a z z i r e s u l t t h a t i s s u i t a b l e f o r u s e
i n a n u n d e r g r a d u a t e a l g o r i t h m s o r d i s c r e t e m a t h c l a s s . W e a l s o s h o w t h a t t h e A k r a - B a z z i r e s u l t
h o l d s f o r a m o r e g e n e r a l c l a s s o f r e c u r r e n c e s t h a t c o m m o n l y a r i s e i n p r a c t i c e a n d t h a t a r e o f t e n
c o n s i d e r e d t o b e d i c u l t t o s o l v e .
1
-
8/12/2019 Notes on Better Master Theorems
2/9
2 T h e A k r a - B a z z i S o l u t i o n
W e b e g i n w i t h a s i m p l e i n d u c t i v e p r o o f o f t h e A k r a - B a z z i r e s u l t . T h e r e s u l t h o l d s f o r r e c u r r e n c e s
o f t h e f o r m :
T x =
1 f o r 1 x x
0
P
k
i = 1
a
i
T b
i
x + g x f o r x x
0
1
w h e r e
1
1 x 1 i s a r e a l n u m b e r ,
2 x
0
i s a c o n s t a n t s u c h t h a t x
0
1 = b
i
a n d x
0
1 = 1 , b
i
f o r 1 i k ,
3 a
i
0 i s a c o n s t a n t f o r 1 i k ,
4 b
i
2 0 ; 1 i s a c o n s t a n t f o r 1 i k ,
5 k 1 i s a c o n s t a n t , a n d
6 g x i s a n o n n e g a t i v e f u n c t i o n t h a t s a t i s e s t h e p o l y n o m i a l - g r o w t h c o n d i t i o n s p e c i e d b e l o w .
D e n i t i o n . W e s a y t h a t g x s a t i s e s t h e p o l y n o m i a l - g r o w t h c o n d i t i o n i f t h e r e e x i s t p o s i t i v e c o n -
s t a n t s c
1
, c
2
s u c h t h a t f o r a l l x 1 , f o r a l l 1 i k , a n d f o r a l l u 2 b
i
x ; x ,
c
1
g x g u c
2
g x
R e m a r k . I f g
0
x i s u p p e r b o u n d e d b y a p o l y n o m i a l i n x , t h e n g x s a t i s e s t h e p o l y n o m i a l -
g r o w t h c o n d i t i o n . F o r e x a m p l e , g x = x
l o g
x s a t i s e s t h e p o l y n o m i a l - g r o w t h c o n d i t i o n f o r a n y
c o n s t a n t s ; 2 R
T h e o r e m 1 1 . G i v e n a r e c u r r e n c e o f t h e f o r m s p e c i e d i n E q u a t i o n 1 , l e t p b e t h e u n i q u e r e a l
n u m b e r f o r w h i c h
P
k
i = 1
a
i
b
p
i
= 1 . T h e n
T x =
x
p
1 +
Z
x
1
g u
u
p + 1
d u
E x a m p l e s .
I f T x = 2 T x = 4 + 3 T x = 6 + x l o g x , t h e n p = 1 a n d T x = x l o g
2
x
I f T x = 2 T x = 2 +
8
9
T 3 x = 4 + x
2
= l o g x , t h e n p = 2 a n d T x = x
2
= l o g l o g x
I f T x = T x = 2 + l o g x , t h e n p = 0 a n d T x = l o g
2
x
I f T x =
1
2
T x = 2 + 1 = x , t h e n p = , 1 a n d T x = l o g x = x
I f T x = 4 T x = 2 + x , t h e n p = 2 a n d T x = x
2
1
T h e s e c o n d i t i o n s a r e s o m e w h a t l e s s r e s t r i c t i v e t h a n t h o s e o f 1 .
2
-
8/12/2019 Notes on Better Master Theorems
3/9
T h e p r o o f o f T h e o r e m 1 m a k e s u s e o f t h e f o l l o w i n g s i m p l e l e m m a f r o m c a l c u l u s .
L e m m a 1 . I f g x i s a n o n n e g a t i v e f u n c t i o n t h a t s a t i s e s t h e p o l y n o m i a l - g r o w t h c o n d i t i o n , t h e n
t h e r e a r e p o s i t i v e c o n s t a n t s c
3
, c
4
s u c h t h a t f o r 1 i k a n d a l l x 1 ,
c
3
g x x
p
Z
x
b x
g u
u
p + 1
d u c
4
g x
P r o o f . F r o m t h e p o l y n o m i a l - g r o w t h c o n d i t i o n w e k n o w t h a t
x
p
Z
x
b x
g u
u
p + 1
d u x
p
x , b
i
x
c
2
g x
m i n f b
i
x
p + 1
; x
p + 1
g
=
1 , b
i
c
2
m i n f 1 ; b
p + 1
i
g
g x
c
4
g x
w h e r e w e d e n e c
4
t o b e a c o n s t a n t f o r w h i c h
c
4
1 , b
i
c
2
m i n f 1 ; b
p + 1
i
g
f o r 1 i k
S i m i l a r l y ,
x
p
Z
x
b x
g u
u
p + 1
d u x
p
x , b
i
x
c
1
g x
m a x f b
i
x
p + 1
; x
p + 1
g
=
1 , b
i
c
1
m a x f 1 ; b
p + 1
i
g
g x
c
3
g x
w h e r e w e d e n e c
3
t o b e a c o n s t a n t f o r w h i c h
c
3
1 , b
i
c
2
m a x f 1 ; b
p + 1
i
g
f o r 1 i k
W e w i l l u s e i n d u c t i o n t o p r o v e T h e o r e m 1 , a n d s o i t w i l l b e h e l p f u l t o p a r t i t i o n t h e d o m a i n o f x
i n t o i n t e r v a l s I
0
= 1 ; x
0
a n d I
j
= x
0
+ j , 1 ; x
0
+ j f o r j 1
B y t h e d e n i t i o n o f x
0
, w e k n o w t h a t i f x 2 I
j
f o r s o m e j 1 , t h e n f o r 1 i k , b
i
x 2 I
j
f o r
s o m e j
0
j . T h i s i s b e c a u s e b
i
x b
i
x
0
+ j , 1 b
i
x
0
1 , a n d b e c a u s e b
i
x b
i
x
0
+ j
x
0
+ j , 1 , b
i
x
0
x
0
+ j , 1 . A s a c o n s e q u e n c e , w e k n o w t h a t t h e v a l u e o f T i n a n y i n t e r v a l
a f t e r 1 ; x
0
d e p e n d s o n l y o n t h e v a l u e s o f T i n p r i o r i n t e r v a l s .
3
-
8/12/2019 Notes on Better Master Theorems
4/9
P r o o f o f T h e o r e m 1 . W e r s t s h o w t h a t t h e r e i s a p o s i t i v e c o n s t a n t c
5
s u c h t h a t f o r a l l x x
0
,
T x c
5
x
p
1 +
Z
x
1
g u
u
p + 1
d u
T h e p r o o f i s b y i n d u c t i o n o n t h e i n t e r v a l I
j
c o n t a i n i n g x . T h e b a s e c a s e w h e n j = 0 f o l l o w s f r o m
t h e f a c t t h a t T x = 1 w h e n x 2 1 ; x
0
p r o v i d e d t h a t w e c h o o s e c
5
s m a l l e n o u g h .
T h e i n d u c t i v e s t e p i s a r g u e d a s f o l l o w s :
T x =
k
X
i = 1
a
i
T b
i
x + g x
k
X
i = 1
a
i
c
5
b
i
x
p
1 +
Z
b x
1
g u
u
p + 1
d u
+ g x b y i n d u c t i o n
= c
5
x
p
k
X
i = 1
a
i
b
p
i
1 +
Z
x
1
g u
u
p + 1
d u ,
Z
x
b x
g u
u
p + 1
d u
+ g x
c
5
x
p
k
X
i = 1
a
i
b
p
i
1 +
Z
x
1
g u
u
p + 1
d u ,
c
4
x
p
g x
+ g x b y L e m m a 1
= c
5
x
p
1 +
Z
x
1
g u
u
p + 1
d u ,
c
4
x
p
g x
+ g x
= c
5
x
p
1 +
Z
x
1
g u
u
p + 1
d u
+ g x , c
5
c
4
g x
c
5
x
p
1 +
Z
x
1
g u
u
p + 1
d u
p r o v i d e d t h a t c
5
1 = c
4
T h e p r o o f t h a t t h e r e i s a p o s i t i v e c o n s t a n t c
6
s u c h t h a t f o r a l l x x
0
,
T x c
6
x
p
1 +
Z
x
1
g u
u
p + 1
d u
i s n e a r l y i d e n t i c a l . W e n e e d o n l y i n s u r e t h a t c
6
i s c h o s e n l a r g e e n o u g h s o t h a t t h e b a s e c a s e i s
s a t i s e d a n d s o t h a t c
6
1 = c
3
. A s a c o n s e q u e n c e , w e c a n c o n c l u d e t h a t
T x =
x
p
1 +
Z
x
1
g u
u
p + 1
d u
;
a s c l a i m e d .
R e m a r k . I f g x g r o w s f a s t e r t h a n a n y p o l y n o m i a l i n x , t h e n T x = g x . H e n c e , T h e o r e m 1
d o e s n o t n e c e s s a r i l y h o l d i f g x d o e s n o t s a t i s f y t h e p o l y n o m i a l - g r o w t h c o n d i t i o n .
4
-
8/12/2019 Notes on Better Master Theorems
5/9
3 V a r i a t i o n s
A l t h o u g h t h e c l a s s o f r e c u r r e n c e s a n a l y i z e d i n S e c t i o n 2 i s q u i t e b r o a d , r e c u r r e n c e s t h a t a r i s e i n
p r a c t i c e o f t e n d i e r i n s m a l l w a y s f r o m t h e c l a s s s p e c i e d i n E q u a t i o n 1 . F o r e x a m p l e , i n a l g o r i t h m
d e s i g n , r e c u r r e n c e s o f t h e f o r m
T x
k
X
i = 1
a
i
T d b
i
x e + g x
a r e c o m m o n .
G e n e r a l l y s p e a k i n g , t h e i n c l u s i o n o f o o r s a n d c e i l i n g s i n a r e c u r r e n c e d o e s n o t s i g n i c a n t l y c h a n g e
t h e n a t u r e o f t h e s o l u t i o n e . g . , s e e 1 , 2 , b u t t h e p r o o f s o f t h i s f a c t t e n d t o b e f a i r l y t e d i o u s a n d
s p e c i a l i z e d i n n a t u r e . I n w h a t f o l l o w s , w e d e s c r i b e a g e n e r a l c l a s s o f v a r i a t i o n s w h i c h i n c l u d e s
o o r s a n d c e i l i n g s a n d w e s h o w t h a t t h e v a r i a t i o n s i n t h i s c l a s s d o n o t a e c t t h e s o l u t i o n o f t h e
r e c u r r e n c e u p t o c o n s t a n t f a c t o r s . I n p a r t i c u l a r , w e s h o w t h a t t h e s o l u t i o n o f T h e o r e m 1 h o l d s
f o r a l l r e c u r r e n c e s o f t h e f o r m :
T x =
1 f o r 1 x x
0
P
k
i = 1
a
i
T b
i
x + h
i
x + g x f o r x x
0
2
w h e r e
1 x , x
0
, a
i
, b
i
, k , a n d g x a l l s a t i s f y t h e c o n d i t i o n s s p e c i e d i n S e c t i o n 2 ,
2 . t h e r e i s s o m e c o n s t a n t 0 f o r w h i c h h
i
x x = l o g
1 +
x f o r 1 i k w h e n e v e r x x
0
,
3 . t h e r e e x i s t p o s i t i v e c o n s t a n t s c
1
a n d c
2
s u c h t h a t f o r a l l x 1 , f o r a l l 1 i k , a n d f o r a l l
u 2 b
i
x + h
i
x ; x ,
c
1
g x g u c
2
g x ;
a n d
4 x
0
i s c h o s e n t o b e a l a r g e e n o u g h c o n s t a n t
2
s o t h a t f o r a n y i k a n d a n y x x
0
,
a
1 ,
1
b
i
l o g
1 +
x
p
0
@
1 +
1
l o g
= 2
b
i
x +
x
o g
1 +
x
1
A
1 +
1
l o g
= 2
x
,
b
1 +
1
b
i
l o g
1 +
x
p
0
@
1 ,
1
l o g
= 2
b
i
x +
x
o g
1 +
x
1
A
1 ,
1
l o g
= 2
x
,
c
1
2
1 +
1
l o g
= 2
x
1 ,
d 2
1 ,
1
l o g
= 2
x
1
2
S u c h a c o n s t a n t v a l u e o f x
0
c a n b e s h o w n t o e x i s t u s i n g s t a n d a r d T a y l o r s e r i e s e x p a n s i o n s a n d a s y m p t o t i c a n a l y s i s .
5
-
8/12/2019 Notes on Better Master Theorems
6/9
F o r e x a m p l e , w e m i g h t c h o o s e h
i
s o t h a t
h
i
x = d b
i
x e , b
i
x ;
t h e r e b y e x t e n d i n g T h e o r e m 1 t o h a n d l e c e i l i n g f u n c t i o n s . I n t h i s c a s e , h
i
x 1 . W e c a n a l s o u s e
m u c h l a r g e r f u n c t i o n s , h o w e v e r . F o r e x a m p l e , w e c o u l d s e t h
i
x = ,
p
x o r h
i
x = x = l o g
2
x f o r
x 1
T o a n a l y z e t h e m o r e g e n e r a l r e c u r r e n c e , w e w i l l n e e d t h e f o l l o w i n g a n a l o g u e o f L e m m a 1 .
L e m m a 2 . T h e r e a r e p o s i t i v e c o n s t a n t s c
3
, c
4
s u c h t h a t f o r 1 i k a n d a l l x 1 ,
c
3
g x x
p
Z
x
b x + h x
g u
u
p + 1
d u c
4
g x
P r o o f . T h e p r o o f i s i d e n t i c a l t o t h a t f o r L e m m a 1 e x c e p t t h a t w e u s e c o n s t r a i n t 3 a b o v e i n p l a c e
o f t h e p o l y n o m i a l - g r o w t h c o n d i t i o n o f S e c t i o n 2 .
T h e o r e m 2 . G i v e n a r e c u r r e n c e o f t h e f o r m s p e c i e d i n E q u a t i o n 2 , l e t p b e t h e u n i q u e r e a l n u m b e r
f o r w h i c h
P
k
i = 1
a
i
b
p
i
= 1 . T h e n
T x =
x
p
1 +
Z
x
1
g u
u
p + 1
d u
P r o o f . T h e p r o o f i s v e r y s i m i l a r t o t h a t o f T h e o r e m 1 . T h e m a i n d i e r e n c e i s t h a t w e u s e a s l i g h t l y
s t r o n g e r i n d u c t i v e h y p o t h e s i s . I n p a r t i c u l a r , w e b e g i n b y s h o w i n g t h a t t h e r e i s a p o s i t i v e c o n s t a n t c
5
s u c h t h a t f o r a l l x x
0
,
T x c
5
x
p
1 +
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u
T h e p r o o f i s b y i n d u c t i o n o n t h e i n t e r v a l I
j
c o n t a i n i n g x . T h e b a s e c a s e w h e n j = 0 f o l l o w s f r o m t h e
f a c t t h a t T x = 1 w h e n x 2 1 ; x
0
p r o v i d e d t h a t c
5
i s c h o s e n t o b e a s m a l l e n o u g h c o n s t a n t .
6
-
8/12/2019 Notes on Better Master Theorems
7/9
T h e i n d u c t i v e s t e p i s a r g u e d a s f o l l o w s :
T x =
k
X
i = 1
a
i
T b
i
x + h
i
x + g x
k
X
i = 1
a
i
c
5
b
i
x + h
i
x
p
1 +
1
l o g
= 2
b
i
x + h
i
x
!
1 +
Z
b x + h x
1
g u
u
p + 1
d u
!
+ g x b y i n d u c t i o n
k
X
i = 1
a
i
b
p
i
c
5
x
p
1 ,
1
b
i
l o g
1 +
x
p
0
@
1 +
1
l o g
= 2
b
i
x +
x
o g
1 +
x
1
A
1 +
Z
x
1
g u
u
p + 1
d u ,
Z
x
b x + h x
g u
u
p + 1
d u
!
+ g x b y t h e b o u n d s o n h
k
X
i = 1
a
i
b
p
i
c
5
x
p
1 +
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u ,
c
4
x
p
g x
+ g x
b y c o n s t r a i n t 4 a o n x
0
a n d L e m m a 2
= c
5
x
p
1 +
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u ,
c
4
x
p
g x
+ g x
= c
5
x
p
1 +
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u
+ g x , c
5
c
4
1 +
1
l o g
= 2
x
g x
c
5
x
p
1 +
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u
p r o v i d e d t h a t c
5
1 = 2 c
4
b y c o n s t r a i n t 4 c o n x
0
T h e p r o o f o f t h e u p p e r b o u n d i s q u i t e s i m i l a r . I n t h i s c a s e , w e s h o w b y i n d u c t i o n t h a t t h e r e i s a
p o s i t i v e c o n s t a n t c
6
s u c h t h a t f o r a l l x x
0
,
T x c
6
x
p
1 ,
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u
7
-
8/12/2019 Notes on Better Master Theorems
8/9
T h e b a s e c a s e i s a s b e f o r e . T h e i n d u c t i v e s t e p i s a r g u e d a s f o l l o w s :
T x =
k
X
i = 1
a
i
T b
i
x + h
i
x + g x
k
X
i = 1
a
i
c
6
b
i
x + h
i
x
p
1 ,
1
l o g
= 2
b
i
x + h
i
x
!
1 +
Z
b x + h x
1
g u
u
p + 1
d u
!
+ g x b y i n d u c t i o n
k
X
i = 1
a
i
b
p
i
c
6
x
p
1 +
1
b
i
l o g
1 +
x
p
0
@
1 ,
1
l o g
= 2
b
i
x +
x
o g
1 +
x
1
A
1 +
Z
x
1
g u
u
p + 1
d u ,
Z
x
b x + h x
g u
u
p + 1
d u
!
+ g x b y t h e b o u n d s o n h
k
X
i = 1
a
i
b
p
i
c
6
x
p
1 ,
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u ,
c
3
x
p
g x
+ g x
b y c o n s t r a i n t 4 b o n x
0
a n d L e m m a 2
= c
6
x
p
1 ,
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u ,
c
3
x
p
g x
+ g x
= c
6
x
p
1 ,
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u
+ g x , c
3
c
6
1 ,
1
l o g
= 2
x
g x
c
6
x
p
1 ,
1
l o g
= 2
x
1 +
Z
x
1
g u
u
p + 1
d u
p r o v i d e d t h a t c
6
2 = c
3
b y c o n s t r a i n t 4 d o n x
0
H e n c e , w e c a n c o n c l u d e t h a t
T x =
x
p
1 +
Z
x
1
g u
u
p + 1
d u
;
a s d e s i r e d .
R e m a r k . I t i s w o r t h n o t i n g t h a t t h e x = l o g
1 +
x l i m i t o n t h e s i z e o f h
i
x i s n e a r l y t i g h t , s i n c e
t h e s o l u t i o n o f t h e r e c u r r e n c e
T x =
1 f o r 1 x x
0
2 T
x
2
+
x
o g x
f o r x x
0
i s T x = x l o g
1
x , w h i c h i s d i e r e n t t h a n t h e s o l u t i o n o f x f o r t h e r e c u r r e n c e w i t h o u t t h e
x = l o g x t e r m .
8
-
8/12/2019 Notes on Better Master Theorems
9/9
R e f e r e n c e s
1 M . A k r a a n d L . B a z z i . O n t h e s o l u t i o n o f l i n e a r r e c u r r e n c e e q u a t i o n s . " T o a p p e a r , 1 9 9 6 .
2 T h o m a s H . C o r m e n , C h a r l e s E . L e i e r s o n , a n d R o n a l d L . R i v e s t . I n t r o d u c t i o n t o A l g o r i t h m s
T h e M I T P r e s s , C a m b r i d g e , M a s s a c h u s e t t s , 1 9 9 0 .
9