Master method theorem

rajendranjrf 1,382 views 22 slides Feb 10, 2017
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

Master method theorem in Analysis of Algorithms


Slide Content

1
Asymptotic Efficiency of Recurrences
•Find the asymptotic bounds of recursive equations.
–Substitution method
•domain transformation
•Changing variable
–Recursive tree method
–Master method (master theorem)
•Provides bounds for: T(n) = aT(n/b)+f(n) where
–a ³ 1 (the number of subproblems).
–b>1, (n/b is the size of each subproblem).
–f(n) is a given function.

2
Recurrences
•MERGE-SORT
–Contains details:
•T(n) = Q(1) if n=1
T(én/2ù)+ T(ën/2û)+ Q(n) if n>1
•Ignore details, T(n) = 2T(n/2)+ Q(n).
–T(n) = Q(1) if n=1
2T(n/2)+ Q(n) if n>1

3
Master Method/Theorem
•Theorem 4.1 (page 73)
–for T(n) = aT(n/b)+f(n), n/b may be én/bù or ën/bû.
–where a ³ 1, b>1 are positive integers, f(n) be a non-
negative function.
1.If f(n)=O(n
log
b
a
-e) for some e>0, then T(n)= Q(n
log
b
a
).
2.If f(n)= Q(n
log
b
a
), then T(n)= Q(n
log
b
a
lg n).
3.If f(n)=W(n
log
b
a+e
) for some e>0, and if af(n/b) £cf(n) for
some c<1 and all sufficiently large n, then T(n)=
Q(f(n)).

4
Implications of Master Theorem
•Comparison between f(n) and n
log
b
a
(<,=,>)
•Must be asymptotically smaller (or larger) by a
polynomial, i.e., n
e
for some e>0.
•In case 3, the “regularity” must be satisfied, i.e.,
af(n/b) £cf(n) for some c<1 .
•There are gaps
–between 1 and 2: f(n) is smaller than n
log
b
a
, but not
polynomially smaller.
–between 2 and 3: f(n) is larger than n
log
b
a
, but not
polynomially larger.
–in case 3, if the “regularity” fails to hold.

5
Application of Master Theorem
•T(n) = 9T(n/3)+n;
–a=9,b=3, f(n) =n
–n
log
b
a
= n
log
3
9
= Q (n
2
)
–f(n)=O(n
log
3
9
-e) for e=1
–By case 1, T(n) =Q (n
2
).
•T(n) = T(2n/3)+1
–a=1,b=3/2, f(n) =1
–n
log
b
a
= n
log
3/2
1
= Q (n
0
) = Q (1)
–By case 2, T(n)= Q(lg n).

6
Application of Master Theorem
•T(n) = 3T(n/4)+nlg n;
–a=3,b=4, f(n) =nlg n
–n
log
b
a
= n
log
4
3
= Q (n
0.793
)
–f(n)= W(n
log
4
3
+e) for e»0.2
–Moreover, for large n, the “regularity” holds for
c=3/4.
•af(n/b) =3(n/4)lg (n/4) £ (3/4)nlg n = cf(n)
–By case 3, T(n) =Q (f(n))=Q (nlg n).

7
Exception to Master Theorem
•T(n) = 2T(n/2)+nlg n;
–a=2,b=2, f(n) =nlg n
–n
log
b
a
= n
log
2
2
= Q (n)
–f(n) is asymptotically larger than n
log
b
a
, but not
polynomially larger because
–f(n)/n
log
b
a
= lg n, which is asymptotically less than n
e
for any e>0
.
–Therefore,this is a gap between 2 and 3.

8
Where Are the Gaps
n
log
b
a
f(n), case 2: within constant distances
c
1
c
2
n
e
f(n), case 1, at least polynomially smaller
Gap between case 1 and 2
n
e
Gap between case 3 and 2
f(n), case 3, at least polynomially larger
Note: 1. for case 3, the regularity also must hold.
2. if f(n) is lg n smaller, then fall in gap in 1 and 2
3. if f(n) is lg n larger, then fall in gap in 3 and 2
4. if f(n)=Q(n
logb
a
lg
k
n), then T(n)=Q(n
logb
a
lg
k+1
n). (as exercise)

9
Proof of Master Theorem
•The proof for the exact powers, n=b
k
for k³1.
•Lemma 4.2
–for T(n) = Q(1) if n=1
– aT(n/b)+f(n) if n=b
k
for k³1
–where a ³ 1, b>1, f(n) be a nonnegative function,
–Then
–T(n) = Q(n
log
b
a
)+ a
j
f(n/b
j
)
•Proof:
–By iterating the recurrence
–By recursion tree (See figure 4.3)
å
j=0
logb
n-1

10
Recursion tree for T(n)=aT(n/b)+f(n)

11
Proof of Master Theorem (cont.)
•Lemma 4.3:
–Let a ³ 1, b>1, f(n) be a nonnegative function defined on
exact power of b, then
–g(n)= a
j
f(n/b
j
) can be bounded for exact power of b as:
1.If f(n)=O(n
log
b
a
-e) for some e>0, then g(n)= O(n
log
b
a
).
2.If f(n)= Q(n
log
b
a
), then g(n)= Q(n
log
b
a
lg n).
3.If f(n)= W(n
log
b
a
+e) for some e>0 and if af(n/b) £cf(n) for some
c<1 and all sufficiently large n ³b, then g(n)= Q(f(n)).
å
j=0
logb
n-1

