0% found this document useful (0 votes)
100 views21 pages

Dsa Notes Unit 5

Dsa notes for aktu exams unit 5

Uploaded by

prasungupta251
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)
100 views21 pages

Dsa Notes Unit 5

Dsa notes for aktu exams unit 5

Uploaded by

prasungupta251
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
You are on page 1/ 21
unite Graph trabhi= & Grabh Com be clefiged <4 Group of Vverhice awn eAgey thar ave wed to Connect tere VerHerp, A grabh Gnsist two diwinge QO: (CAS) A Sek V of €lement Celled mode ( point or Yerticey), meemmat} Asck & Of 44gq Auch Mu euch edgy in 6 i unique feiveel of verHieg FUr,v) aia | Adjacen}noder— Subhofe @= [U,9J then mole Youd v are Catlecl ene foiwt of e€, awe U ame y are dated fo be adjacent mode or neighbore. Degrees The degree of mele U writlen cles (u) 6 the number of edge Conta wive u, ui deg(UJ=0 then U 1% Called (dolate node. Pati A pal P of leqginn from a ‘neder u to nade v (4 defined ay a , = Connected [bteconnectexl Grate A grabh i Connected if there ig a patin between amy “Ho of oder othereise grub ke disconnected, Complete graphy - L ny A grebh ix Gmpleke if every node Ws u eo lacea to avers other rede U in G. A Complete graph wil have DOAD edgep, labeled Graph - A grabh ig faid to be labelecl if it edge, BAe asngned dati in the lebeled grabh Some weit assigned fo tach dep, Math edger Heaps uf Eder |e lowel ve! eee ee end point eande! are parallc| edger. Shi- Ba edge @ id calted Joob if tt hag Leal end foinr je, ~e@=(u.uy Welgnter| 4 netbh: eel gw 5 Graph Rebre Hor fe ineplemeat naph Represeufetion The wel ote ia fed by esl scene a mnekax rebr 1 a 4, > C) Adjacenc Makar 5a eeu oor. ithe ise © pljaceneg List Cea aire SAC Oe ee “Od direchion of gai nen tb40H & £ i team Wwe Gon Coter! for A] Adjaceney seta eM wat v) boos > makay Gre: depend Oo grab: verica [nxn rn Iku a mahix alrt(nd there ig m0. of Vertiter {a= YY fon af. rele the +_Inthe od} acenty yep steel Ls} + Adja cover or on grep is ase by swale : { = T-e i PT ees 7S) | cy IHN Ww Beet O(m 42e) There ave ome drowbacky ™ peg ue tee”! Le TE may be defticutr to byert ame detehe node © hecuye the fire of medax A” mau need te, be Chevg-ee] ewel node yeed fo be Yeardlered. 4 thes numby of edgy 18 que to nO. of rede then the matix A wil be Shane (will Gran mane) Zeve)| hence Greste deat of Space wil) le User tec, ; Now the above Cande tewo adaceseg : Wore aufeh aNbeclo Vertex Graph Traversiv9 s— The process of Misting avel Zrblvig 9 ca. Srabh for processing ia Guléel re. (1) Debth Ficst feareh (Corey es slack CLT Fo) @) Bredth First fears (BPS) - es Mveur CErFo) he ese Gea e™ AS Debt First Search s- Tt is pebular fechnique ee Spmmebic. traversing. A depth fist Aearch fist we frevese Att” Vertex aval then ite adjacency vertex. Ef there are more thom one adgacencice then We brewere ae oue of The adjacency Vertex camel thea its adjacency Uertexee castef ea. Her ning 0.4 “deed node ? dratis, tothe end ofthe batt. se badttpeck on Patty unbil WE Can Gatinue alorgcineticr Pet vcwd foe. Duringy the Executjoy of both aly onthe Each node in Graph wsill ( one of the three Abaleg. Status <1 — peodly State (The wal State of the Neen) _ STATUS = 2 USaaitt eae mode iM iB oe pa or Seal, sintus = Processed SIE Tre nade Wi hey been frcescd. TMS algorttiven i4 —¢rmi i: — . S 8tie bimaey tree. _ i, Algorithm + % 1. Initialize all nade, 4o the ready State. (staTs=1) % Pushthe Starting mode A onto STACK aml change It Staley +o the Waitiveg Atate (STATUS=2) &- Rebeat Steb 4 andl 5 Unkt STACK IS Empty. Hy: fob the top node N Of Spack. Process N ane chaye (& Lhatuy to tre Ayocessec| State (statvs-3) | | aa Push onto stack all the Neighbours of N thet Gre SHU i'n Yeadly State Cspatys= 1) awd | Chante their statu +0 the Barhng Ate (status =2) 6. Exit. (D Subpose —Starhing node u A STaws4 = A,B, 6, DEF GH + STpIvs2 = Ld } Stas = A eA a ® status) = BEEGH Stamis2 = GC) TF Q Example i- ft) Pop E From the Ftack ancl chge its fates &to3 awl push ike Heighbouns usdseln are Im Statey 3 te 4 STACK omd chomge their Stetup 1 ed Per pases) A STATUS 2 = BRAG eal me svatvs 3 = A,C,E D A & ae € %G mee pop y= eae A STATUS 4 = OX STawsee B/D, eA on OS, 2 STAYS 3 = A, 6,E,G a vs e 4 : A MW) bobs ee 4 STATUS | = e STATUS 2= BDF STATS 3. = PISE OH Wi) Pob F 4 Se i eat : Sa? ame ll pa 7 D St 3 Ae ye a - pi) Pob } —* ¢ ST" > [aa ‘al Sue “4 a sta = AGE G MED © m he ol rs 2 Sia. = $i = Ors = rie Breadth Pivst Search (RES) ¢- Tra breadth first earch first we fraverse the Startivg Node ave then Its all the adjacency) Vertexes. The, teke omy one of there ome travers ity all ad) acenc J omel So on. | Algortthwo + Initialize alt node to reodly State Grats =1) 2 Put the Stavhg node A tn QUEUE auvel change its Statyy to waiting Stete Cstatus =2) & Repeat —3) Add tothe Year o f Gveve att the Neiglters of MN that ave im the x cacy “lede Cstatus= Ome} aee ee sie ) guphose A iS Startivg poiuf-(nedle), SATUS = Aid DER OH. enqueue A in dhe Queue evel Cleegep tts Staluy eae fal) Queue - SATUS 2 > A : g Pequeve A es the Clureue ane} Charge ibs Freby fon b, 40.3 evel Erqueue ity neighbours ufo Muewe uotnels are iw Sead anne chorge they hee A fom 1 fos fo i" é S73 = REF, GH : E e SIL = &¢ ; telel_] wir bequee F ames. st3 = A, eee A GD) pequeue B from =a iN Gi Spl =] erent ST, = AibGDEF ape = GIS ees ot Depew —e— SwZT = Re ae Gee ic eee eo s,, STi = FiG\H mt stp) = prenes(pleinel-e! Stz = PB? Sty = ABC? SFG Dequewe H Prom —a— : Ts Dequeue fen a A sr= Sti = GH fo Sts= Pi B, GER GH Sy = eae tee \ ST = AibeCb dequeue - € from —r Sto trees + number of tne trees drawn ph is called Shannw9 trees. If the Grabh is weighted geabh dren if we added tne weight of aul ils vertexes In the AS paorieg dite; Tne tree Which boy minimum fell of all Vertere, Se legal imp The Shinnivg tee fromthe 0 A meted) Subuprabh @ of gaabh GLVE) is ded te be org ifs () Gabqpaph Should Gate all Verticey of & @ Suygrabn Arould gate C(viet) edgy ee: Vs's oot 4 ° Aye = Ul = 7 . 24 Ke ¥ How 1 Sbonning Atree are conshete ig Given Gywhlete graph: fom a gral Complete graph - prstel Alger bn a is beyec| clivectly on the qereric. rinse) Apanni ee Algorithm ust gees ae gemove 2h am hea’ edge. “”d 8 dy a ) gore msT- KRUSKAL (og ae y Ah AS te . Q. for each vertex VE v@]J @ : do make -setCv) ; eS q D coypine Sige Pe aemymendecte9s 25 oreler by Uleiglt taken In Yondecresig coder eglt qe edb tH DOF 2 4 5. for each Gt) EF , «dda if Finb-ser(u) 4 FN b- Ser Cu) > ~ VE €legEr+e 1 then A AU SQUU)S i | = 0 (Elegze) 8 UNFONCU,¥) F ae 9. Return A» = lege +4e9t = ocelegv) MAKe=SETC2) Create 4 nei fel Wwhece only member Come teas reprefeutative) is 0. Svce tue 4b are olisgorut WE repwre that ye not alreadey be tn the —Some otner Set UNFON Orig) Ubsitey the dyramic Fels tat condany xe omg day Se and Sy. inte a men He that (8 the tmion of there tuo -tets. cis. cer Gx) sretarn & “Porter fo the Yeprecutative of tue Example: - B= £066), 4,0), iA) Coe), Cet) © © © © @ ® sdaiilkaal Sites aclce Z 4 ets | @ re ) arn s @ cheese @b) ee a @) — © werd at ® cheese (0,0) bit net union fecure it Close the ary © chase, a, J ® ces (ce) © cree (ep) Cgint's Algontt dreels the nevle % 9 divgle tree awef } ie BA adding “esd nocley to Apanninrd dree. ¥e loop avd baralte| edge: “fee p chose any arbitrary mode af Toot note. pir’ Bee he. q A gorithm Msr- PREMS(6,W,r) 1. Poy each UE Vlo] a do pec | es Pluja_nid, 4 key [yJ<-o Ss. O«VfaJ 6. while Dad 7. do ue Extracken min(g) 8 fr tach We bj [4] qe {4.b.6 ay ca dof VER cre) was cl g u. % aul lee Te PlvJeu uf KY [ule w(uy ——___—S—“‘tPaP Transitive apsure * ‘ For diveded gretph tne (.€). The amcitive chave of grabh Gig a goabh G”= (viet). Go fer vey vertex pur (vw) I” V there 1297 edge EX, if bind only if there ua valid pepe, fom tow In G a d pe ptide afse ale ' | tot : ¥ Eitan (re wo 4 (4) 4 |? 1 v gdh @,4), (ab) (ad) @d) (ae) ela \ | O88 (bid), € Hb) .0 Reachabisity Madnx. (db) Cd OC4ad) Cde) (ab) (e9 (ed A fair Shortect path uen 2-1 = 9-1, 1-1 23S 9-1-3 i-< floyd Wars hal Algoxtwn Create clisharce matnx in ° 4 \ © 2\ co 3\4 Floyd -Warshel A lgoritin The Ployd- werelwll gi) pair shorter path Algontin we a Aynawnc * programmivg metrodolegy to folve the Al. fair Bhor tat path treble. The algortin rane in Ov) -4,, awd negatively weighted] edge may be Breer, howevey Negatively utlputed Cycler Cure “froblews uttth the ag oth Ihe main yecurfve clefinition of the algerstinn i per by: Kl ; Aree BGs = min gee) i, AU asa Gj) if Ke FLOYD~ WARSHALL (Ww) N& yousCw) bow for Kx-1 to ‘do for fe1-ton © you do for Jeacton Colour * do dee ri (a? a Guae ans ay yi Ne Yelun of” sige $ ource Shorferh Fath: - pijkestea’'s Alg.o rtm of pifkesta’s Algoriten Solve the Sigle fource Aborter jal frorlen uslen olf eeey have -non- negative Weglts yin a greeely ANgortnm gue] —Semilay to Crten’s algontre. Algonthon Ateark of the Bereenictcx, 5 it grows 7 bree, T, Theor ubbinehely Abans all vertice reachable fom S. Verkie are addel 40 T in order of distance ie, first S shen the Vertex chheebs closest fo § then the nevt closest, ane So On. folrowieg implementation assumes that grabh 6) is teprestube) by ojacenc Hiss, Alewo Al genrtivm: = PITKSTRA (Gy, 9,5) 4, INETALIZe Srnaie- source CG,s) % gf ff 5S wit whimately Grbaing verticey Of inal Aherteet Poth weiglt from S. Tnhabize fron gueve @ hee, O— Vie] Wile priority dueye () 14 not ery do U— Exrencr_manC@) — | Pull oat new Vertex S— SE{UE If Fesform Telgxation for Gch Verken y adjacent for Gach Vertex yin Adj [W iy | Felax Cu, 9,19) © ' LT ravize SEN GLE SOURCE (G,S) in For Cac Vertex ye VC Hh de d(v)aeo © z eae hr wy 4 PCO )a— Nit. dee Example: - = (QuyxN] g [s, S Q- C4, vOy] S- | 8%,

You might also like