4.recurrences hsu, lih-hsing. computer theory lab. chapter 4p.2 recurrences -- substitution method...
Post on 21-Dec-2015
228 views
TRANSCRIPT
Chapter 4 P.2
Computer Theory Lab.
Recurrences -- Substitution method Recursion-tree method Master method
T n aT n b f n( ) ( / ) ( )
Chapter 4 P.3
Computer Theory Lab.
Technicalities We neglect certain technical
details when we state and solve recurrences. A good example of a detail that is often glossed over is the assumption of integer arguments to functions. Boundary conditions is ignored. Omit floors, ceilings.
Chapter 4 P.4
Computer Theory Lab.
4.1 The substitution method : Mathematical induction
The substitution method for solving recurrence entails two steps:
1. Guess the form of the solution. 2. Use mathematical induction to find
the constants and show that the solution works.
Chapter 4 P.5
Computer Theory Lab.
Example
(We may omit the initial condition later.)
Guess Assume
T n T n n
T
( ) ( / )
( )
2 2
1 1
)log()( nnOnT
T n c n n( / ) / log /2 2 2
Chapter 4 P.6
Computer Theory Lab.
Initial condition However,
T n c n n n cnn
n
cn n cn n cn n c .
( ) / log / ) log
log log log )
2( 2 22
2 1 (if
)(01log)1(1 cnT
4 2 2 4 T cn c( ) log ( )if
Chapter 4 P.7
Computer Theory Lab.
Making a good guess
We guess
Making guess provides loose upper bound and lower bound. Then improve the gap.
T n T n n( ) ( / ) 2 2 17
T n O n n( ) ( log )
Chapter 4 P.8
Computer Theory Lab.
Subtleties
Guess Assume
However, assume
T n T n T n( ) ( / ) ( / ) 2 2 1
T n O n( ) ( )
T n cn( )
T n c n c n cn cn( ) / / 2 2 1 1
T n cn b( )
T n c n b c n b
cn b cn b b
( ) ( / ) ( / )
( )
2 2 1
2 1 1Choose
Chapter 4 P.9
Computer Theory Lab.
Show that the solution to T(n) = 2T(n2 + 17) + n is O(n lg n)
Solution:
assume a > 0, b > 0, c > 0 and T(n) ≦ an lg n – blg n - c
T(n) ≦ 2[(n2 + 17)lg(
n2 +17) - blg(
n2 + 17)-c]+n
≦ (an + 34a)lg(n2 +17) - 2blg(
n2 +17) - 2c + n
≦ anlg(n2 +17) + anlg21/a + (34a-2b)lg(
n2 +17) - 2c
≦ anlg(n) 21/a+ (34a-2b)lg(n) - 2c
Chapter 4 P.10
Computer Theory Lab.
anlg(n) 21/a+ (34a-2b)lg(n) - 2c
n≧ n2 +17,n≧ 34
n≧ (n2 +17) 21/a ∵, 21/2≦ 1.5∴ n ≧ 12
34a-2b≦ -b,b ≧ 34a
c > 0,-c > -2c
T(n) ≦ anlgn - blgn - c,T(n) ≦ anlgn
T(n) = O(nlgn)
Chapter 4 P.11
Computer Theory Lab.
Avoiding pitfalls
Assume Hence
(WRONG!) You cannot find such a c.
T n T n n
T
( ) ( / )
( )
2 2
1 1
T n O n( ) ( )
T n cn( )
constant) a is Since(
)()2/(2)(
c
nOncnnncnT
Chapter 4 P.12
Computer Theory Lab.
Changing variables T n T n n( ) ( ) lg 2
Let m nlg .
T T mm m( ) ( )/2 2 2 2
Then S m S m m( ) ( / ) 2 2 .
S m O m m
T n T S m O m m
O n n
m
( ) ( lg )
( ) ( ) ( ) ( lg )
(lg lg lg )
2
Chapter 4 P.15
Computer Theory Lab.
).(1)16/3(
1)16/3(
16
3
)(16
3...
16
3
16
3)(
3log2log
1log
0
3log2
3log21log
22
22
4
4
4
4
4
4
ncn
ncn
ncncncncnnT
n
n
i
i
n
The cost of the entire tree
Chapter 4 P.16
Computer Theory Lab.
)(
)(13
16
)16/3(1
1
16
3
16
3)(
2
3log2
3log2
3log2
0
1log
0
3log2
4
4
4
4
4
nO
ncn
ncn
ncn
ncnnT
i
i
n
i
i
Chapter 4 P.17
Computer Theory Lab.
substitution methodWe want to Show that T(n) ≤ dn2 for some consta
nt d > 0. using the same constant c > 0 as before, we have
Where the last step holds as long as d (16/13)c.
,
16
3
)4/(3
4/3
)4/(3)(
2
22
22
22
2
dn
cndn
cnnd
cnnd
cnnT nT
Chapter 4 P.19
Computer Theory Lab.
substitution method
,lg
)3/23(lglg
2lg)3/2(3lg)3/2(3lg)3/((lg
))2/3lg()3/2(3lg)3/((lg
))2/3lg()3/2(lg)3/2(()3lg)3/(lg)3/((
)3/2lg()3/2()3/lg()3/(
)3/2()3/()(
ndn
cndnndn
cnnnndndn
cnnndndn
cnndnndndnnd
cnnndnnd
cnnTnTnT
As long as d c/lg3 – (2/3)).
Chapter 4 P.20
Computer Theory Lab.
4.3 The master method Theorem 4.1 (((MMMaaasssttteeerrr ttthhheeeooorrreeemmm)))
Let a 1 and b 1 be constants, let f n( ) be a function, and T n( )
be defined on the nonnegative integers by the recurrence T n aT n b f n( ) ( / ) ( )
where we interpret n b/ mean either n b/ or n b/ .
1. If f n O n b a( ) ( )log for some constant 0 , then T n n b a( ) ( )log .
2. If f n O n b a( ) ( )log then T n n nb a( ) ( log )log .
3. If f n O n b a( ) ( )log for some constant 0 and if af n b cf n( / ) ( )
for some constant c 1 and all sufficiently large n, then T n f n( ) ( ( )) .
Proof. (In section 4.4 by recursive tree)
Chapter 4 P.21
Computer Theory Lab.
T n T n n( ) ( / ) 9 3
a b f n n
n n f n O n
9 3
3 39 2 9 1
, , ( )
, ( ) ( )log log
Case T n n1 2 ( ) ( )
T n T n( ) ( / ) 2 3 1
a b f n
n n f n
1, 3 2 1
13 21 0
/ , ( )
( ),log /
Case T n n2 ( ) (log )
Chapter 4 P.22
Computer Theory Lab.
T n T n n n( ) ( / ) log 3 4
a b f n n n
n n f n O n
3 4
4 43 0 793 3
, , ( ) log
, ( ) ( )log . log
Case
af(n/b)= (n) (
n)
nn=cf(n)
c= n
T n n n
3
34 4
34
34
Check
for and sufficiently large
log log
,
( ) ( log )
Chapter 4 P.23
Computer Theory Lab.
The master method does not apply to the recurrence
even though it has the proper form: a = 2, b=2, f(n)= n lgn, and It might seem that case 3 should apply, since f(n)= n lgn is asymptotically larger than
The problem is that it is not polynomially larger.
,lg)2/(2)( nnnTnT
.log nn ab
.log nn ab