12
Proof of Lemma 4.3
•For case 1: f(n)=O(n
log
b
a
-e) implies f(n/b
j
)=O((n /b
j
)
log
b
a
-e), so
•g(n)= a
j
f(n/b
j
) =O( a
j
(n /b
j
)
log
b
a
-e )
• = O(n
log
b
a
-e a
j
/(b
log
b
a
-e)
j
) = O(n
log
b
a
-e a
j
/(a
j
(b
-e)
j
))
• = O(n
log
b
a
-e (b
e)
j
) = O(n
log
b
a
-e (((b
e )

log
b
n
-1)/(b
e
-1) )
• = O(n
log
b
a
-e (((b
logb
n
)
e -1)/(b
e
-1)))=O(n
log
b
a
n
-e (n
e -1)/(b
e
-1))
• = O(n
log
b
a
)
å
j=0
logb
n-1
å
j=0
logb
n-1
å
j=0
logb
n-1
å
j=0
logb
n-1
å
j=0
logb
n-1

13
Proof of Lemma 4.3(cont.)
•For case 2: f(n)= Q(n
log
b
a
) implies f(n/b
j
)= Q((n /b
j
)
log
b
a
), so
•g(n)= a
j
f(n/b
j
) = Q( a
j
(n /b
j
)
log
b
a
)
• = Q(n
log
b
a
a
j
/(b
log
b
a
)
j
) = Q(n
log
b
a
1)
• = Q(n
log
b
a
log
b
n) = Q(n
log
b
a
lg n)
å
j=0
logb
n-1
å
j=0
logb
n-1
å
j=0
logb
n-1
å
j=0
logb
n-1

14
Proof of Lemma 4.3(cont.)
•For case 3:
–Since g(n) contains f(n), g(n) = W(f(n))
–Since af(n/b) £cf(n), a
j
f(n/b
j
) £c
j
f(n) , why???
–g(n)= a
j
f(n/b
j
) £ c
j
f(n) £ f(n) c
j


=f(n)(1/(1-c)) =O(f(n))
–Thus, g(n)=Q(f(n))
å
j=0
logb
n-1
å
j=0
logb
n-1
å
j=0
¥

15
Proof of Master Theorem (cont.)
•Lemma 4.4:
–for T(n) = Q(1) if n=1
– aT(n/b)+f(n) if n=b
k
for k³1
–where a ³ 1, b>1, f(n) be a nonnegative function,
1.If f(n)=O(n
log
b
a
-e) for some e>0, then T(n)= Q(n
log
b
a
).
2.If f(n)= Q(n
log
b
a
), then T(n)= Q(n
log
b
a
lg n).
3.If f(n)=W(n
log
b
a+e
) for some e>0, and if af(n/b) £cf(n) for
some c<1 and all sufficiently large n, then T(n)=
Q(f(n)).

16
Proof of Lemma 4.4 (cont.)
•Combine Lemma 4.2 and 4.3,
–For case 1:
•T(n)= Q(n
log
b
a
)+O(n
log
b
a
)=Q(n
log
b
a
).
–For case 2:
•T(n)= Q(n
log
b
a
)+Q(n
log
b
a
lg n)=Q(n
log
b
a
lg n).
–For case 3:
•T(n)= Q(n
log
b
a
)+Q(f(n))=Q(f(n)) because f(n)= W(n
log
b
a+e
).

17
Floors and Ceilings
•T(n)=aT(ën/bû)+f(n) and T(n)=aT(én/bù)+f(n)
•Want to prove both equal to T(n)=aT(n/b)+f(n)
•Two results:
–Master theorem applied to all integers n.
–Floors and ceilings do not change the result.
•(Note: we proved this by domain transformation too).
•Since ën/bû£n/b, and én/bù³ n/b, upper bound for
floors and lower bound for ceiling is held.
•So prove upper bound for ceilings (similar for lower
bound for floors).

18
Upper bound of proof for T(n)=aT(én/bù)+f(n)
•consider sequence n, én/bù, é én/bù/bù, é é én/bù /bù/bù,

•Let us define n
j
as follows:
•n
j
= n if j=0
• = én
j-1
/bù if j>0
•The sequence will be n
0
, n
1
, …, n
ëlog
b


•Draw recursion tree:

19
Recursion tree of T(n)=aT(én/bù)+f(n)

20
The proof of upper bound for ceiling
–T(n) = Q(n
log
b
a
)+ a
j
f(n
j
)
–Thus similar to Lemma 4.3 and 4.4, the upper
bound is proven.
å
j=0
ëlogb

-1

21
The simple format of master theorem
•T(n)=aT(n/b)+cn
k
, with a, b, c, k are positive
constants, and a³1 and b³2,
O(n
logba
), if a>b
k
.
•T(n) = O(n
k
logn), if a=b
k
.
O(n
k
), if a<b
k
.

22
Summary
Recurrences and their bounds
–Substitution
–Recursion tree
–Master theorem.
–Proof of subtleties
–Recurrences that Master theorem does not
apply to.
Tags