Download as pdf
Download as pdf
You are on page 1of 23
GREEDY METHOD Kmap4ack problem, Ta, Such tutth cleoclenes . cy a +> Minimo Cost nniong, E002, A Pitinas Amel eek U Bthon8. > Am opimol Ranelomized Alps. — optimal ae potlerns. eer Shale Sorte Ghérlest path- STNrRo buction: =) hs Method ira Stam ht frucond method and Ona. of the appSoach ff Shitga Porohlem. 7 Goaedy riettod 1 also krewm 08 Optimtyetion C&A) bininn?- tion poobem. 3 & > Oplimtpation pirohlam 8 rothire bub tub Stoquiras ether Minimum Steet (8) Maxtmuen C&L. sell. => Optionzadon porolaen gues a Solution S 2 called Opttorizeion liction (8) MéEntmol Solutton, > Gnthe gresy Mathed Cut Cam flnd out suumber of Auctions, , ftom there Slutfons ture Cm Sell only, feasible Slotiong > The ee Methed ts alo Known a Selection Probdeoe poollam eat FEASIBLE SoLTiON: Fa Silay a portals problem | thw Gals“? Inpuls dred the ruad to offen Sulpels “Ther Sulgel- thal Sofiz-fios Phase Gt 8 Called -feoaialla Solution. s OpTINAL SOLUTION: Fam a Gt of fensifle Gluliors, portiaslos Glubion that Sdisfios resol. Selsey the ofjectine function Such a Dation £2 Glllad optimal Button. : OBJECTIVE FUNeTION: A foasttla lution thal oth af raclted «hen us till Mantmizes 8 taiaieriy & giuen function 2 Called! Olfectia fonction: GENERAL METHOD / ABSTRACTION METHOD: AlGoritin: Biithrn A @ Grady. (am) < Solution = 04 a [es fafos]ays] : +s far f=Q10n do x= Slutin @); if Feast (solution, 2) ten lle c= tiynton (solution, 5 t Stahim Salton f ' ie Mothed following actislion wo perf Pred. 4. pak wo Select Boma Sclubiora fom Input domdin. 2. The tua check eubectir the Sdlubin t2 feasitla H rot 5. cham the Sot of femifle. Slabs, Partulr Sutton thal "Sibafan racy Salifs te cacti of the foro Such Gadin £ Called optimal Sludfon. A oe Prcbied ie Jn Slages «Al each She I oe Tnpul fa Comgdepad oat Cath time. Based on Tnpul 2% clocted eshothen poorbiuleh Snpub giuss te cpttrral Slubion Fi mol» , -KNAPSAcK PROBLEM: (> Rraptock 22 Nothing bub BAG» > Kraptack prroblom i abo Known 0 Contatass pron: St ? Kno poole 2 ali krowm a3 oon knapsack proflem — 0 (2610) Sapsiente Jem 2 rot CGmidlerable 4 wb, Hom £ Qnitdbofle. > The kroptatk plollim Gn be Slaled 08, fells: Suppose thew O2n cigels fron feb ee=n- ach ere Some postive Bik ty and Some. perfil 2% arsecabod tuith ca object cahich ts clonofed ee Thi knapsack Gy. ab mbt a We Lee Slog. alout menhtrad knapsack prdblem we haus tha. . s the Capote. Gmtnamnb, Bhan tat, TD Sit Problem re fee appsroach oe hy 1. deo oe Cages, tae ghia Maxhmum prof An The. total taeight of Sebecbd olgect should be 4 W- And then tua Cam oldatn tha. Sd of foastle Solutinss a , larimized Z Pp. geck-t > LX Now Splubions are 2), %2,%3, X%y Ag % SUF xp £8 tn bebumn O44 fe O42; ope erate i > Accteling to PRatE sake rothed cua./Contiden Mathie element 4S Ges - ‘ + Now odd 1'q +o the Krepsock Hent xgel, He 4 Boa Capcity da 14 Ng > Now add 214 te the Knopsack Hente x21, the pee sy: Pe Ce ae ekg => Now add Aig to ths. Kmapsoce Hen xg=1, the at geet ae 7 New adt Sts do He fmaplack Henle 5°), the Tet ee Cort aky 7 Now ads a to tha knapsack Henta ee aia Bap Gos Ake ey) —> Now add objahg 3kg to tha Krapsack Hena’ 44 a Gog Gpacly. Org ie We Garnot act ol peck 4 hecaure bog Conctaiins, 15K bite Hen %4-0 > Dy = Wi% PDK +2 +b Hy Xe + Hg Xs ™ Weg xe + Ha % = axl 43x +50 AKO wt ae 2 Q+Qarsrotit4tl = 8 DZ w;X; 4 15 2 15 Bier seh Mite BRS FBX FRX t Porth X +R XE = 1OX) FEXZ 445 I+ FXO + OXIFIE* + 3X) = (DF333+15+0 +6 F183 er 55:3 Hera the Optra Solution 2g Cxy/15,23, Ay tS, Oty ) = ic ey i) Ond the Maximum povafit B 55.3 ALGORITHM: Algetn Greedy kNAPSACK CP, HM) : fh (i= Iton) do i X[*] =0-0 oo LE CWO] >t) thon Bowaks oy XCi]= 10; Me m-WOid é if Cié=0n )then xc) = Yas ie NOTE: The time Complartty, fo the ate: Krapsack £2 Ot). MINIMUM COST SPANNING TREE: SPANNING TREES: ; SA Sporeteg. toe of a pr Gz (ye) Baa Subgeph of G that 280 toa and Contains all Ho Lértias of 6 Contatns No Grcutt = A> Eche of the Spa ong 4900 £4 Called a Boanch. > An Figo tn the 9%aph that i Nok fn tha Spamnin tn00 tia wal ¢ PROPERTIES OF SPANNING TREE: 4. The be Seural prbatmunn Sa en San. Heat Houtng tha rinémum Numlen of Eckees & Ge all to ee ofa fem qr coe tha Soma, hon Eig Gooing. at of thak geuph 23 rtaimunn. 3 GE Back Ee Hao. bstiret aaadpit thon Ahcta Ul be One, unique Minin Sparming 1800+ 4. A Grnoclod & Gn 4 meet, mre 6 5- A dislonracted geph Can't Howe 1 Spanthe doxoo, tt Gn't Span oll Ho \oortizes. 6 Gat “ax chew! Corin ees. yt ene Tae Hos, Crt) Edges ie ee to of Verrtitos,« EX: al 4 ee eed CRE= 540+ aul SHH) C&lestioty CAE Adzolent Minimurn cuaghk ths the pSotadiee ta Cortana Undill all the —> ihn Ex: > Sep4: Tndalle the tolal eihk JA‘o? Slep2: Mentify bash oxi athe Now the total ait us O45 25 (8) 5 (©) Sleek! lnlefy “Neat least astotnt waht ede @ 6 Noto the total woight is oe: O+5té =n ©) Sepa: Tdonlify eit loosk euighted ese 1 © R Now te folol CH tg © © 5464 = Q2. ©) Gentile noxt look ce @) Now te foto! cat % St6+V +16 = 3& ©) Tent. nant (ast Gael eve @\—*—8). . Now the tofal ca} ts ©) IS ©) SHE HEHE = 56 Oo o. The total Cat % _56. ALGoRITHM: Algsitien Poem (e, cabin? a Ck) beam abe of reintnuen CA dm E 5 minced = CAt Tk 215 tiie=k; tpor-4 fi Ci =1ton do *f CoBL Cr) < CALLE KY) then roca T= Ls else ron [1]=k; wan [kJ = mone ]= 05 fir f=2 ton-) do lalenj Levan’ fedex Wahab gun eT er oraes CAL Ti, naofs]] ts rents EG 5 3 t Ui27 = wally mintdt = mintdl + cat [}, world]; yao [5] = 07 +H k=l 4on do £ C(maor [K]F0) and CE [e, noon ET] > ht TeiJ) tam ra0% [kJ =S ; g Hethim min cdb ; | oe Complnety = Ol) « Oley KRUSKALS ALGoRiTHH: > Tra Kouskals alosicthm alos ta. (inimunn CE Edge | { { Ir hos tbe Solocked, { a) eh ree naan thet Selvctad ptt Se ( adjownt. ( > Mh thes Ha pouticson te Condinuad embtl olf wantin 02 Comoctad cutthaut fining Gyles \ U { \ 7 SEE! Gly to teal wast 2 'yo0” SHep2: — Gdankefy Mintmiem Cat ee fom the Graph G) y Total, waighh = O+10=10 © Step3: Ldantify Ténimum ce cat D Z : © Da 1 tel ape: " = OFl0+!) = A} @) Step4: GderhSy tinier edie cat © 10, Bi 6 Aht = OF lot D2 Teal uagt = OF» ® Steps: Sdn bify- Minas ede ae 0 @) ? aN Total waty it = OF lo +2 HY © ® @ = 44 i @) SE Gonlfy neal rivtmvm exe Tolal aa =O+ JOHN +12 +14-+ 20 = 6% OFIOF NAD $14420+23 = 40 The Ménémun sfrrntis tose = 40 AlGoRITHH: Algbiithn Kewskal CE bn.) £ Covstowel a. Heap oul of the oa Cos usted. Heop2t45 $e tet-tom do pownt Ti] =-% f 20; mémcat = 0-05 bt (Ctem-1) and CHeap not emply)) lo { Delefe a minimum C&L eae (uw) from the Heap ancl J haope tate Adbpuats J= Find (u) 5 k= Find (VU); if G7#K) ton Pe FH; [iJ {ln Shah Syowe Shortest path poplar the short dlistanta -foiema Strato Velox Collad Sooro % oftotnadl. > G(VE) bea uph, them 4m Stile Soin shoal poth te shabest poths fom Verlox Vb 4p alll penis Verdex Te dlabisnminad. The Vérler v4 te thon Called as Soa and tHe lat Vortex % Cale captor > Lh attumed that all the clube olislancos oe Pésitine. EX: tua wll Slomt foro Quee Verdex 4 . Hence Spy=) Now shirlest dlistante fiom Veter d t10. he 19 Hen. {1,25 ancl Mea = 10 a Prom Veer 2. te mont vertex Choten ts 3 qe fat =m fists tish= co fy, Regt £1,2,33 = 30 yeas $1,24 $ = $125} =o $12,6} = 2 Henw Soloct 3 S(3] =1 Now £128 44 = 45 $5,23)S4a= 35 £2,364 = 0 £12,345 = 2 Hento Soloct wort wrter a 5 SCJ =I Now £23,564 = 4.25 Sophy ae 2. -. 2 4 4 4 2 4 4 4 4.64 Heme F tutll be Selocked» Pn Sool S de Path f dushimation Verlex 2 4 Hem we — Shalest path p72 73959 tat path lamoth AQ» The Siege Soo. Stet path rom Gy ch A Sienien on elliee a ie torte ts 172 =30 43293 = 10+20¢ =30 123-44 = [o+204 15 = 45 132-35 = l0+20+5 = 35 1 2-43-5 40F = J04 204164920 65 1523545 = j0+204 St 25% 192339544 = l0t2015+# =42 146 = 2% 1-634 =65 L&ORTHN : Algitthm Shértest potha Cv, cork, dak n) t ta taiton do { SU] = Fables aut] = c&k Lyi]; SW] = tue 5 dish [vy = 0.0; Sh mw = 24 do Chote U from among. thate Loris rob tS Such that list (uJ £2 mbmimm 5 STU = duos Fh Cash w adyocert tou with Sis] = Foleo iat “if Cosh Tod > dak Da] + ct De ai eanen dist [wy = dat bd + cat Lute] id f ANALYSIS: ae Conplanty of te ab vn > The 15 f-tcop clay. donor OC) Heme = Checking q tates O(n) time , because 4 Amvelus Firdlng a. Minimurs Son Am arth es > The Drmasrmadt ff loop for ate Det Here = ab Hat 1 Himes, thus foxes Om) bine = > Thow-fte , tte ep torading our voltarer O (nen) Hine Toa, Stele Saou shoteat Pet shakes Ont) Erna « 5 SUR ! - £ d nana. a2 &2 2 2 2 2 2 OpnHaAl (MERGE PATTERNS* Ee ae abvaady tho gpusn list of Clements ava £, ae biden Ex: Usk A Grlains 4-elomnk 3 5 #9 list B Cordoink 4. cleminks 2 4 & Il > Now “¢ A and B wR ie 5 sea Ce 2 eae a 5: i 5 0. (em) Wie an 4 8 Tha Steof He labs i 444-8 > In too - EG Mee rege Roald fy Cates az a 2 Howe Mitethan hoo Lele thon ma. > Use techn? Oe ae Cong Ne Ex: Tho. gem Libs cove ABCD and tk Ctoapding oe @) () G+ li+20 = 40 @) +14+20= 45 G @2) * Hente tha tintin C&t Optimal Solution J2_4o_ eX =A To genrole Optimal eee Mothed Prebrroclute “tho dgramte prsplom Js Called “optimal fe D Fie: pester EX: To find -totol ae ere Puller -f the following lithe yO 20 30 10 5S 30 > alfiuen [Bb role Aap ta eagle 2OP EOF RT 5) SY 3 ie te ajous Sysco fn Inésasting Adon. Sh 10) 8d ~ So aeG Arne wietne Caching en) @) % 30 30 > felonies 3D 30 2 eo the afour Shoe a2 bn ee 30 30 35 ‘ Ond 7 Si are eat ay a) Ee Gd 35 3 Arsene tha aff Sire ta Fntvantig Be1 35 60 a Aare ae 4n 35 60 ~ total CAL a 15+35+60 +90 = Qos “Total cot = 15+ 35460 +95 BXS + 3x1l04+2X 20 + 2X3) +230 = I5+0+40+4+60+ 6d = 205 ALHORITHM: er tee yatodtd £ | ! Alahithm To20.n) : Asaanoda +e Lchild 5 Se 1 Paomoda # yehild 5 : ne fi f21 ton-1 do : dolagen ad 5 iets Ros new faonode 5 (PE-Qchild ) = boost Clst) (Pt Feleld) = Coast Cla (pt- capi) = ((Gt— acts) west) + (Gt dats eoght) ; Sracrl Cl, pls Sth (oat (lest); f Analysis: Ot oe doe get velue a te Sls Hn la CE) Begins, OG) Had ate Cam be 7 Oln) Hime» Heme total as list & supa 0b & lnayp tn cath the Stool Veluo 48 (or trom & equol totua Value of Pe Chelcian than least CUsh) and Drrent Crt, b) Om bon. Oe) Tn ce the Computing Homa for Tae 2 “0 z Olle se

You might also like