dividepawang/courses/algo20/chap2.pdf · combine:-the securesire calls olp the sof" lathe...
TRANSCRIPT
Divide2- Conquer
Complexity Analysis{ ↳efficientoff-Algo Design Technique
÷÷:÷÷÷Data Structures
q.io?:i::aE::e.. .problem for which ilp instance of
size nie giver.Rex : - Sorted army size n
find the element with keyin'
20
Divide: - Break The problem Cinsknainto subproblem financesof smaller
size)
conquest -7 Recursive call the abpOn each of the subproblems(stop when an instance is tuff'smad
Combine: - The securesire calls olpthe sof
"
lathe subproblemCombine these solutions to obtainthe
so of the original prob (instancecompass with middle
Recourse into
insideone of the
Conquer Combine- -subarmp -
Binay ., Trivial
season 43¥56-c- n→
in:←
Imp tyg , Recurrence keen .
Tcn) - T (2) + 047
gTCh)
''oc,- fTCF) tour
THE) loca ) ✓ depth
" I+ (3.)'
oui - -
K / = began
-147 KOCH
TIN - Olhgan)
Binary season
#cyclic61%
121838T-1an
→ Powering a Number
Given a number ginteger nzo , find a
"
trainedn.ng.j.se -
Oln) alfo
DIE an wrath.ants
an -- fEna.
1-Ink 0 ( leggyw# in"¥ . no n odd
-.- -
r TINK TIE) -1041
Sorting Algerost Quickest
Afi,-- ng
done & Divide
Recursively sort Ab. - . ITanimating)
↳
IMerge 2 sorted lists Confine
ink a single sorted list
Pseudo code- Base case- Call with 1
. .. nlz
Call with Mee '.- M
Megee . -
TCH = IT ( z, * 01nF"
.
-= alone * 09:D ten
/-
-
-
/ IT me
m.
i
,
-29"
--
- - 241,7.) t Essen(
gdokn Ca) t cntgn= on legist n 741
= OCnbg.mg -
*worst-Case Lt'T =
-
Cnhgan = Ol )= OC )
Olnbgan,= Al )
Ouidesost A
nChoose was pirog rearranges
suchthat x is put in its proper
posh in the sorted awayto § I conquer← →TEExo i am-
may notth
dividestooted
Combine : Trivial
Quick sort ( A,start,end
if Stan = - end zetumni ← PaAGMd)QuickSort (A
,start,i-17
Quick sort (S, its end)
Partition (Aidan> endat A Estaing
Eine es.
eata t=⇒→ →j→
6 E i,be If-3,2 ' '
Money"
forward until SBTsooi ← it a swap ATD ⇐AED
i ← start [ indicates the boundary up't
je start -1A In elements
assed
TEX6 5 §To 8 ,
→
q µ
i j → → . → →
6 5 35 8 is noTi
se-
← OHA- Estate # SED partition
⑤-681310€{⇒ -
a#- i -
pasting tie. qin-i
Time complexity CluicksortCI t TH-' I + TH
TIM = I +Tht)gahp nlz nee
media:-O n±fI← sinned:b.
TCH - Cnt Tln -D=
Cn t Hn- e) t elm - a)
← Cnt Ccn - i ) + 1- (n-3) tuna1
!THX
= c. Ent n-it - - IT
= C - nlz = OCn4
Ohne)
InsertionSort--
wens
Slm)-91nF Cnt Tliiltdnni)-
-
-"n-
equally likelyA#-
Ne
i÷:÷÷÷÷÷"*T (n- a) t Tfn-4 a- TIO
[ this t - --
-1¥= 21-147-1 - - Tcn-D
N- l
THI - 01Mt I E. Tci)-
J ith- -
Guessitheso# TINK OfstedThi s anloyn AI-
f) I can 't En ? ailgithiamine! in:
this ohhaaai.i.IE/?IiihsiJ- 2
genes.is?as.✓
c- centralised . :tz tCn -
n-'
ibeen - Emu . ]i¥÷¥ish- -
= MII - HE2
= 4¥64 = 3nln8 -8
This cn-tluzhgn.MY" - Thay . her . #¥g
THE cent a Cn -' I been - ¥-21 lgzI f
= an leg n + on - align - analyze- azhgz
= an Agm tf -earless) n - align-
-- gigs
-neo-
San Agn
Ice alwayfind-9>yeg①arose →
Tlnl I an bgn
Tla ) = Olnhgn)-
in glide? sorting AlgoMime- complexity spacetime
Dirickson- - any case O (nbcsn)
n
:::÷.. . .ie::/sxYmi "- 6
'
6" -
G -
sadMemory is veg, in terms of ilp size
Read the ilp valuesHow much
Old t additionalamong ?ready ilp-
Joe?,Oln ) -in-placein -placeX -
Polynomial MultiplicationSuppose we're two polynomials, eachof dagsea n- n ( n terms)
AHH a - -a. xtao
Pdx) - Ann X 't't bn.at/n-2e-.baXtbo--
The product pblgnonn.atA Blx) ← GCX)-
degree 2nsCl = Gqn.at/2mt62n.zX2n-3e - - Go
o - J n-'Ci o Sieg. .-2)→ 044
a - -0*4- K -- ing
'
i -- 2ns Ci = I aibk- Osi
,Kent - Noire
Cena -- Ann bn-2 ↳ yn,jtK= it fliptan-abna -
Dir. & Cone .
1-AH an1on,
*E
)"
xtlam.it't't. -at)
A- Cx) = XtAni (x ) t AboutBLX ) = Xt Bni t Deol X )
cut. ACH . BLX)②-
= X2t Am. Bn .. txtlabzix- TO Anglo)
1- ABBA ③→
-
EEIdng
- Master 's theoremwrote
" ÷:*..:*'
fCn7= Ofyhesba - e)- -
forgone E -O
⇒ Hnk @ (nhdba)
air:÷÷-
A -- 4-b-- 2
9h01 = n.
Hat off-e)Tink Olney ✓
-→Maire
Or ⑥ aAhiBhi ArloBb
- i-Ahi Blot Alo Bhi-
only find this whole thing(m÷sm:.Multiply Poly Z .
TIM - 3T (Nz ) t In
This = ofglossyOng
Oln "54 /be
Karatsuba's Poly. Multi
Matrix Multiplication-
ilp A - Tais] B- Ebij]
olp ( = Icij) igj -- I . - D= A - B.n
(Cig 's E aikbkj →Oln)K'-Mu
01ns) → NaivelyT ,
a "nee b
'
t÷ '' Ic.
: d n g :b ni ,
✓A 7 B
'
n
F- aetbgre-
✓-
u diss -- aaftbhne µ - ÷. - 1- nt, cetdlf t
.
U
y -- CITING In
TIM - IT(E) t Oke). Feng =oln'-9Master's,- theorem
C
7 Olney -9=067= 0h31 = Naive Also
complexity
Strassen's Matrix Multi.
TCM -- 7T(hate Oln "
-
- Alm test)Cmx : Div a long.
Trick bredace
fabproblemsat
(Poly Mutt . →
Prob. Large Integer multiplication
× 33021 . .Haine Algo] Dad → More
efficient
Closest Pair problem
x
x*
A
:. :x
-
Maire Sol?. aeh pair
Ietp.to
↳ f- 'rdthe Smallest diet
OlneyDin. e Gna-
Let us denote the setof points byP- Ep. . - - prig where pi has
co-ordinates (Riggi)for every pair pips EPdlpispj) denotes the Std.
Euclidean distance
Goal : -3 find a pair of points pigs; thatminimizes dlipispj)
n
emin d Cpi,is
igj.- A-it;
t -D planeSortthem 2- then find min
.
2- D planenloyn
c'
,r f
l l.-
s.
.-
,
* (Il, pit x
--F-
s- -
* fix a o' x
X,-lI,
'
✓ c
×a
'
II,
×
I ✓
x.
:*
( left !: fright
-
.3)ketoses- pair in
, closest poorleft ,rim"
L )closest pair overall
conquer-$ combine
all points acrossAJI plait gownday
Sort all the port in P by a-to → Px
also by y-co - pga
oR
Oo
Op
° o
g, ↳ a,o ooo
o Oo
o o
O-- - n e - -
.
S - min (do,der)t
O : set of points in The first'f7 poshof the dirt Px ( left half)
R : - final LIJ poshof Px ( sight haltf '
Recursively find closest pair in death
Esther gone 9,1Eta ate
for which dues) ad ?--
KI. . -S.'
/'
f'
/ In.
•l
':/ , ! rl l f p
Sy : the listof Inknkl Let ¥1I ' b:p pirinpoints in S l L l had
sorted Gf-! -zper theiry - co-ordinates
-
band .✓ Is✓
7×7 "'
I - e
"l
l l
'
I µµ2d%I'
l
l : outI ×
I .
a
-i is
- -i- .: i
.
f- i. it- -i-I. it. . said
,
.' .
1
.
She
f:÷÷÷÷÷÷÷÷÷÷÷÷:-
of other portsfact : Atmot I point can lie in a
single block .
> compare with at most 15 other points