A General Method of Solving Divide-and-Conquer

12
A General Method of Solving Divide-and-Conquer 計計計計計計 Chapter05 計計計計 計計計計計

description

A General Method of Solving Divide-and-Conquer. 計算方法設計 Chapter05 重要補充 唐傳義 老師. given. rewrite it into template. given. ,. Deduction-1. (1). (1). Example1-(1). Example 1 : Solution :. iteration and cancellation. 又. log n terms. ,. Deduction-2. 而. Deduction-3. - PowerPoint PPT Presentation

Transcript of A General Method of Solving Divide-and-Conquer

Page 1: A General Method of  Solving Divide-and-Conquer

A General Method of Solving Divide-and-Conquer

計算方法設計Chapter05 重要補充

唐傳義老師

Page 2: A General Method of  Solving Divide-and-Conquer

2

Deduction-1

)()2

()(

)1(

nfn

kTnT

T

)()2

(2)(

)1(

ngnn

TnT

T

pp

kp log pn

nfng

)()(

given

given

rewrite it into template

,

Page 3: A General Method of  Solving Divide-and-Conquer

3

Example1-(1)

Example 1 :

Solution :3.0)

2(2)( nn

TnT

7.01

3.0

7.011

)(

1

)2

(2)(

nn

nng

p

nnn

TnT

(1)

3.0)2

(2)( nn

TnT

7.01

3.0

7.011

)(

1

)2

(2)(

nn

nng

p

nnn

TnT

(1)

3.0)2

(2)( nn

TnT

Page 4: A General Method of  Solving Divide-and-Conquer

4

Deduction-2

)()2

(2)( ngnn

TnT pp

)()2

()]4

(2[2 ngnn

gnn

T pppp

)()]2

()2

()4

(2[2 ngnn

gnn

T pppp iteration and cancellation

)()2

()4

()8

(222 ngnn

gnn

gnn

T pppppp

)]2(...)4

()2

()([)1(2 log gn

gn

gngnT pnp 又 pnp nlog2

)]1()2(...)4

()2

()([ Tgn

gn

gngn p

log n terms

)](~)1([ ngTn p )2()(~log1

i

nigng

,

Page 5: A General Method of  Solving Divide-and-Conquer

5

Deduction-3

Ο : upper bound ex: Ω : lower bound ex: Θ : exactly ex: ο : exactly,even constant ex:

)(~ ng不同的 g(n) 對應不同的

)(ng )(~ ng

0),( qnq )1(

0,log jnj

0),( qnq ))(( ng

)(log1

log 1 nj

n jj

)(3 2nn )1(3 n)(3 nn )3(3 nn

Page 6: A General Method of  Solving Divide-and-Conquer

6

Example1-(2)

Example 1 :

Solution : From (1)

7.0)( nng

07.0 g

)1()(~ ng

nngTnnT p )](~)1([)(

1p

3.0)2

(2)( nn

TnT

Page 7: A General Method of  Solving Divide-and-Conquer

7

Example2

Example 2 :

Solution :

)()2

(7)( 2nn

TnT

72 p

7log p

7log2)( nng 07log2 ,

)]1()1([)( 7log TnnT

)( 7logn

Page 8: A General Method of  Solving Divide-and-Conquer

8

General Representation

In general

)()()(

)1(

nfc

nkTnT

T given

)()()( ngnc

nTcnT pp kp clog pn

nfng

)()( , ,

)]()1([)(log1

i

ni

p cgTnnTc

仍然是

只差 的constant

If g(n) is monotone

)(~ ng

clog

Page 9: A General Method of  Solving Divide-and-Conquer

9

Example3-- Pan’s Matrix

Example 3 :

Solution :

)()70

(*143640)( 2nn

TnT

)]1()1([)( TnnT p

)( pn

14364070 p

79.2143640log70 p

79.22)( nng

Page 10: A General Method of  Solving Divide-and-Conquer

10

More General Representation

More general

)())(()()(

)( 0

nfnbTnanT

nT given

,)()())(()()( ngnhnbTnanT ))(()()( nbhnanh

])(

)())((...)))((())(()([)()(

0

00

1

nh

nTnbgnbbgnbgngnhnT

Page 11: A General Method of  Solving Divide-and-Conquer

11

Example4

Example 4 :

Solution :

])2(

)2(4log...)log()log([log)( 4

121

h

TnnnnnT

nnnTnnT

T

log)()(

2)2(

21

21 時只考慮

in 22

2

1

)( nna 21

)( nnb ,

)()( 2

1

2

1

nhnnh

nnh )(

nnnTnnT log)()( 21

21

)1log2( nn

21

)( nnb 21 )( nnb

4)2(1 b

Page 12: A General Method of  Solving Divide-and-Conquer

12

Reference

Bentley, Haken & Saxe “A General Method of Solving

Divide-and-Conquer Recurrences”, SIGACT News Fall

1980,page36-44