0% found this document useful (0 votes)
106 views63 pages

DAA Unit-4 Notes

Uploaded by

Ragipally Divya
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
0% found this document useful (0 votes)
106 views63 pages

DAA Unit-4 Notes

Uploaded by

Ragipally Divya
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
DESIGN 2 ANALYSIS OF ALGORITHMS ONIT-4 > Fpaphy lgedthes page Snape DFE REFS Yranditine closure 6 Ducted Aryolio. Smep Topolog On —> Tris uses Tite corer Thies ; > Satomol beaschung (a, 6) Thee Be Trees Scanned with CamScanner a 3 gt. Professor 21 OSE gUMRANA siDDIQUI Ass A rowersol is haet . ae , na pyslemales proaduse. for eaplewng % arepl enduring “Bih-iek 4 whtiéa orn edge Rl gpadke Vigil all the vertices b odlges on ten! The tao Franenalinethods dutibed av () Bruel Fisk deschy + ln buat fu earch, Stork ot a verter Cy? amd mark it os having, hen visited. The vertex *v" at this time dona to be umeaplored: Al vertea. bid to have ben cnploseal wher all vesticey adjocerct peor rk bax ben visited . All unvisited 1 | Cy? an visiteal newt. Scanned with CamScanner com be pupnesented wing amdasd epasorbatons. 4 Algoxthm BFs(v) VINA breadth first Search of G is caried out beainri 3/) ok voitox V- fos any mode 1, visited titea ith nod 4 |] adrwady beon visited The graph G amd oniouy 5 visited C1 are global visited] is intialized 4o3er0 64 7 wrevs Igy ib a gpm of unexplored vortices. @ visited [v]J = 45 4 Teopeat ° toy all vertices wo adjcunt fom u. do \ ‘ t *f( visited [w] = 0) thon | t - Aida vo 45 973 If 0 6 wranplored lo visited Jw] := 2 > it % i ay is emg Hen rekon 3] No uncplre ever 20 Delete the nwa curren » undrom Y> al ey Get Sivst unexplored voter » ad 4 wait (false) s a % Om : Psst. Professor CSE, DCET Scanned with CamScanner ) Daplle hast Bearelv 2 In depth first earely the exploration of 0 vertex’ v? i Suspended QU hoon Ob a no voter le hod. At dhs time the eapleration ) the nud) Vertex Sur? am. When this rev verter hax been erplosed » the exploration 0} °V? continues The searclr femminatic when all Peocbed. Veitices hone been pully explored . 1 Algntthm DFS (v) 121 Giver ov groph 6 = (VE) with pvohas (SH) and an visited CJ: fritially Gy he goin, ae vol peacholole or Ip /[ V one visited - G and visited C Jane gle 6 2 \F visited [v]:= £3 L 8 for coh verter Wo adjasunt fom Vv t ’ lo if (visited [w] =0) thm DFS(w) 5 I ff Scanned with CamScanner Connected Componenti and penning Ths y G ik a connected wndlirwelocd geaply sum All vertices of G wil act visited on the fost cal of BFS. Y Gu not connected , thor atlask two cable te BFS will be needed . Hence , BFS can be weed te deborwime whither 6 t& connected « All mowby visited veilicu on acallt BFS fem BFT feprcserd the vuilices mw connected component 6 Cr. Henee the eonnected comporunls of 9 gsaphy com he obtained wong BFT. As a final application y BFS & DFS> i the problem of obtaining av sparing, hee ee am wndoseted gsaphs Go! . The gig 61 as tpeing i G is emnnuted « Hence » BFs | DFS determints ° w & annin fue. the wiiskenee ¢) ree vain a, BFS/ iping hd pes on called buadith [er © suinmana siD2IOU! ORE gst, Professor <1 ese, DCET ‘Scanned with CamScanner Pease. | + lie the ppl bl Draw the bpamunwna. bees ator gg (Orie) Scanned with CamScanner “Age. Professor voter 5 Aogstlud fos adjaernt- Unvished vertices. Y mn unwisited vesticu food. lop s fiom the tack and book for the tw umisited vestica 4 the top 0} the otaek lop & pen Fie wnvisited voskices 4 clement amd svoxeh Kb a 5 bb ia Goel oma book cpr Fe one frond apt ea Keep doing wil The wp ctoak a Scanned with CamScanner (8) Add 9 vuten ilo the os visited . Nov add the vowtea. in qyruae that te vote chore 9pene | bun Visitecl » Scanned with CamScanner ere aoe . SUMRANA SIDDIQUI ». Asst. Professor * G5 6— #8 Scanned with CamScanner ‘Scanned with CamScanner Sn the connueteol gregh. above. vertex 2) iy anedetion point ab the deletion of vile Gip2 0 (2) 3) CSD EC) 3102;5) leaves behind hyo disconnected ‘nomempla components © ©) [> The Gyvagh 6 has ether oo abit ory porn: vortex ©) omal vedo @ orp Hing, tomaining vertices 1 deloted cia Ly one ono i ™ 7 A graph 6 conrad Ty amd only ty contnime mo Ssdiculedion point , = & O—6 pap is biconneetec. Yhe above SUMRANA SIDDIQUI ‘Asst. Professor” cst > dhe crmectecl spaply is tesed If it is beomeded. The qoaphs thet ar wot biconnected, al the articulation points mad to be detunined , ae bet of tolgcs whose Inclusion maku the graph biconneetedl crs cetamined. Determining such a bet 4 tages i fpceteted i the marimal. gubgéophs 6 that ant biconneeted One known » Ge (VE) % a maximal biconnected bubgvaph G if and on if G hak vo bicernucted nbgraph 6)" = Cv", 6") buch take ee hCLULlLhLr Lr A mmarimad. biconmectect bubgtaph le a/ 5 the bicovmucteel Componenti of the graph 6 below Wu Scanned with CamScanner : het By Ba yse+> Bk be the biconnected 4 componenls containing voter 5 5 6 7 het vp ou; favs be a verton in Bj» Leicks Add # & the edges (Vj sVigds 4 4b KS r 3 the paph G com be transformed into a. biconnectead graphy ba wing Hy above edge addition scheme. Adding edges (4,10) and (10,4) covepanding to tie Onfieulation point B 5 edge (4,5) counponding th the ontialntion point 2 ond edge (657) covaspending point ©» tramtjorme the gsaph & inte w biconnected gseph. 2OSUMRANA SIDDIQUI "gst. Professor * ‘sy OSE, DCFT _ lll Scanned with CamScanner Y has “p? articulation point amd. b° biconmeeted components , then eaactly “b-p? nun edges ane Inboducecl info G. —> Problem fer identifying The onticulation paints ano bicownected compares of a connected. pepe & with m 2a vest Couidu. the gr below « Scanned with CamScanner dhe number ontzide cach vertex cormepond the ede, 'm whier a duth fink search Visile these vertices. Shis number is erred be 06 the “depth frst ? hn, egth fixst mumbers (clfns) of the Thus 5 dfn[4]-4 dfn [io] 4 dfn [5J= 7 din[g]+ 10 dfn[u]- 2 dfn[3]-% din [4]- 5 dfn[2t- 6 dinl6J- 8 afm [#] «4 dn the figue above the sotial edges pon the dipth first Sparing true These eda ew dre called © bie edges”. Broken edges ie ol the Aumaining edge One calleel * beck edges : ", SUMRANA SIDDIQUI Asst. Professor afm [ul . 5, be below, L 1 SUMRANA SIDDIQUI Asst. Professor (OSE, DCFT Scanned with CamScanner Lfio]- wim {4-2-3 = 4 L[a= win $5, —1-4 5 L[6]- min f 8o-2-J 8 L[s} mm {102-2 Gh =6 L[ a] min 76065 = 6 [5] < mn {TF 6 Lf] emm}6,6,24- 4 L[z] =mim $3,4,-4-4 La] = tim GL tend > A Lfa] =n G4,4,-$24 The | values [[ists]eGtotots4t ,6.86,655 44 The witioualion poonls ane Tdertified wing the condition [wo] 2 4fn Ju] sifu child ‘0 omd Cu? is wot the vob - voden @ 6 the rot @ voter ® bs a child 6) Ls] 2 dfnlad 6265 ue - » Vota © wom ovdiculation pol i | ‘Scanned with CamScanner utr © haa Children @ @ L[ oj 2 dfn [3] 4.23 => ee vedex () u am adticalation pont ® verter @ has child @ L[3] z dt [uJ > 172 = Fae @ win © has a childen © @ L[eJz dfn [5] a7 82 Fate + verter @ 4 am articulation poi. & vuten © is ov leaf mode - © vectrn @ has a child (3) L[e] x dfn [1] = 6 z 9 = Falee © verter © ia laf mode . verter ® u ov ap mode « © vorbee iu a leah mode « The anticuladion points one : 2.3 Bind S : _ SUMRANA SIDDIQUI Scanned with CamScanner > L[u] cam be ently compriled if the vuilacce of the depth fin Aparna ut we visited in postosde Thu be detent the asteulation ome, it 6 mecessau pesferrn rp dept fet Seaach of the graph “Gy? and vicit the odes in the nesntting depth first Spanning tue ‘m pe . 4 Algesitiem Art (u,v) AI) wis a start yorker for depth first geasch. vie ile 3/) posont« It i axsumedl thal te glebal 4 [dfn i initialised te O amd tak the global variable S/n & initialized th 1.1 uthe numba of verliasing., 6? . 7 dfm[U]:=mm 5 L[uJ:=num s num zenum+4s ¢ Fe each voter “Wo? adjacertt fom “U” alo 1, : iF (d$n[w]=0) Then | : i Art (wu) s // w is unvisited 13 Llu]:< aim (L[uJ>Lpo]>s te elee Hf (wo $v) thon Hul]e= min( Hu) ele 5 \F 4 a Scanned with CamScanner SUMRANA SIDDIQUI -. Asst. Proféssor * ~ I Once L[a:n] has ban cornputed ; the arttculastion pointe cam be identified im Ofe)Him. The comploxulg ig O(nt E), woh €? ie the number of odges in & 4 se > dfn [ul] SW & era, the root ot aim anticuletin poi Regovllas of whiter Se snot tha neck os 6 He fk orl as oe children 5 the (usw a ihe od. base rms Licernucted cemporumt 1 Algevithm Bilomp( Us v) 2 | 7 fort vestea for DPS: vt pol Oe jf tn the depth SO tis agum ek is inti O amd that glob on ann mie vy the m4nbes of vesteser © . wm 64 7 dfnfu ]:= 1m 5 L[uJ:srum > fo, ey vertex vo adfipcemt: cprorn uw do % © gd v0) od (aos) aD) he add (usw) ti the top of aS" © numicrum +45 Scanned with CamScanner la if Cdfn[w] =0) then im if (L[w] ee dfn [u]) then ! ic ‘ lonle (* New bicompornt") lt repeat 18 § " Date am edge porn tre topofidack ss Ao Lb this be (as p> 2) wk (x45 an Ss unhl (Gay= (uo) ot ((xsy)=(too4)))5 a3 2 fa BiComp (wo 94) 5 I] w is unvisited fuse nim (Lu), Le] a6 z at eke if (vw ¢V) then L[u] z= min (Lfu] scabies a8 % 4} The Computing tie fo deleting, the biompore la Ofn+e)- Scanned with CamScanner Wanattive Chew U dlinceted graphy» alto Known as a digraph, it L whose aw all directed... Gjiven vertices ‘Ww’ and a7 a digpaphy G, CW? peoehes “vy? (and ‘v?# reachable fpom ‘W) if GF has a directed paths from “u’ to'v?. eA digas Bi snl conned jo ben wedi te? ty? of > wW? reaches ©y? and Sv? reaches “U- By A lisated cycle of GF is a eyele whine all 4 se 00 Saeed SEE SN tuspuckive direct a dita =s A dignaph GF i acyehe if’ oye: nanos * Q—-O-7B dined ogtle oy = 3-70 oalaie* @ uirgly commuted dippers SUMRANA SIDDIQUI .. Asst. Professor * 2G Scanned with CamScanner uch that ey? ig reachable ‘W’. : sj ©? wdiue- Lot G be a digraph with v and ‘on? eager - The lraruilive closure % Gy & hid ma Surie of round = . Ynitialige Go = O Number the vertio 4G a Vpo Vag veer Vn by ian ela. edge Cuov) fa each‘w and 6v’s Scanned with CamScanner : Begin the compuctalion of the own 5 beginning with townd 4 © Ga a Geume hownd he consincl: digraph 6 Yastin with Gre Gin ond adldung te Gx the ducted edge (vio) if digraph Fas cordains both the edges (V2 VK) amd (Vj )- 7 FR isfy. digeaphy Gc hos am edge (vi2¥)) ih amd only fs dipeaph F has a diicetec paithy joom Vv; b Vp whose Iridemedialé vertiou lif ama) gow. in the bet FVyo-e1e3VkG + da pankioulor , = = -— = Gn te G® othe ramnibine hesuse of Gy. spit con be wed to compute Ure Womile cles Of G- Wanshall (Gr) 1 Algosttvan FloyaWlans a ; Tay Snput + A di bh G vith, av voices ‘hae Coste close G* & Gi. 3H Ondpwit The f AU] hak WoNaonMn be mumbemeng of the sy aA ; a 6 < YY > |. SUMRANA SIDDIQUI . 4 = 4» ne Scanned with CamScanner 8 doe Kiet tn do | Gi = Gy > lo for ire ate mn do /i#k. i for Jict om do Mt. jr. iF both eat (up sVidamd (VaoVy) one Ip im Cre then \4 IF Ge dows wok contain diveded edge \5 (visyp) then IG add diacetec edge (Vir) pe Ge. 13 talon Gn - le 4 Bi ating # rile emp Kranalace clesune Gr 4 4 By crenata omy Oo Aeris 4) digraphs & o87,s--- Oy, 2 ) bea by itl‘ o? veils repreunlal ate 4 tralia. The. Floyd blarshall Nan ol ae lama clesune Ge or Gm O(n?) time. Scanned with CamScanner Sample + lonide toe flering raphe V2$1,2,3, 45,6] amd EBONY C3) (2.45) (3). @ 4) (4,6) 4,305} Consputi the Thantitive closure Ge. dolvtion Veet A Bo o f “Aajaaneny Mala fos GH \o001 1% mi o Pal 4{060 1001 blo 00000 6]000010 B23 456 0 @:£fi\ 10° T bi Jo vl LO E lifto "i (0 iOr 4 [po 1 1) 5 ooo oO. 4 ¢ jooo?! 5 6 ) ,2a ug 1 THe yy oom (2727 B2\641 0 wh pay 1 6 oot parle | aPIR 15 po ooh? po 0 ott . 6 \. SUMRANA SIDDIQUI Asst. Proféssor - CSE, DCET Scanned with CamScanner Scanned with CamScanner Diveclel Payee Greghe an pithert Aiedld eye cone m aman applaalions bud ov digagh i eft nfo 08 a dd aegelis graph ee Bag Applucalcons of, suucly ap he mnclude the illasing: * Inbuidamee between BU anes 5 Tm rine : Freregpirsilece between Courses be + fehedabing tonal Sob, ened ” project. Topologual Ordos A tapologueed erduwing oh is a ee v3 Vm) i. is oh & buch that wedge (Vie oh G >» V4): bw an oie eralepieng ’ Os dineteol p he cee "'sumrana SIDDIQUI ©. Asst. Professor ‘Scanned with CamScat 4 Algesithm To; ical Sect (GD * Mabel nde G with m vertices n Vy 9-19 Van 21 Og» Per eb ina ph AW Lat & be am initially empl Simo 5 U) for cook vesen uo do inecuntos (w= Indeg (HD = if Greets (u) t= © tem g g. puch (us sy 4 jre43 to While Gis mot empty do 2 4 ops Tein as the eth votes ) trebt4s iy Mn each edge € eg: out Tneident Edger) dl Is Wie ee oppetite C4o® lo smneouritin (W) 1 rneourlix (W)-4 5 7 iF Cjncowades (w= o> then 18 G pee (4 if Su 2 wien gh GP hax a diveded of Scanned with CamScanner Croemple eee the topological ediiong [sebing oy Vertiecs in giver digraph : ALB) QD é IN Solution 4 [| @-a QH-o Ir & = Begun, verter, A => it & wwisited a once Visited ,mark if visited amd book fou ile Unwicited neighbor (B amd FD CO BY (E) BN wey O (in clphabetical ged) bnolv stock dnd Plah Bin Slack nwisiteal neighbers a hoz 10 » | SUMRANA SIDDIQUI. Asst, Professor Scanned with CamSc amd move back tH Veter [Link] verter A has wrwisited noighbe F. Visit F. Tt has MW wnvisrted neighbess: Push F to cheb and move back -o A. Now A ako has no Wnwisited neighbors left: Fux Ain thy Stack LA | E New coniider another Wnvisitedl He mode C. Visit C. Since it has “o ee reighbers - Push Cm Stack. Cc LA | LF _| i | a Corside. omothu verter D. Visit D. H Move te i wnwisited Meighbe E, Visit . Visit LT. E. Move to te wowisit tnbiqhber. T Since T has no Uuniisited neighbor Puh Lim ‘Mack amd move beak t verker EE has ne wawisileel neighber Pudi Em etack and move back 't D: D also hax no umwisited neigh bets Pap D in Stock’. Scanned with CamScanner Now considur verte G - Visit a Gincee all ik neighbors ave all visited Push G in stack . New chee verter J. Visit J: Since all i neighbas ane already visited - Pasty Tim Stack - oll the vention of the digraph, anal Since One visited . lop ovt the Stack elements for the Topological sduing of 4 EEE: ERGEREE EEEEEREP Topological Ording . To DEL CAFS 4 oo SUMRANA SIDDIQUI ana Asst. Professor Scanned with CamScanner —> het G be a dignaph with “mn? verditer and Cm? edlqes - The topdogical Seiling Waesithin ume im O(n+m) time usin O(1) aurrile Space s and either compris a Topological ordering oo Ov ik te number Gome vertices, which ‘indicates Hot G how a directed. ogee Scanned with CamScanner Network _Flew_ A flow melwerk N conisle of the jpllowing : © A connected directed graph & with, nonmegative inddegor weight. on the ed , where the wel. Gun ealge e j« called He capacili e(e) of e. O Two distin ishecl vertices ss’ and t, of G, calleel the “sowner’? amd sink”, puspectively., suck, that “3? has mo imcowiung edges and “E” has mo euctgoing edges A‘ low? for netweorlt Nk om ausignamet ef ar vp vas Ho oh ee 6 5 that sad the polewing properties 5 * For each edge & of a, 0 ZF e£ (2) — Ccapacily rule) Sumani SIUDIQUI Asst. Proféssor. ” CSE, DCET Scanned with CamScanner * For tach, voile v of 6 distinct from the bower & and the dink t ££. f0=2. 40 (conservedion mule.) eee (vy) ecE*) where E-(v) and E*() doneti. Fhe bole of incoming ond. uct going edges of V> respectively, . brample fo ogy . The by $(e) wu called the “flow? of edge e fi. a fino 4, demoted by Ils & egyal ty the total Omourt oh flem conimg ont trom He Sowwee ‘8’: if] = 2 #0) eceEt(s) i tiny fr flow network N is a flow Peta Value over abl flows for N. Scanned with CamScanner

You might also like