You are on page 1of 6

CSE 565 ,

Lecture 02 , 08/25/2021
Master 's theorem :

1 if net
1- In) =

{ a. Tln/b) + D- Ind ) if n > 2

# sub
a :
problems
Mb : size of input of each subproblem

D- Ind) :
running time of the combining step .

Assume :n=b Olnd ) ⇐ nd k =/


ogbn

TIM = a. Tlnlb ) -1 nd

af .TK/bYtlng)d +nd- a?Tln/b4ta.Ln-d+nd- aYa-Tln1bDt


=

dtnd
(F) d) + a

ta.LI/dta-L1-)d+nd-a:.g.-)d:.- ak.-ln/bk)tak-'.n7.-. )d+.. - a(


= as Tlnlb})

Told not 7
+

ak.fr?,)dtak-1p1-.yd+.. +a'l1-)dta.lJ-.)d- -Eai.(ni-)di- 0


=

i
=
nd .

5¥ (g),
geometricser.ie#
a=bd

nd.lk#)- nd.lwgY-&+ijF=--g-n,.1fasbddclogba
d-
If logba
Tim -

# sub problems dominates .

)=O- ( nd ¥109bn)
k
Tla )=O- ( nd .

-9¥

.nl#n=-nb9fa- oLnd.i -.ia)- O-(nb9ba)


=olnd

If asbd .
d >
1098 combining step dominates .

TIM = Qlnd ) .

( hd D= logba
① logy if

{
'

TIN)= D- ( hd) if d >


log :
⑤ ( nlogba) .
it d-
logba
For sort a- 2,6=2 d=1
merge
-
,

Tin)=0-
lntogn ) .
selectionproblem-7-nputiar ayA-4.mn ] , integer K ,
I a- Ken .

output : the K -
th smallest number in A .

specials :
k=m , k=n/2.1 median )
Goat design that 0-1 a) time
: a DIF algo runs in .

Exampte A-
[41-912,4%+7-310] K=6
:
= ,

based
pi partition

4¥ ☒ TEA 2

selection ] K)
function ( ALT n
.
. .

if n=t .
return All ] .

|
✗ c-
find pivot 1A K) -
,

Az
partition A into Ai × .
.

Ai =
{ a c- At a < ×
}
Az =
{ ac- At a> × }
, mum µ ,# on , , , µ
µ µ , , ,, ,

else it k= 1AM -11 return ×

else K > 1A / ,
+ I return selection / Ask-1A , / -

D
.

ead

correctness .
Runningtime
:
Let Tlnl be the running time of
selection ( A , K) when IAI =
n .

Tiny = time I find -

pivot) 1- ① (a) 1- T( Max / 1AM IAN} ) .

that is close to themediaaofA_


IdealY_ i
pick a
pivot ✗

twine median
using median of medians
" "

V5
¥É;;¥f#;y
sub
arrays
A:

M
t.IE:1 1Mt 45
:

pivot ✗← median IM)

function find pivot


-
(A ,
K)

partition A into V5 sub -01M


arrays

|
.

calculate the median in each sabarray-D-4.bg 5¥)


Let M be the list of all medians Qln /5)
return selection 1M .

1m44 Toys)
end

1- In) = OLD 1- THAT + 1- ( max-tt.AE ) .

Fact :
1AM 7 F- It 7-0×2

=

¥ .

11+43 F- ✗ É -1,10×2 =

3%
=act 1AM = n -

IAH -1 £
7%
1174 = n -

1AM -

£7,10
I

Max { 1 All . I Act } =


7h40 .

Tin ) £01M 1- 1- In /5) -11-(7^110) .

fÉÉ;÷§ TIM
TIM

5-+8--9-07
=

=
01M

① In .

log n ) .
if atb < 1

TIM =
0-1^1 .

n.IO#.-JTln)=O-lDtTln/io )tTlmaxf1Ail. AzB1.lA4.iAY7 o -x-z-


I. siie of Subang = 100 .

find -

medians takes

* 49 ¥
"
✗ = =
¥ .

1 All , LAY f n
-

¥ =

3¥ .

maxflA.li/A4} a-
3¥ Tln) -0cm -1T¥) -1113¥)

too +
E- =
to a 0-1^1 .
2. size of sub
array
=
3

TIM =
D- In) (F) 1- 1- ( Max { 1AM /AaB )
1- 1- ,
.

1AM .
1174 a-
Is I + f- I -9--31
✗ ✗ =

1AM , 1174 3 n -

-4=231
TIM = D- In) 1- 1- (F) -1T¥)
-3+-32--1 TIM =
Olnlogn) .

comparison of size =
5 vs size =
100

finding all medians


£195 100 -

log
100 .


in all sub
arrays =
logs
-

N
=

log 100 '


N

Inclusion 't when the sin of Each sub is 75


array
:

the selection algorithm runs in linear trine .

Conclusions When size is 75 ,


smaller size leads to

smaller coefficient 1 although asymptotically all linear) .

You might also like