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

Striver Graph

Uploaded by

Rohit Rathore
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)
403 views21 pages

Striver Graph

Uploaded by

Rohit Rathore
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
Page: 1/21 " GRAPH DATA STRUCTURE Handwritten ~ Notes Raj ea Tapesh DuaNOTES 1. Introduction to Graphs 2. Types of Graphs 3. C++ Representation 4. Graph Traversals: BFS/OFS 5. Kahn's Algorithm 6. Dijkstra's Algorithm (Using PQ & Set) 7. Bellman Ford Algorithm 8. Floyd Warshall Algorithm 9. Minimum Spanning Tree - Prim's Algorithm 10. Disjoint Set Data Structure 11. Minimum Spanning Tree - Kruskal's Algorithm 12. Stongly Connected Component - Kosarajv's Algorithm 18. Stongly Connected Component - Tarajan's AlgorithmVOTO OTOCUI! gihaie oe ES Grokh dota AShuctore ) 4 Connect To othty nods chyouyh edger. We Is 4 Speak “type oh Srcbhe with Some estnCions . Nods 2 AKA atic, dhe tudota . Numbaing of tv maces Gp be done in any orduy. Cage + Two Nodrs Oe Commectd bY % hongon toe Cine Edge Com be ivectd os Undive chad _ + An edges Oto dinechd Frm ons Medi te Ris, a Onothey eg note tae Powers Ede Oe i oo) Ooo O—o } ‘ w voy There is Gh edgy ble There & On edAL fin Roya ae | U>¥ ond vou us SV ond os wene ac an enclosed Stroceres tt —Grebh does rt necessamly neon Gon be an open GrrUctUX cHwde - & Mrobh Rave Cyd> (, * Sore Gam a nod: nd ends ok Sam Node, ondsrectcd Acyelic Grob CDA) > Diveche grobh with Mo Ey bo io rep © Path Contains a Rot a nodes Gnd cock Ay aan iS yeachohe - ee) aS, is o path. ee is x poth = Crvods x Oppret fuse) qauaes wk po Mo edges Oe fem Degree So Groby © 94 isthe no: oh edges Gnee ge ins ov ie gudside chat pode. « Fox Unaredih Orb) Heghts -2 0 HO Gh edges otacha too 6 * | Propaty > Foret auc - oe alt (2 t Cage 2 | peecanee curs Kage KOKO GOtE 1 (> | Spas 240432 32 pee | , ' 2) og ee [ + Fox divecta Given ua hove Indigy L A (3) mL i our da re ee & t Adasen’: No: & incoming tage feng 3 a ndeqyer { moe] | = Ovtdegne 2 MO- Q oukGsing eclgc, Se Cae acti ay Edge Ldeghe 8 Cobh v4 owe Laeighb Ossignad 6n nie 7 Chin ested os Cost & edge > FY Wwaghh aw not Osignt Phen cssunre the Onit oe fyptition @ Guhl «= Analytsis 4} elective circuit © Shovtst youts plug Hus placts 2 Novigasion Syshwne Vie Choegt er © Socal meck’o , +o Stoxe chate Cabeut €och Usersyor Pe nomber of edt? Ost ro Gna 2 Uv > Yepesenting on edge 1 vb. de Gine = fo Beundahan te number of Cdyes @ Adjacency Mora @ Asjauncy Usk. Yahion, “Pay Motwx: ts 2D onoy oh Sige NAP cath th: popaty rok aaslotvy=1 > Sb edgy bleu ondy GdyluIlvI= 0 —e Wredy > UEnov ue. wee * Exovp! Unarrchd Gwephr a a or , Mods canbe 0 bored oy Aboudy sip SF } nerd Fox one ducck — Gedy MEM Size 27k 13 int os§ [nvJEn = oye 24 a1 2 6 ee = 3 ° \ aay ; | | Pole - 3 Se > 2 2 ai = as 3 {2] [= | = =) Ie L GY trve & op dye bY st a = diondx G@mmk 4 at 50 ANE aad annie adj iP ond of IVI biw &) and @) Fer on aire eat gxobh - © oni ” Code: a ee = sire CornpQesty > 0 Cm) Cimons? \ Spou Compr-rity 20 Cr) int adj fred Cen"? | “a4 for Cintizo >) * \ (sty ‘ int u,v \ Ce yurY Go CUItvI =! ‘oc TvITu3 =! ae x required Bor: divectd grabhPP fd) st Ligh (doko Crnppace] This is node - based vepretentation . Ut associont moda ceanre ith 06h G ist F pode adjoant up tt To Citak Aelf Lk » Crea Grvay A type Vector g dye ny Bow 4 bem Vector cin\y aj ies s ees. pany) } > Fuerg tele Containing empty vectn Exornptt onasrect gxobt [S\ ene gL stores 91 S48 12 23 @ > $37 nas ret hbo ar 12548 In Gry Ordy. a Bias as nods 4 os ocyoust 9G] —* 23,9 Petey sn, YY 2 3 ona S oot 4d Co | int rm ears = TN ; i 5 gn UG + each echyt dato Opper ne fain. 58 | Spa TERS fy rep OF Nadioucica, O00" > yo Ne aioe S we fox Cizo ef int wy \ Spaw Comptenity ! axe Time Compre cine? ¥ oatjfvr. push: be ay [v}- posh pork (0)Y a x Xacqund bee eae Ke \ 2 Wwoghia “cuophcpunentaton instead } Siovng ~ + _ Stove the Lig Fox ady Modan ® ant OF cin DY aos Costes 7 4 Qods 4 CC woud) For oof List, St Poe C adja wnt? 7 adj Cm) vectyr epaw em, Exom ple : aoe ye 0 & oe orem On Os &) eddy wulgh* ieee@ ues et alo Ss) ak 0] San 4 ‘ bigs £493 ae | oe 0) Rh ¥ thee a ane > Fpclagect Vo yeti Sr Tapologicol dating , node U wit) olvoeys Gppton bit NOdsy) ib dhew & cirectel edye Brn nok U feos neti v [UAV‘fe on GREED Finally Stack Contos one 4 peo Son uohite (1 gt empty? ans. posh -botk C St 1p) 8" pop) — EEE Pee eee eet A. Sa —* OC Vv) & Griturion + OF Ror Belg Ms NS Fine wat inserting Sm nodes (nro Slocr Ghicr Compeition atroversaly AE Gx molwing SAY thaw LAr be NO Gar Lhe OPO SBrworth bat 105 Come Before inthe ovat ting as eutrgom dusty froveysel asic haut bétn inseriol | in th stack. on Pah thse 1 Epo sot i 02O-0O= Gece. |e 2 ie = — — — iy 3 Gor PONT Ply CD Pash Sw 4 Peck ce é Rm @ Dtratvely y pep Gnode fsem que hits (14. empty) § Ged Ht suit, ANd diamant Now = 4. hwrt 0 © PaaS ema ayatine padi: 4: pope) ; @. = BONG Ne Indegya ECO Oo ‘ons -push-bock ( nes ~ SDI fo Cours i > adjtnedd) £ > pa (Oa Koh torte ) S We ned arty to Str indeqre oh, im inaegne {vd> £03 Al node er (fz to v OE ‘ fer Coutn ot: adj tis )f 6 3g Indagner Tita 4+ Ber every nou 03 Vv qusus cin > 4 NO A incoming edys Rick. Mare 0. purr cnrocs wath otodigre) ya PEDO Into quits vectys col? ona: v2 oa 72 aa © Eo =Acpile a ea : ea Que, 7 ae 6. Gea ee Dist Arca: OmiNatige Laity Ott valux te initoly| METESINY Git Cuan) ae 4 Ghd Sopa" C2 © —~ at [S32 6 aaaligo:s foo ey O 4. Posh Sovve nods into PA ith — Jone (1a Bae) ast = repo: Stam its distonce os 0 oe 2. for every nod ot top of PQ), took rf fo ot Pinion aistonc Bron Seo + 3 fog (Sf) UN fea oy ; ' 2 6 x Pate Sov, Frown (2) wt con ech eg PO FAs, mead F - © Cow ont Ge ~~ — 6) with ais OF6 = E 62, 13; bret) pep ‘ os } fer03 a) pop 12,13 oO With is OA aE ‘ae Frm @) ox con Kerr = © 343 = & (ur Conmech 2 of Cost 0) 6 Grete O a rap Tad oer NS) 3 4h +4 (Ue tate non fearon °)) wa coho tek oN ee Updoh MWS" 6a geen ae ouput + [4] eo ott heppe 4 ee Diykehia’s Algo + % vaVd or yg cydes — Usny? bea (Gempe) = Corn tether y dou to oe Bye! _= “WUSIn« Set in C++ SL Sek cparveintyamey> SE a ee Wad PARTUTa ast rode fom} Ute civ GE Cv, Sram) a RMP cease cia) yi it cing Ste St inven (10/83) if using «a O% Ber Stow in Solha oder - os Pon oe e bone Clg -ametyo) 7 A i : \ = , Only a, bio PA and Stk ts thot 9 node > (« st begin) + Setonch O Ged Use con get sh Mhume Exists & pay coith os > . unt « fort node tog guaiw diskna than aseps St evere (it) PH pooprps Co 5 Gy thine Cuill REND point tn Raping Shak noi into ft. 40 feniours \ + asi Unetia 4 GA siMipdy Autele the errant. % Ve NCI ,w at q EE OUST Ze Dies edie a eee te TC Of Vx (pop + Cadjoann « posh)) Come) ih (os+ wo % aetui)e # Of Wr Clog trepsize + (HEX oye Mole White M% Cais Td 12 Ine { atv (C4) + CW ay 7 Le Gate * St chu [ate o( v2 K 09 Chop vy) Orstly} ogra o (VT 2) Fa 5 > 3 sense cont 9) oC E *2 Iv) e pees Posday SerEe no: hedge Vor no re [ Fines Ayu Sharkst path obo nodts BE Galivon fea, Aarti Cf ane To 0 CE Ig v) m di4o (t+v) ~~ eae Alpe a ~ Con Hore ntgotive Cyclo: 5 Only apotabee Yor nee ~~ Dijksvo +x hondte ney tdgy Kreger snobs a ; Sg onply ante ge meng rob ~ ~ hi Uh: Convert Seb 8 iD nee ae me ROX otlthe edges Bor Ne) nus O= Ones aD NG me KWKalyy AB NA Ama, Coe Chole Oe ovr Tinting ed the A’ghance ty curry Nod 2 -- 2 m * Lthet is Rayan tel ; a OF wot —= (9 Consider this gychh with dist ToT , dist tvs ond aie porcachn node U «node ¥ Ositel Shovtet dAistona TES ick ~~ ~__ Dist Iv} YH dist tov As con be fe (distTols ut) isgmaner thon fas cai This pwcess Supdokny ch v through UD ft dishance is Coneck . es the Se\Oxat and eH re ee oo need exoct NA itvations? AL Ast Heaton — 7 4 3 ‘ical igh [2d wilt Be iC } (a) (ast09 3) Update t a! Aistey +1 Ind Hey cin Aeveron).) ON So One is Loe need totol 4 The Aist [3] 44 2 dist [4] {ueltvay ates minima, ade dat [p44 : LPGOFE Me Volar G didtTy] with disttoI4e . . > = , , } , Phos + “detect “ngotve ele in ty gph pce fo ous intuition , we should four minirnzed oll thu didtarces Loita sey Wel + 610 S10 KAHN Ts Poss i oe) Nel teerit ons Comeane fhe ae Chal t exetna ru ee 5 Use Lait Khon, ‘ya ons mov hms ohter Compestion & 10-1 pape eg ood toate 0% Hobe Awd ah rages " Wt Con cont> Boone possi be: “1 Da are on’ tor Loute it: edge) ! = vo eile V2 Ud es i Pr, OC * E) ij (ast UI $> Sntmex ond une ait THD) € dist TOI Se | 6 Cv) nodt St ye hem 4 no ‘ 5 on a es Vom a a 3 yd Warshall ies ed pre Shortest path BIW coy axShall A) nnn T ar oye Eres): Hyer c paivoh vawes * pace . Pens is) 2 tought i} eg oo , one ae | si Matrix [sity = 1 iB mo edge - Floyd uooxghe yo tH ~ S00", 9/P ae igiine 2 s.7! shavtst poth obgo and. it ; mies * Go Sct | Acres eels rag oh 06 go gay Beery he), -! af) 0 =! os cout i, ae. 3 5 4 ©} rad do Check evry possibe ath Jong vt jl * Ciro! martvic stoving Sion A aa each pascibte Distanus . Fe, mattiits) stovtny = Shostst cistana Bure ites = toe nad to Bin Shervtat path blvd ie ond = MF or i path vie OW nods (o>!) =6 we™ (6 32> ef ve? (9 2 347") 25 : wi ore Binding the Shorts E cia (034+ a eaiied amin fe oa 145 geiny, “euayy pessh& Bw 1 (927 «(q-8) mul * i (Gamo ) Patnx CIE = min (motte II, imatexd ly ame +motniT KITS] “a A> Sour : J dustnoten K > 90d ie, cn Oe Mahi Bem ito} +«A “prrong ot Pp 4s dis Ont | mst & Pe gycbh aw Q—-* = ecky. aught Vere DID i> Dan's Bigositnre [Usa to Bt cast en Soro AYLI? ee mst] | Approach: Code uae ried 2G CUmin-twop) StoPg pee Petes gots Covel?) Rite Feayetd ond nosed Qe pa & Teint 7 ls Gd 9D) ae nd not only tt Sem sro po posh (20 03) ost fedgrWdy adj nod pant node} Int som =O avis array, Som =o? MET GrESGy Fo shite CPA empryo) t srw ‘ @ posh to 0.2» pa be S ppea = pa pO WED Re - ©) \ nous 9 PA dap Second rarer en. Bop, ou cmt Pmm Pane (PO Check i we Docs vie Contin LO [node], (Sai Pete ne etamane & not vei TA ak 1% v vie trode) 2 + . Hun mork a) sit 9 cdo Wegrt * ree eon Can om Bom Gnd Site Lpourtond corr nods} 1” for Cours HE , Yass frodt) ® Oa int at CODE ae Tho FX every Ady Node 7b gnvisifh ie? Qe nee Ste th PQ ip Cvs TL aay rot) £ 3) oS em eet pq posh (1edto pk most E teratOrs a) bec Yim SO a Anduttton §— gntuiton ob this Glge tre yeas Heh nique usd oe £03 Carn ply! Disjont Ser tnt nd § ntti) is poxnt DONR-VeEsiZe CA, 0) © Pavent [J =|Oerent *) ginek, Pont vesige( At) Sty kp Porent (7 = Union equines too nodts [U ond v), tun 2 we Lill Bind UHimot porent, 4, oondy - if ) U > PU conch vcr PY Find he verkk \ york? Cost Tel Boxe) “Pewe fume 7g pocndpy, ( PM Gh Powe porn | for (iso 40 a, { bry word . unenbyhae a oy iY) pu = bind Pox vd pv tind Pcs wv) = Finally, Cemmect Ulmer pent with & Smaller yank co othr Olmak parent Lith @ ager von I i } | Gf vonRs axe equal , Wt Con Lerbeece Sp) = Connect any pownt te YWevcase thevank by one for te porrb nos Poxnt [ Pol =pV seve one «{ te canom ux hour Cone eck OFF ale iy (von Tuy c Krk 16 a — Citi boty OH mats Parent 2 2 ‘hoo tea sot a Ee ChUCP From Yht hove Porte cnet poyent v3 = pv thn ond @) belongs \ sonk [pu s+ to ih) Component asthe paint } ‘ 3 Se ox cl. aan —__—_— Frativohy we find Oipmer ? { ge {nk rd OPov( ant noes) f ‘omen, sorta for ©) ord @ a re I} (node == porn Crag Gf we find Upannt osing wcorsion qecch is ocagcnee nin quiry y if esi) end op tohing oClog Md TC But cre reed Constant time. fo use| Ue fosh Pathe Comp ress on. ie Actel TC & Oncerby tank \ \ (pornt nod); Ona nd UPOK() wv OCHA) Connecting each hode in apartcolay poth ap cone m vy Bly Smon & clow WS Obie Parent ‘xckos to path Compras on 2) poe. — 9 tog, mativmetiah YD) Corsten woo. Zemprenon imme. 4 $0? io at @ Hey © un Great Chyiny Yank, dung path Oe - ~ grpmih Prd Pay: ry Ounruony | = (Exorn® )abo neda se spout [nods I satin the Noh + omnt node dol. aa Es 4 bind port 4 0 hee © Gnd Uohile Rachie ac fine will UP! SC RepoHNe w, Curr nod eaitlh wend VGtuy conse york) (Prop Drs eo { ne y {connecting a C do Smoliey 5 2 " a) ey @ em tore) (' € 4 © Apex applying path comprcsion the xn gf eee cha gehhs becomes distorted: veers How (0 ond @* Rotney than Stang) 1 LHe Con Stave the She: Void Onionby size (ovD§ Se Ones 5 She. : ind UPOICY) Herve ux nud o oige crroy not yorRUI. A 5 Tinea is + Shwng the sige Q, @ pentieex node vy = $— SBTID> sige 4 component Yum a Csi Lpvde stye TOVIE Tnitvoliged sith +, Mods { pow Uta Py DP (weit Connect th Ulfimat povent che (Oa Lath G Srnalley size to the oti - UlHined porte cuit. & Gorges Si3e » Gur % tte Spe & MH too is epuek | y UL Con Connect ang porxnt t 4 Hu othey parent. > Incvement the Sige Q whom other Companorst is Connectcl ,sagen? Gitta Conbig- Gal Conk patie Soy pe a onion 01 ee © @ a fe renee we = tise & oS as bat ww (0) 4603 =. nl ie Qg 643 A, ree site : a8 Sl re aa (a) she) fel ae) eo (EE LEED pon Be Krusee OT Ted MST oy Sm 8 Se ve Kouskol's Algotnye [To pnd MST oF Re Ki 3 Aigonty yecty Pate oRe gm LB oS Conneckd (amponent - Kasaxaos Alanine —® pe — O=@) Oy SKC Gre Net Hochobec sy [fA Co a, we shat DES bom Gooree o- r J} Mow Ls con't move Inter } eee ad Bern seca oe geca- +. but Ce TCon eRe aaa SCC4 a S SCC 3 te SU my 5 : Bb Gov Sore node (0) Ge im SECH, LHC Again tnd OP UBiFinget $4 » aS BeWOdINS To Sole this UX Four te Sort aM hy YOIG 6p the basis 4 Muely Boishins time.9, 06s = ean] ab als 3 Beh OS SAN A, Ya ive Oso Se Q =) Conupt §, Stat ano finish tim) pusends Binish tim) yates ip . > ~ MP oy $465 3,021 § Mo oe =~ Now ma hi a 3 AY “A z - ae eee ate in [some flys o Taposod OFS} my AIPP¥OACh * (ods EST. capestna tal VEO Y UE (YO), adtach cint? SE TL. Work al\ the hodss actordiNy, = they Finish time ox Chee o. Pea iets erty pengeet aa TH Cow lis) Eazsidiy vise 8 st B at ‘ Syetbh iv Vector Cinty wu- OOH) vy exfevn OFS cind Counl tne for Cizo to v)h =, no: 4 AdE DFS Cours to get Th vo [i320 © » te $ cs tor Cauto it! aay C0) * oO ee: ed oS Mane 4 «push -batk CL e 10. o(vtt) DDFS 7 Revewe. Lr sce

You might also like