Download as pdf
Download as pdf
You are on page 1of 8
BSA ASSIGNMENT 4 "| ALGORITHM : dune ihe pout rmmbur as Low sand the tart mumbo as bak | ji) Take Me middle oluwunt (con any elument) as pivot. UID woeen Yous Jn lars Han Leigh , uv cLumonb ab pi. (pivet) Hs ok tw night porikion . ) Repeat WAL Hees (SUtve) fet hu arrays , one prom *honk te pi-1 and the then pum piss te wd - $f tu condition is not sakispied duning trowenal, ‘Jawap dium, ot" continue. Vi) The beyt bound jv moved te sight auctil it seached a volun greater than or equal, te pivot - EXEQUTION: og ee kb Te T TPivot | ] i \ plolalepa fe jw fr papt fa | TT | vight| pivot ‘ti 2/1 @}si2}wo)/t1)/3 | 4 4) Ss = oo adi pi jot TST Pe | afzfolr7fs.a) bls es rial | hpiver ala |i PS fi jwls 3 a & an — , vigheftept | r | [prvod e}a2]r |'3 |y2 | lo 7 81 q 6 5 . | __Praee a - 4 )2t1]3 }|3 | 5 | 0 | 7 8 | 49 6 12 i HVvOe T T 14 | 2 na 3|3 5 | 0 | 71 e|49 6 | 2 Scanned with CamScanner GO tei2tta) F ae rs oor : i \, 3 5 4 7 |e |4 6 a CrrrC—CS Saige 6 12 Bearscuce afete tee t—T yal 4 38 | 9 6 12 | 2 4 3. | 3 lope [2 | i a oo C222 af — Fiver] 12 ri 2 3)3 44 & [pire 4+—|—+ a 1 2/3|3|4 al 7 Tight] jive E : g f [2 1 2 | 3 3 + La TINT] 7 [a |-s [vt ine 1p? 7/2] ||? 1 {2,3 ]%) 1 rf2|/o/ | aisle} 7 eal el” | Divide she asetay inte groups o% 2 Vii) Sot the groups and neere thovt medians in an med CJ, seounively call . iD Qe med20J os porction ( medfo... size 1] te size Wy) Apply pantition. alporuthm jor medalJ and stor Ub ab x- VG, 27k , subir med2 Wop x>k, rehwnr junction (anr[l..pI,K), p= x-4 Wy Sf xck, rebwur portion ( wor [rett,.- pe eee ] - Aton | Scanned with CamScanner 3) BST : b,2/1,8, 3,5, 10,7, 3, Vbre 12 Trt 7 Scanned with CamScanner | TOPOLOGICAL SORT: Sn any diced graph , tnar i» oyiic , Wor onduuirg a Linear ordowng of its vers yd that din edad 1dge un yrorn u tev, w come beers v in ovduing EXAMPLE = Cownidin 0 job unth’ to ares with pnocedince sues - Mut waeqin with 7,5, 4 er 4 Tork 1 ahowld tellow 7 Tavs 3 ond & must yellow both 1 and 5 8 mvt follow boy | mut potlow 4 lo uk fellow 2. ALGORITHM + | Owake an umphy linked ut 2. De Depkn Fwut Sort (DFS) on Bu graph 9. whenever a. node i» completily visited , odd ik te “lhe bop eo the nud Aut Scanned with CamScanner 2 3 4 5 ° oO oo 00 | ° O oO & TH v2 _ | bo 8930 =—100 V2, 0 lo 50 30 40 W274,3 | o 10 50 30 $80 24,25 | oO 10 50 30 b0 6. nae 3B F | Kruskal : Cet woe! Eps2 CA=2 | AB=3 AE=4h EF>4 DB=5 BFFG aDd=6 Scanned with CamScanner 6.)ALGIORITHM FOR KRVSKAL METHOD: KWON vols . nun ; : 2. Add an edge to the graph im the asancdurg orden Af. Ak dow wot yom a ye: 3. Th we edge sors o ayche, tun don't add ik, ko Map next & : Ne 4 Repeat thin sacll alk edges ww coved. | Scanned with CamScanner 2 _ Pr e S ths jure mabictd AzTa b) and Befe f tame wor macs TS GY od TG] Jrromon's method : Tn vermal duvide and conquer mettaod , dae number 9 acuive calla in 8 buk im ptransen's wullod Aue number of suonnve calls M7 i) Die te “quven vnatvices of nit nave Nx No Ti) Find HAL vols o% Peay 7/5,t, W/V by MME” de formula, P= (atd )Cerh) y= Erde yea(t-h) g-c (4-2) tz(ath)h us (c-4&) (et+f) ve (b-a) (9th) ii Cotoulab i,j kil by wong the foumula, te pts-ttV , jerre, keats, b= ptr-4tu iv) the plmudtawk matrix do [i 1] eo Scanned with CamScanner how vaddition and mubtradin take o(n?). Tw ae 1 coluwlabions of Ny mabuce _ N= 11(N2) + 0(NY By marten's there, rin) = O(a *#7): on? 9 8 Gnatdly algorithm yor knapsack problem: Bort Ane dtertt bared on VObUL of soch item weit 1) Add ane item with maximum valu ono by one : : q iii) when momaining capacity ip lux than the, wovrent volute thon add os much as powible- weight | Copacity. 6 batk = 90 weight % objecta = $40, 30, G, 36, 8010/25 4 | Value / Prope = = $200 4 50, 100, 300, 600,550 ,2504 | Rabi % prspt 295, 15, 1.33, 857, TS) 55/104 : Prvogit weight | B5XI0 = 550 10 lo+30 = 49 550+ 450= 1000 pras =65 550+450+ 300 = 1300 5 = 90 550+450 +300 +Q5xe5D = 7 ot sory) [1464-255 Scanned with CamScanner

You might also like