0 ratings0% found this document useful (0 votes) 73 views37 pagesDAA Module 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Modube - IC
"Generel Method
- eohuicuc.
Divide arel Conquer Ts a top-down
Rew clesigotay algorithen Hest cnstch of diving the packer
Tne amellea aul gnoups. Again each sub gooup abrvielee!
into Srnec gooups. Becaure Heer emubler YOURS ore
eourier to Pind
The. dive 4 Cone yer hechuique depends ro)
Fblowrns Hoc. SAeps -
© Bride. The problens rs divides! Tle member of
- Seb groups.
© Congques > Sead the subpovbles 11 assenclingy o@
decors order uss sd sag bd Revere)
¥ The sete list oP seb problems ave
Combinest to geb He sebdieny Re the
Lovesers Pre blern,
Binery Seareeh *
———e
@ Combine
In As technique the Lek m He Rom o&
endhey ine}
dex Of alercoreliry ovale.
mele gerere idea of by
Seencha tecdanie exe
S Seacch He telephene nud cee .
Adephene. reckon, Prev Perse in te
Weddle Pac a
oy) op He buh iy He
Comper eo} search elemerd wy,eee nan ee oe Poke anes Paranal
thaw Stop Seomching
Opher wire. Searcky “the demert name. cithey
Lebb subpook of He beck o& seb parte te bok,
Ms lepers of rjdbelle clrnevds..
Genered Proce
2
ALT al} = --- afk-J Ak ol ktiJaken}---» ator]
oo
7 ow
ope ee
1 mid)! !
5 ' :
spagh 2 Loe mea high.
“The key elermenk 1 compared vor rnpelolte_
ore amide. element ook 1S ea{ust to Key elemerd
than Search -elemenk ot the mniololle pesidnn,
® elie iP middie element 15 less Hows key,
Hen key jdern may be Aight pool ob the shiy
® du & middle element greodkes thoy key
then key then oa be lelt pert oF the stain
\
\
!
u
IvoNdgoo torr Browey, Search (Key, 4,9)
key clened to be deol
IQ ts the Lust oP elemerd-
I] - number of olemert
/] toeo ~ read posshes of @wery,
HW hugh - te positieo Lamey
bow —o :
gh <9
wotale C Leo Ze high)
mnrd < (tows bigh)/9_
ie (key = aLmia))
* pat" Key 1s foure| ">
ele 1h C key < aLridd)
hugh = mrad]
eb
bow big = mmrd +)
end P
bl while
Ties Canplonitif ol Beat eer
The eect core oeeees whey tHe key clemenfe
Ts poser at dhe eater ef en ormeeny Ther Hee dota
Nurecs ot Comvpaed sen required wi be ene. Thay
time corporat by iser exily oP Binomy Sone 39 Woes} Core’.
; Bone)
(0) =
atherwht
4(%) #)
Plime creautreed dy compe de
the mrololRe clermout:
4) = AC) tray ACM) +1
460) = etc)
= 9+2(%p)
4%) = 144%)
= Oar+ +")
= 344049)
Soondenty = b+ 4(%)
- isa(m)
Pal alow
tim = i44C%n)
+>) = Trac)
"e=!] ——@ren
tokny deg en both erde
Jog, 9! = dog
i= tego
pul “he value ak dn e” ©
4(n) = hog »
a
© Apply Bro Beondy algpsithro to Seach elernend: 60
Reon sthe (10, 20,40, 40, 50, £0, 7O
Bed) Sut
2) Gr Jo oo 30 4o 50 60 FO
Ioeo highs 6
mrd = (hoorhigh)/» = (ore)/r = 3
rord = almrd = 4d anol key = 60
Key is greda hen mre} C Key alma)
Seah tr} SD 60D
boy toss
words Curd) Joos
mre [s)= 60 & Icery 260
ie mtd (83 = Key cthevy Beachy elemert found ob
vtHe sto post tun,
SOMenge Sot
Meage Bak za aondlyy ctechniowue do Sotee the)
Pooblew caimy she divide. anel conquer 2 dradegey ,
Th Hers wethed fesk aplube. te anay fdr choo
Salo geoups 8. arol % wort Dp elements ip earch) peab-
agen Spbih th chse gub geoups 3; ard 82 Into Sub
Group? $3, $4, 85 are} & In each Sub gooups Dy clemerds .
are} 30.0n,
Soot tre Yad & Sab geoeps mal combing He
OU. scotes| Seb gooups Inds ainghe oreaty ,
Gromit
Reobleny abSneN
(ear eiisns) (Emaar
——
Sab Poob) Sab Pooblery pease
Size “ly Sire My arte 7/GExample O Apply meege sorb 0, 20,30, 40,10, 50, 66
[30[2 30 40]io[s0]éo
EIx|Alm/]P@] LIEMeeye ant Algoathon
Tenge Sonat Ca, Loco, High)
oars eel aa
PC tees hag) “1
tote = (mothe) /a ;
Mengesr(a, Low, Meph)
Inengeseot (a wiclet, High):
end UMTS, Lew, Hag;
Ties Complenty of Menge -Seob!
° Rone)
ten) =.
4) +4(%)2D atheawr_
tev) = 10%) +9) +N
oad 240%) +
= 2 [oe (%)+2] tm
* 4
Let(H)+ Dan
2 + %e)+ an
2
=o" +2]ron
ie +) =ah(% ed
a
Nn
{l
3° s)+ 2a ton = 21(2 80
— oedt) = ony (3) an
z ot S-)sin
anidted eonclifved +61) =0, ID
ttn) = na(%)29
= nxt 4s)
SJ
myo t 3
to) =n ———{D
=n “folky log 00 betp ene
i tog, = Lagar
i= dog patio eat” D
tc) = lego
reo) = © (may)
30 Gert care, Worrbeare onel avenge cone, tne
Compleatty ts "D bey
Geserp) ©5,2,46,1,5, 2,4
@ as, 24, 63, 45, 17, 31, 96,50
@232,9.3415,4Qure deb!
© On sths Aype oP aerdinay slechnrquc Presb
Prod the peo Rect positrons oP key clemeuk thary split
a tnd teoo sub peat) theef 15 JeLP ger aol ety
pot.
Faample
AL OO AT2I-- - ORI ATRIALKHI-- 400d
—— rn a
Lele port Ke, Right feet
® Lele peek af the adomg ts dees thar eR.cotusd do
the key element
HloT ALI - + ~ ALK-T < ALKI
® Rybr port & the atoy is grenke ther oR equa)
+b key eden ods.
Arka ofk+99 --- -- 8€017 > ACKI
Again some poco apply te tellt pook ano}
Repl poo ob the sonny.
Algarthm Qurek—se( A, lee, Hy)
71 Las 15 Prask positteo arel High 1s loot posrbsn ePacom
RC baw hgh)
ke— portitivn Car, Low, high?)®
5 2
re Sort 5, 2,1,9, 9, 0 4
® Apply @urele
Given Sting }
Be
oe %
5 eau bes
“t ee then s
lees
3 1 4 8 2 83 ¥
a a 13 re
S 3 | 4 2 g 4 7
AG
2 3 so 4 £§ g 3 x
-
- AAG 8 9 Ff
5 2 ee
2 1 3 4 5
pad 8 7
\ eed J D 5
a keg
3 4 1g
k>9© Opry Gusek’ Sook G5, 7, 76
oO 2 3 4
6s ao Fs 80 8s
—_—-, FF
gs as so OS
Ga 4c. SO ss Ss
es &s sd S560
ee a
60 &S 0 ss 6S"
6 &s FO KS key
ST 4s sm 6
ss 4s sp ke3
so bs ow
4s 3
be keliw,Beat Care time Camplenity ot Qurek Sob
Ty ths ee ie the key clemenk is preetotthey
perfest position of the sizing arel adatea Fe olricirey
que} choo pacts.
soe}
0 it =)
HM) +H) 2 othnwrse,
aS
% Va
% My "ey
tt) =
2405") + DH +m) = o9(%)o&
= [+z]
= ot(H) +99
H%) = o+(2 +2
=] |o4(3)* 2 + On
= Pt (2:)+ Bn
= 2 (Ge) + 40
AC) = oia(B) ritom aml 20) 20
4(9) = of 40D) 20
= oft tin
den) = 8 | ———_@
ge)
“hoking tes _o9 both erde
Log.2! = doaat)
L= bog,o
put veluc of J in eo” ©
t€r) = 9. Loan
time complaihy of Berk eoxc ans) ewerage Case
ie |ten) = Cn Jogn’)
—Ty Hes ease the ghen anay ove 77 ascending
Order. “the Orrray 18 liviclusles) indo hea ports. one of
thew Ys empty,
Examphe * 10 90, 80, 4o 50
Cel
/~
40) “f° ey
TO) + 4(r-N)a 1m otherwise
Ato) = demijen
= (0-2) 4400-1) 2 1
= t(n3)4 te2) + tln-1} +1
ten) = HO) rt oyae- 4d (2) 49Cm1) 41
ten) = oon) ~ 9
a
ten) = ot
ctine, Compleniby ot Qurck Serb ty Wee) Case
re Rent)WWso sens Madoix, Muthpbret ior
Let Bard B be hoo Nm rredeix The product
ck deo medi ts € Cie Ce A» 8). The mubtiplicediy
io the fam db it aow of B are} 32” columo & ®
Lang Fallon, fermulu.
CCi5) =F ALR) BIAS)
Tekin
“The madete. Nand B me pondidreneol two
Jour Zqusre. Sulo madrices, each sul madara fein
dimentions % %%. Then he produch 8B eon be
Compete o) bg wae ste ferbnoira prmenss.
" Aw Bu Bio} _ Cn Oy
Aa Ao By Bop GQ, Cor
Gy = An Bn + Aira Boy
Cio = Air Rie t A Bar
Coy = An Bn + Aor Bo) e
Cor = Any Bn + Ase Bro
1f 0= 9 the Heomale © 1s compaded . Jn Ads ea
® wwe need co pester Brault pred PO are) Ros
adele of Y% m% madoin .= core.
a Leacn) one cas) ry We Nee,
. ina amnetipt
Bet uss Sfrassen's mode
4 ae feomulorr ,
Ps CAn + Ase) (8+ Bex)
Q= (Pa 7 Aor) Bn
R= Dn (Bi.- Bos) i
So Aor (Ba) ~Bn)
T=(An tAn) Bor
Y= (As.~ Au) (81+ Bn)
V= CA- Hox) ( Ro + Boo)
Cn= Pr3—-T+V
Cin = R+T oo
Coy — @ tS @
Cr = P#R-@Q+U
Th sloosers medtoix mublipliced iter we bee
Yo compute, using formuters ®) aro) BD, tore wre
Meee) to Compale F multiplreced joo an) 18 adels rhery
OR Substonedi'on .
eye} if =+(m)= F40%) Awl’) = 7.4( 96)
ois (%)
= a4 (%p)
= 7274p)
= yh 4%)
10 = 490%")
pabs olan
4e= 40%) Hl)
ttn) = 7!
ate o
cbhirg log_en bot aha
lags e! = §og.
i= Leg.) Formula
ten) = 7 te) hee plas
tem = ni?
ten) =
Fem = Ol mre) | Time ConleyExample 2 [! i}, e.[4 ’
P= (Ant fos) ( Bt Bor) = Cite) Cat) = 2S
@= (Asit Bor) By = (atg)a4 = 28
R= Aun (Biz =Bor) = 19C 3-1) =D
S= An (@.)- Bu) = 4w(2-4)=-¢
T= (Ant Bis) Bor = (ite )al =8
D= (far An) (Bn Br) = (3-1) Cars) =1h
Ve ( An +22) ( Bay Bor)= (2-4) (941) =-¢
» ABH=C
“fo a]
Cy Cy
Cn = P+8-Taye 254 (-8)-3466) 9
Cr= R4+T = 0403265
Co = @ +S = 28-8 =o,
a PTR @HD = 0849-8414 = 1g
ofa
Ue Ma eg19
* Dsing duvide avd conquer methed, mebtiply the fablowirg
shoo motoices with the help of 84 anusen's modeix multiplied.
Po2tl//o rot
G41 10ff/o 1 04
o 1 30//2 o11
so a2ijl! 3 50
Sor
q yy )
lr A= jy ali at
“ 3 0
lo a) ay-{% ! ,A -[ ]
[> lb i - [° 0 3 |
let Be
fe (An t oo) (But es)
(at ‘MELE
“JG
f Nc) HED
it
tt
@= Cato iy
e ({!
Ss
= jz
I?
]= (As, An) (Birt Bn)
= (1 Nl HE |)
“Pale d= [h4)—~ —
= oF, Len
+
= Cara C a
> a lo aaa — v0 aS
7
°
| ay wo 2& wo fees
aT ag a
$= mo I nN a
— os nH Oo ao
Ae) leap ' Ta) eo
qa o- -o > =
= ~~ ao xo 0 +
7 =) (ol F + = Hs +
¢o9 FP jure + - wl,
ce = b fop mn Tw ! RR
gq 85 FT gore ba t <9 tga Yee
w oS wv LL on
N i} 7 | u fn © 1 a Te eh
° = 7 y i
8)
a
SCz Cy Cin
Coy Cor
It
uy of OF
_
4 3
‘Gi 4
I 7
@ 1
2
=e =——=s a
B Darog divide arel conquer method maldiply te Fableoiry
shoo medowes voit the hebp ok Lfrarscen's mespoie
Yet tplteed vo
Pz 4699, Fo, lo 6300 3 2 47
A= 48,76, 67,95-
R2 20,44, 16,40 b= 4 326 B-|2 7 To
B= 2011, 35,49 7 814 3.59 023
T? 16, 20, 18,27 393 46 7 7 6 2]
b> 84,28, 39,5%
38, 39,
V2 ~21,-26-m-55 Cn 38,34, 66,77. ena 30,65 34,63,
x Cor= 68,87 1091134) Core 52, 128, Bb, 124
!o2oyte)jo roe
|
7 !
Po Ul, 22, 7,24 4 4
0
ol
5
B= bsne | Be 4-646 Cr 44 my
se ,ooa |
\ ol 2
o | OD o (=O
Re 6,-S, 3,-9 Vv
’ 2 6,0, 18,20 a) =
3= 1,0,-9,2 pO, US, oo, Ione
21)
T= 4,14, 430 :
‘
Cn 88,1912 r= 3623
“Tope log ico Seating
“Tope logices) Seng ts bevesl ex the poineiple of
DAG, speeiic cadeniy « vowtte2s Ts possible. Thr
mettud of arranging the werttess Tp Same apecitre
monnes ts Codtes| Lopologre Seating .
Topobegice) seating ts dyyicles| tte doo sypes
© DRS - Rases} Algos thm
© Source Remove) Alani.
@ Des bereal Algonthyy
@ Seleot any ovrloitoeny Vortec.
® when a yeoter ts vietbeo| fea the Pret tyne.
ibrs pushes) on de the stack.
® (when a wreeter becomes a dleao} end. vw
syemeves} fourm Hy &dack,
®D Repeat sdep2 to 2 Ke al) He wottees tn
the geoph:
© Reverse.tne eveler of dleletect items, h geb
the topo logice.) Sequence
Exompke OD Apply the DFS boreel ayer ths Ay sel
“the dope degree Servding pooklen Oe the: oeStoel, aadyecency Nedewvisited Pop
a = Qa .
2) ab b a,b -
8) Abe e abe -
AS a be . G,b,e e
Sab , 3 Gb, e,4 :
a,b, 9 £ abet g -
Dar g,F : a,b,e,44, F
9a, bg . abeh g, g
@) a,b a ab € f, 9 b
loa e. a, b,cekag :
Nac : a,b,c. e, A ce
Da . a,b, ee, 9,
18) a a,b,e,defha —
la) d = abc, deta, dA
Prope Sane
anee. Batters todop te -
~this shiny rs eodled ov topelog reo.) slove
asSs
@ Souce Rome) Sports b °
® Fore 4 apie gop find a werter cot no
» Meemm’ calger. ewe] delele it allergy corto al
oO mf edly o» Peer ik.
He.
& UB there one nwt thon one such veadrees
then break the rrardenby,
® Note the vertrees thel are deleted.
® ABU the oleleteol veodreey pene Oo] the_
tepelegica) reatea Dik
Exomnple
@O Rpply Bouece wemorel olgouthn 42 Ssehe
logteed) Seating) poo laters fey the, lee goaph.da.c,b.g,F doc, @F.e
topalegres Seoleal bist 4,¢,0,9,4, @
. aloF
® Sea} the. digzaph Rea dopalog reo] 800} using Source
Bamere) olgermton.
(°) B.A. D
B.A
dek
BA, 2.6
BA, D.C
Aopelegteod) aordieg dnb BA, D, o,€\
Adv ex are) Disaolva 23 of Diviele & ere \
Advantages
O The artbreedt peoblers Ys plates} who subgroups .
ard cook Selo -gooups ts salves) irolependerdly,
Thrs appreach ts urefu) fer sebigy the dilhent
Pr bem,
® Dwide avel Conquer faratétaber the. krscorery
oh ebrerent odgearthros By example quick Seok,
Merge cab ava aleassen's mecoix mulyiplreos] in
Dis asbrantages
© Longe. mumber of sabres ore creaded) ana) gece
to be proveriecl,
@ onde are Conjuor algenrthey makes ure af
Teosive methods arel the weeensien 1S eben anal.
Complear .
* Finding tthe Maximum ard Minimaro'-
“The problem rs do Pind the menimeny ane) mmimern
ems ina seb ok 9 clenents.
Thes we peojire. dolel Crt) Comparten do obgery
minimum yedoe . Similooly we an oltedy the
moximum yelue. Prem an array A {n-1 Comperrser),Algaothny Moxmin (a, 1D, ove, mis)
Waits Bley onvoy ard MTs ane daray ,
1) 0% *s menimum velue_
J] iQ 18 MioimuTD Velue.
max<— alo]}
mm <— ale]:
fen T=) +e m-+1 ao
1 18 Cali] > max)
roate a (43)
3
12 Capays m9)
t minal
3°
5
era feo-
» Pinel mardmun aro) minimary vedic Celemed) Faor
List ob Ts 50, 40,-5,-9,45, 90,65, 8, #F
Ark Contour eo Reauorive. dree,
Soi?
tooo S 4 S ¢ 67 es 9
50, ho -S, -9 4S 9° 65 oO FS
oleh Given Lb ts aptikeol to Awe sabgecups
Sw group
as Ss & 7 & 3
So 4o -Ss -3 45 90 6S 2 FTsiep — Geoup are! Group SON SP “\
es 4 c 4 7 _ |.
3 4&5 3D 6S ue HE
Uw a
50_4e -§ 2
Gs Gy &s Ge
Sep? Group 2 agaio aptiteal nko chee Seaogeeps:
1 2 5 boc a e 7
50 40-5 -y Ag ees Be Se
q Gy Gy, Ge Gy .
4 frp
— gee Ge torn =4e K mox +5
(TERTR]p
gtep Garry
Cealorce. group G mry=-S A man e-
[3,-5-s)o
Steel Combine @ 6&6,
mar = 5d min =-S
[1 3, 50,-5 lo
Skept Raw qeep Gy mows bo Amine-g
[1s 45-3]omons 50, mir 2
1,6,5% 2 J@
BlE2 Combine elernert cin a7
+ ynee> 92, mine 6S
combine. clened 01” gs"?
mone FS Km =
[as le
Coubone clement ay do a
pan = 90,min = WT
poe ieee Right sebgoouP
ee ert qoour
man = 99, mI +" 9
1 lg
[v3.22 95= C emer
atten) =
PO > W
toh) 90) 7B
deo) = 290%) BP Arf.) = 9CYe)tr
= shy eal*
4 = Blips 4 ,
S = PTE» Fine} MMIMUND aye) Mantmuns Pepin tHe
Sab
=
6
VV
22ND, 5, -B, IS, 60, 17,31, 4H A construct Codd Rewy
Stray. spiel iwh chee poots:
'
2d s Ue é 7 g
9% 1% -S -B IS 60 *
eS oe
Ce
LDF pent aval Atght post aplkeol into Zeb group
t L 4 ko 6 1 s 5
Oe ee CC ea
Ce ee
Spbekeo] Into Selb gaoups
\ 2 3
Ze 1s 4S"
re "oe
[ae ly
[us, m1,-8 |e 6.3, 60,14 |
[ug 22-5 le as, Ist a [ew.cer] [esta
®@_Atsignnest TE \
O Encplodo Browey Seonely are} write Olgoathro.
QQ Poove. tome Compleres & Brreroy Search 18 doy
® Shed dime eomplems of Meage seat rts nloyn
@ Apety menge seb
@ 0, 20, 20, Ho, 10, 56, £0
® ExAmPLE © QUESTION
© Eeptero Quack goat ane} fine) sme complorsby
OCosege)
© Bprby Burk seo algenstinn aire aonstrest ent}
Reoornve sree
@ 5.4, ono ey
® Example © QuLcKSORT
C) Explain sigoaen's madaix mulled ion
wort sim >
@ mablipty mab uainy S4xaHen'S mech? mubhpbed
oe@ What ts topologteed Seeding 4
© Apply the DFS horea) algsertino to solve dhe
rtopologicad) send ine problem eo ‘he fadtosorey get
@ ©
® Fnebo Mardi mur ave) mioimury Vellat. Prony Y
of onroy tarot Consdraad- podle Reasrive doee_
@ 50,0 -5,-9,48, 30,65, 98, #S
© 22, 18, =) 8 I 60, 4, 31, AF