in general tcn a divide and of at each level ne no 10610

2
Solving Recurrences merge sort : Tcn) = Z - T ( Iz ) + och ) Tcn) - ocnlogn ) M " Pei ' - covering : Tcn ) = 4. TCF ) t OCD ? ( nxn tile ) In general : Tcn ) = a TCF) + Nc runtime of " divide " and " merge " at each level : ne - no . . . . . . b- a.IE = F. ne h - loan . £10610 aint = i. ne C 9 : : ah ( = # Y - no . . . . - Tcn ) = a. TCF ) t na sum -_ nc ( ltqtq 't . + qh ) = a. ( a. TCF ) + CET ) + n ' g - = a ?TCFz)ta + n ' ' y q= # Claim . Let 9>0 be a fixed constant - For any integer h > o . Oh) if get It qtq t . . + 9h = { htt if f- I Cgh ) if 9>1 Proof : One can verify the 9=1 case . When 9 , htt ( Fix this to 0.1 ) the largest -1+9+92-1 ? ! -19k = < Iq - - OG ) . top term 1 When q > I be itqtqzt . tqh=9"g÷=qh(9÷h)cqh . # =ocqh ) t the largest term Master Theorem - : The solution to the recurrence Tonka - TCF ) thc is ( where a , b , c > o are constants ( nc ) logba - c acb ' gel { Cnc - login ) l°9ba=c nc.qhnc.fzjosbn-nc.ba?:!n ( n' Bba ) logb A > C =nc E aiogbn.at#o=n' IT

Upload: others

Post on 20-Nov-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: In general Tcn a divide and of at each level ne no 10610

Solving Recurrences

mergesort : Tcn) = Z - T ( Iz) + och) ⇒ Tcn) - ocnlogn )M"

Pei'

- covering : Tcn) = 4. TCF) t OCD ⇒ ?

(nxn tile)

In general : Tcn) = a - TCF) + Nc runtime of"

divide.

"

and"

merge"

at each level :

④ ne

- no⑤ . . . . . . b- a.IE = F. ne

h - loan € . £10610 aint = i. ne

C

'

,

9 :

:'

ah - (⇒ = #Y - no

④ . . ..

. - -

Tcn) = a. TCF) t na sum -_ nc - ( ltqtq't . . - + qh)= a. (a.TCF ) + CET ) + n

'

g-

= a?TCFz)ta + n'

'

y q= #Claim .

.

Let 9>0 be a fixed constant .-

For any integer h> o.

Oh) if get

It qtq -t . .. + 9h = { htt if f- I

⑦Cgh) if 9>1 .

Proof : One can verify the 9=1 case.

When 9 , htt (Fix this to 0.1)the largest

-1+9+92-1? ! -19k = < Iq -

- OG).top

term1

When q > I beitqtqzt . . . tqh=9"g÷=qh(9÷h)cqh .# =ocqh) .

tthe largestterm

Master Theorem-

:

The solution to the recurrence Tonka - TCF) thc is

(where a ,b, c > o are constants

① (nc ) logba - c ⇒ acb'⇒ gel .

{ ⑦ Cnc - login) l°9ba=cnc.qhnc.fzjosbn-nc.ba?:!n

⑦ (n'Bba ) logb A > C =nc .E aiogbn.at#o=n'IT

Page 2: In general Tcn a divide and of at each level ne no 10610

- c na

logyA = C nclogn

Applications of Master Theorem.

> c n'09bar

Example l : Tcn) = 2T (Z) t ⑦ (n),a- 2. b=z,c=l

Tcn) = ⑦ ( nlogh) logba - I = C .

Example 2 : Tcn) = 4. TCF) t ⑦ ( l ) , a=4 b=2.

⇐ o

Tcn) = ( NZ ) logba -_ 2 - c

Example 3 : binary search .

Tch) = TCI) t ⑦ (1),

a=l b=2 c=o

logbA=0=cTcn) = ⑦ ( login)

Example 4 : Tcn) = 2 Tern ) t ⑦ ( 21092T )Answer : out of the scope of this course .

one common approach is to prove by induction.

Example 5 : Tcn) = 2T ( Nz ) -1 ②( NZ ) a=z 6=2 c=2

Tcn) = ⑦ (m2)logba =/ cc

Example 6 : matrix multiplication : C = AXB. Cij - I Aik - Big .

nxnnaive implementation : A ,

B , C E R

runtime = ① (as )

a- III. I:] BY::B.:] ⇐ ⇒Cu = An B" t AIZBZI Tch) = 8 TCI) t Oth )Gz = All Biz + Are 1322

9=8 ,b - 2

,

C= z

Cz, = Az, Bil t Azz Bylogba=3 > cCz, = Az, Biz + A-221322

f-(n) = ⑦ C? )Strassen Algorithm

(source : Wikipedia) TGt-7.IE ) -1%4J

time to split the matricesand perform additions

and subtrations.

9=7 6=2,C= 2

Tch) = n'%7

= m2-81 ⇐ n3,