You are on page 1of 19
nenent =F at Discuss the pyre » pul b) revue -orelered inp Bt st (ar, low hregh) A ssi evithm For Mang uh =) sorted Jin 4 f Herc Gt ase nee Y (arr ,midt! high) 4¢ 2 Lowe, rial Migh) 5 merg € (arr, low, middle, high) hi gh- mnicttle crealé aways t[\.0n] and ef. 024i) for iso te mt Ui} = am Clow + 1] Poe ize: oigees RL} = ar[mickdle +545] 0 jr0; k= loa; while tent and jane if ura <= et an(e) = Ui) 5 deme, tee; laelj else omtk) = ety) 5+ey asl) while Tent ane) = UI; f4ely K4eh ushile jane an k)= GI; Teelj key f : hav a tulal oh Diteany compan ti 1,3 ot, it wilt be Bhivieded: Fist atunend 9 fel Ust 4 UL camel g will “be compared to all elements itl on Hence ad loved We hawee have twe n/y tomparisons ond s on. gaia wrison ushich is the best cose b) Reverse-order input Th the array is veveisedl, al each Level hich means & tolal & nloga maxieum and H is Considered o ©) Random input For yandorn inp also we need Candas va re way fall io one 8 the depending on the brder @ the oumbers fone platy a merge Sort vill be +) Explain Quichsort olen ta Ahe Lol Derive exprevion tor overage, Ars Given array 10, 26, 1090) 19 9077 low <0, high=6 Prot ~ aarfhigh] = 7° Ts tow-1 = 7 From jp low 42 Wight SS jo ince canfjl <= pm // ts 145 one | \ r rCf7 > pet cle ) f lo fey ened op Cam (i, arta) nethin g 4 xer(J iy 104 anny, 9 40,10, 80,5048 5 gz pivot da ae 7 (anti f + and swap t=3 - Qrr(J =} 10, 40,40, 50, 96,90, 70F rd 50 hoe come out @ loop Decale) jaigunan Finall, we place Pivot at correct position con (hit h} (or ptvot) oss) = § 10,30, 40 )SO , 10,99, 10§ $0 ard Fo are swapped 10 is af ils correct position All t realer the Now po aio quick fort is formed and 99 "9 Ht esi % pivot - as. coro ee a will take ‘place these 1S yer el sebard an) = {90,304 4 ,brgh=s, prot + areLhl and all elements loc = “Tewerse elements from j= le jeu: Since arn ~ pivot de tog: al] = {80,905 [/s@p 80 and 40 to Since je hi =f loop tern arr (J = $10, 30) 40, 50: kSert eneral; con bes extthen om Hk) TE -k-t) OCD t lerments hich ode Seneliler thei prvat mast case’ | us when the parties proces: 6 t element as pivot ies Saamet i, sorled in increasiog) Ge gaenamaas 4 9g a To) 4 T(p-1) + Bn) | tuivalen! +o b Tin!) + tn) Best case bes! the midadlt lerr TUn aT (mfr) + OLN) the solction + above Heeunnence rk Case: We can a an. idea ED case Shen the partition: pub O(mj9) elerne elements in other Se TWH) = Tlo/9) +Tenfio) + Ste 3) What is a Minimum-Cest Sposning the mie and show the Hare edges call the vertices together wothout 4olal edge weit i Cas is, tt i is as ode as posse The seb moh! is initis vertices are 4 0,INFsINE;IN tet us pick 1 05 slavt keyvalues % adjacent! v laid as 99 and 10 a 8 oT black minienusr value ond fet ale und ackled 9 mst eh Upsede rep : Ww mstSel - $165 | vertex 3 has minimum value and | Vertes 2 has eee | % pick vertex 9 ard | ucle Vester 4 . the mstSe) Confeuneennenia the -Anioin um oe dace is oblained ost the MoT a 4 STS 10425 +93 +125 yaa ee 1) Find on optimal solution 4 the knapsauk Insleneel Cpt, pays pt) = G0, 5,15,3, 6, 19,3) and Cor, ay 91) Ans - Steps To find preftlisdat ratio ofa =5 s]s- re7 is/s 23 F/o = 16 + 6fi =6 » lefy=ds xf 4 Skepa: trrange this propitse ie resto. Since highest Aleta ratio Ms G: highest Sroft |werqht resin fe S” teh PUGS a Order = (55108, 3,44) Steps: To find optical solution usi Consider 5 =) potl-s 2121 profit s10 we uptil now = tara=3 Consides x62!) proht 18 Total wag! = 3499 | elher v1 Concer #521 ae Congidat * Tlie } ee eh Total prop = wise’ ye a more onthe ne L+ 333 +558 he ophnal solution 4hed gies mostmam pept Ch %5 bo, uu17 10) Explain the Sie. le Source Shovtest path yeh i ete Ad A al fe shorted: Path algorithey i all 4) vith is used irae nice fin distance 4 diipercore butwesn dai 0 Djksta's algesithm se Ganmenae we can handle 4” easilye ‘Bellman - Ford algesithm finds the dielanes tt finds Hose J slances which have tod ir x the path ee to tnd, li At gerithm npuk - “Distance list, predecessor lick anch 4 Odes Thue , hen a rege eye is ho Begin NiCount i= t MarEdge = 9 #4) Jo | oh vertices vo the tate | did[v] i: © Pred[v] is of Cone dis! [Source] += 0 eCoun! := Oumber ef edoes pee create edge tis! named le While icoun d, | Predfedgelistiyy | done | done | iCourl = iCounk +1 for all vertices i in th if abish feckep List x pt tre dislance 4p ne 4 verbces in the be proceed must ssed 1 the foltevsing erder( : € k ge the Follessincde oiietan Shes fave. The first 10.) shows intial fatAneaE (G6), (0,6), (9,0) and (85) ore ie . al a dipp erence” bedhioeen ipa Maoists, ay d >. yreenie a arom ing, : ed -cach bevel hepa bh {| Solves subproblems only ence Ond they Stores in the ‘totble. 13 Q Bolton, Up opprack 5) In this Subproblems ase hee ©) Dis more eppeciert » Fram ples ove hese modrie chain multiplication, optimal bina Salk dove r ¢ 2. Find the minimum no chain matrix ~~ us! A(Q0 ,Yo)* B(40,5)% C(5,1 Ans.| Me have 4 modrices A,%,0) 8 | The madi roullipli cation is | product is porenthesized ibe |fos the above four matrices, | (@sc7© = ((AtBe) 6) = | . we fist compute the AB = Qox4oxs x 4Ox'5) + 3000 +@oxIsxs) 0 + 3000 + 1500 4000 + 345 + @oxSx Ss) a( 8 (co) (Ce (coy) 335 + Uoxsxs) 4 (2ox4OR 534s Ce roatnix cnubkiplication 3) Whak are the drawbacks Wrepiosd si! Number 6p objects aaa, tOuahle fon Ca, paps PA) = He as ‘Drawbacks ise ‘Pog | Move eapertise 15 required i | other mmetheds - q usin | Dlaek oe ta algorithes ti Jcodes necessary Pes ineapensi | 3) the biggest prob is die | We ih partieatar appt codhon | problem fox computers | ‘ ‘ cial opal as @ 6 Iola propjl = 9 wd pa, ce get he el be los comparecl to 8 6nd BHR and OY yt +649 = ae ; Poh 24841 eH ' tuhon vill be Cel 4) function OBST to com, w(t, Fas for the iether set (ar,a2As, a4) = Ceoud yah PCD) =Ye, PC = Yio, PLY= ‘Yao , gene yee ard gta) = Yoo 9 ¥(1,Jj)'s construck wW(0,0) = W=e) v=q! be 12 (3) 2 98 = ae (4,4) = qu = ho wa wo) +424 p2 wt (1,2 + qa +p3 Qt Py %(2,3) = WD + qaspa,- (204) = 25 ema eg w(3,4) WS + yt Py Cyj can be defined ee F Cor San = Wr + ei, “the elements the C (0,0) = W000) = Ys C(O) = WHI = ig | c(a,ade WEIS Us CC 3) 2 WS C44) = WOW, | cost made ae potter o tines” thal ove povalltel core have been Cony + Th wl Pl + Tot W vo (0,2) = P+ pt Gott tte = (0 2 a4 Pg = 0!) wo volo, 4) = WO 3) + Pla ApS Not ts * Ve = ae “ho™ ‘Yoo* Yo = “faey ‘i Yo tho = "Sho ‘s * pa" ho + tho * ho Yoo * tho 4 ho = 3 tig CSheat Clos) = va(or)- C(t,2) = wl (bs) = CCS) = ¢ Paahe 2) Sola o Ee [a | \ ‘ho |'*/r0 >| | Tse Z | [ho [ho] ‘|_| | | ai C02) = wlo, 2) tminl e(1,3) = WU)%) + mie (24) = WC) + ™ 0 3), CC01)9 CE% 8), C60, 294 OCS): to) y+ tonya cay), Cth) 40 (3a), Ce ta) Sac) “ ya mnin( ¢f0,0)+ “The ed optimal dre is shag b ‘ *h S!)¥0 2 Computing the nace pesitions im the area: ~ Root Fy the optional tree 0,4) heft subtree seel RO, = 1 ~ Rech a mal subtree is @( 3,4 ~ Real sah subtree & gis RU 5) We axe 4p iy a | The costs ore a 1s ae [be ne more thon 4105: “the relia hos We will frst compube Uy, Uy aod | — - sole | La For comy ai, 2 a For cornpubiog, Up us =3 lo Fox coreg a us 23 | Hence (uy, Me Hs) | Chat s* (ory : 1 30 ‘ ©, device io povalte) ae 4 1 1-047 20% ; : aa : : J = 4 072,45), 90 roe ete ¢ ; "i Ss 364 ,¢e), (0 9504, 9095 Fox three device: Da A Drs of: ¢ © $928,189 506 419108 105) 5 3? = | (o2.M5), (0-792,18) , (0 864,60), (OAs Gd se 5 (0-192.,95), (0.9504,90) is clinnineded =e +o pur cH — After this r ) (0-864, 60), (0 9% For one dewce Dy e joo 1. 4s), on is 4 ‘a Foo tuo daice T' S, = 9 to-s4 sy IS wee devi 3 For three device Dy sue {O-o3,105)5 (6.49268, 105) is eliminated dua a = [eas Now we Ore rT to tied 3 gb: (to, 65) ,(o-432, Se) s[oaHet 95), Co Due +o era wale offer are 5° = {to-se.6s),© 432, 8), (0-54, 95)> Now the best dey hos 4 vehi -Racing back throw S43 we deberenine thed ny et) ME 1 182 Least Cost Search the corral abetrackion for } ‘ lo vee ancl ct) 0 cos) foe | | Tien cw) ts the maine Sai | hus ect) is the Soe ae mainienn | to echmede CO this heneanie j { er propetty thed Y * e ye f 4 O a4) f find an answer node The @ \ , ty cldde and ocd a Yve Mele teastty fined live nece voith least eC): this Add 1: hati Les, Yeot 4 This - Kald went Which gi the { porent! vole: te From “the Kiglnocle = reeovd, Lidmode # oext separa ftocd cust; 3 ae LoSearch (t) t ig an answer node then Tee ar rf ads Ini belize the list » live nedes: repeal © ty each dill = ot ‘ fect , B-neck Bee tee execichon | es Gate the Erode Thiti th ry ult the children % the E-node ,t one » oulpul the path ror cuer mede, then + 6 » and is pares! cfeld ts dren gy & have be erated ,E become a h tm t's childien is 0 ansiser Modan live mocks found cthenwise , heashO the next E-nedle Ord the Search tonbnues area iC search terminate “4 uthen ther 6 th re stole space ree (i baer @)) Give an algorither for tims Honian jae Ans} A Hamiltonian Path in a qr aa permutation oy the vertices ape aph [yt vs ‘an tdge behoen ve ond vey ictal perm ions the vertices Whether ood % t Podh os nol Pseudo code: fundion check all. perm ulakions (adj 3, o) dos i=0 b 4 pti] =% : while next permutation is posib valid + true 3 tor i204 4 if adj Ceca} Cetin) t = : ph + , vertices tL vist alt the permudations ‘ lerodictts onck je anaa 5 dhose Herad ; hon + 1 odjacent verbees are tonnedte %) F sg problem r ( “hea aubse y 2? thet Tk holly subsd~ 44 V 5,4 (2,15 5,4) 10,19, 2¢ 5 jH0 1% Sao 1% 5,4, 0 20 eis | 5, 10,1215 5, 10,15 $, 10,15, (8 5, 10, 18 5,0, 18,90 [51 10,20 | |5, 185 | ) 12,15, IE | I 554 6,15, 15 5518 5, 1%, 20 Act oext demand” Acid Oenk element track i bert ement lack Rack tunel Add neck adement Back track » the stake space tree great ty apsack instante toy Wy Ks) = 424,5,0,9) on

You might also like