Algorithms

You might also like

Download as pdf
Download as pdf
You are on page 1of 114
eae jootthng > Te solve any pocbleow , sup pose we wrt pogo in C. But before wt wrty the Progen, we wile a bosepring On, hing Jn informal lomguagt in ordgr to solve “Ce froblam, Bevfore te solve th ppreblem by untae uy language, toe Neel algo rithm. Tare maybe soln. b a problem, is, onthm. pee ay? &, — Po grou “7 t mealy O pe erey ACME NS. TNE ON BSS) 8 ES AG ay ae Before wp . cay algorithms as a progewn, we howe b ford vat which ae ho akgoritt.ms oe geod in herve of tine and wavory. Mlime - whidh could oxecrite faster: @mrervory — whi ould fos momory, In Destan and analysis f oleortion, we will kot about Rows to nm VoxrLouw oriéinn foy a Very roheon and how to then jw, ae . ioe ; memo; we he oleoitiom. Te algoritivw, Ghich vv mock fiat rca in team f time ond space in eluded. @ Nobatirow wmd ait (fl i rl 4 ae 2 algo i ut ( symbtotic notations) og), 0 mn) af f{MNo qo Gn aw wal nos. and, CPO, ort thuy fla)e ©(g0)) i w Pry oly io upbor bound « A lonys gor Ge heat epper bound vodue . for g fe)=aut9, g&) =a Big oh, PO) & ¢.9(0) | | a 3nd2 < Cm | | | ! bE c-¥ ant) < Uw cate oh, solu sfied. 2 fd > Og) Now, god tow be voluo, such an | OO pe yn gk , Ary of th above anu CoO cou reght, bud alongs oc mek | gelect Be teark values among the upper bound valucn on tho tightest bound - | (@) BE ees t FO) fOD> e-gl) after tome value nny egw) wiwu 030, n>! then fl) = 2 (a(0)) @ cS fos ec. flr) 23nt2, ginden He fl») O(gtn)) , thin Flr) peg by) + 3Bnt2 2 cn , why io bur fr ony value ofc, ce and >I, condition i satiched . 2 fm): 2 (gi) Nous, yf we Aoke the pee a gr) ad ae ee ON? ane ~<) Suid > Cen > swe %, bat How oa of cad LG w iy way. % = PPP Pa a OS ap EST beg Cad Bega Goi he Bo, Bn+2 com never be lower boundid by Ww bat coteiala upper bounded by w, e Therefore, ip fOY) = D(n) , thon ony thang less Ronn tll by the onotwer - oy. leg + lea (logn) iv a value lower than u and in valid. $0, we Com hove more Han oad aver for Beg oh and omega, but we should tate He closed or thy Haltt bound - @i) Bey Huta, © : i gata) G OS FY < cgta). offer all voluw ie a and 6,620 whuw ng? | \ “f@) 2 8(g(»)) Ww eC Ns for eg. HUW): 34, (aden FO) eeyg0d, HP eed Bnt264n, fe oll ny?! fr) 4 Gg lr) ab One! 3nt0¥ OM, fos ath > 1— Plower bound] both the above carey ow valid for Me >I, NOTE: © in aloo called ar aiympboticaly equa « Senvehi mer. vwhidly meno “yf : ere] foun in the nction, fla) gry % be nw then we Cow dake Sn! a [upper bound] ; | P()= 6 (m2) E gh). Suppose, yf ft) = Bn ttt , they O 3n*ent1 > O(n?) » tutor adi y/ doninoti ! é kexonn can be oe in ata Practical significance 20,0, Oe Given any ol ovceivm , | @® oh (0) > it in gow fe wy Me wort cane toe or | ee hoo oe mecunp if you oie ony ir ee tare our time io nek g a Te es) ony. ee ound which mecww iv wy tax we au not goug to achieve hetlex tine thew tho - | 3 : : @) Be Hebe (> it v pens Hu average taw Lime. | NOTE = We ao wel Slerorted in whal tu bet time io for any ~ (de axe alo abbemuted in He wowt time take by ony ap. fox ony if. th ule ay ae fn, Bt, AYU Be Lad come, tose time WW Same. ex We howe ow arr o s1#| 1 [2 [4 J er a) , ke Stac of arvouy be on Hf ue Pafom Oran carck to wand any cnt: tn eappose ae seaxcly for elvan 5, than Bot coe time = 21) Now jf oe we howe to seardy th, entire uray foo on clut thn, Worl cow hme= O(n) aw fpf sage Sts of nln ae aig thin, Avecag con time > O(2) 286) = 6(n) a Morte, * f(2) for the algo. w rob the wal Aime» Ub i jab ow | approximation. To validate, f fr) dcrenseo , program time Arcenren and if ftw) decreaser, yog rou tLe ' fo, wc have fo find thd oppwrimoh tim (f(n) of an o. Iw order t do thet, 2 ue of 2 type, ©) Pherntiive algorithar .(eatrg loqpt) (b) Recwxatve rithm. (usiry fomrdions inside which we Coll aks i Both Heriiive and wernste algo. axe ob power b each oth Theralive cow be converted intn reamtve ond vice ven. Algor tha # ae | Reredive Recurotvt “4. AO Pe ht Gq AWE mar(a,b)s pa ACh), | | i | ] i i I Bi cots 1% tha, ; ma | loop goto ; iterative Neste: af Gh algo. doco vel contain leape—oms func. or tecueacie ww Chen thie 1 © Ash of Ge running fine on tis Up sac ia, hole 1» Oe ee Eve for the alge. in going fo be @ cont. value. So, for Suehy preg ra we tort O(1), vomt-care complenity ey. of Hevotive fuss tiono ¥ AC) t Hew, the p at 15 3 nh ia wing x bb for Get & 2») theralive aad oj ive v aot prof C" Ret”); > 480 Gnplesty =0C%) Noes, : for Get w 9) f for (j>! to ") Compluraty - O07) Te oo, Ley ¥ ee re “f 3B 10 Ea ee white (sen) £ oe io fe value ae ow sum of bo sth5 te 7% ht hak position of L- poiatf Cv") Seppo, fer $56, 4 t [=14+943 2G ae 2 By the Kime ( reocher R, 1S valu will be the sum of fib eee lL, ly Hf the op ba ee de Ck+h) aay 2 D> e+TL oe L 2 b= 0%) Ctouplocty) aan t 4 izl for (eb 2 deny 144) ff or we con cay ee : prof Ceui")s - tl iy > Ovi) te, me ond aweraye (axe in vi times . Therefore, we con write Conprity » 6( vi). Jn come Gam ts book satemorl ing on seaathin oe the Coch, than we could have beat, wort or evexoge sae ae as S He neal ea@ac) £ 22 it Lijs tins je (ina | p= 9 Boe for (4- neice ny itt) { kz tuto | k= e100 pone woe 3 ceW for Gels eis) ]edtiow| J =n timwo for Ue= 15 k¢= (00 5 kt) M=3xl09 | = n X00 € Gq enh, prev ( vou); CO F2K100 3 X1004...4 t XX [00 ; 3 a (00 (t+24 at... +) @® 401 gt 2 ink bf, ene Complenly 5 O(n?) Kewo fow (iets tCeni itt) £ Working » f= 9 for (ab TP ij) ¢ for (ket) Reet kat) pulp Come), 3 ae . ee n A Ay nt pe ee A Pk ee . a yi 2 S% (urea. te’) Sen (fe (241)) Ip? ZW 2 (ot) (2n4-1) ] 7 AS Se g > O(a4’) ~ Generel ain ; fos)= Pt Wag eee > O(n) eA) AC) t eae for(l= I tCv Gately oy Eat ey pf 000”) alata tt at 2" ye goo wv ond. we sep See x hen loge) He value of it abt ow ,L244®, ‘b hw. Whatever wll be te Volur of ee ee Pa. of te conpaxity “leq forction. vy) AOL nF: a inh hy ley a ee ee ee ee ee ee ee ee ee ee ee ee ee ee er ee ee SE for (O 2) Lens tH) t as ‘ ee kee)? PEs oh) prodf (ois HS * egy = } GS 4 WwW AC) ¢ at be ag fos (t= 4 iden; Li4) t — tine for (jz tj jcens Je 2epet —— loa, n dimen one ly Whew phe be 2) ——— leg, w Himes patxtf Crave’); 4 3 E. ae egw ra, | : wi) : testing 3 yt) eg) Asta n>2 lo rking > ileal 4 aot 3 > 0 (Alea, x) while (n>!) : bee Keen hed ne gk je loop= Hine leofp= 34s | loop > k ternen : 2 Caplnly- Oleg) o n=I90 me nz(0 nS hed [49,90] =4 ime lef a loop w=s loop , n= 9 loopen = pty 0 Cg) ea. (iii) ACIS . for (iets ideas Ltt) £ —n sonny : eh say i l= ue for (jlo Loe =jH) esa eee Prentt(“ reat » k3 Fas J ] =A tee] j = 2 tive Phen ee see sora) ; UHL) antiga ie BDO whegn’) Aro, HOO AL ant nage fr (=; Xen; LH) { pe ah Yeon) ¢ Help prostf-(" mui” 5 } ? } Recs, fording te value of kin tem fn, neon | 2 ' leg 4" 2" f he leg, leg, w Conpluctiy = O (n(e41)) ; a © (a Clog tog, n-f)) Be. ' Ww ae tom foe , we v Tove Complexity » O(log log, n) Ano, @® Tine analy xf recursive Program ” hh i a o ote) — (const tine] Ustibe ait: red (ACL)+A (YD) Bg to count he, j W, WE code rteunrirve ” a(n) cre) * func. and tie bay “ty analyse Tha comp tocty hare, till be ve Tim) = c+ 21 (4) x C x x ea) Als) { ~ Ta) e+ Trt) * 4 (97D ' retwuv (A(o-1))) dos bot AA pa probe (ar aan subdituition. Back subdtitution cow be applied for any Areal) problems bat drawhack ¢ thin in tk b slow. O. Solvt -a) Taye c+ T(t) —O T(at)= cf T(a-2) -© Tat) = c+ T(4-3) —O Substituting © in O = Te) = e+ Cet tla-2)) —D Substatasteng ® in® , 2 tle)= ct Cet (e+ T (n-3)) . lb cm3 2 34 T(n-3) > k47 (h-b) —© Now, in, the algo, Ce bose condition in n>! 2 TOs t+ T(e-D 3 nt AD, 5 n=O ech recusnive fanchion sup whun equol to J, Se func: with ebop. how, v—lL=t he n#l— © © n@ 2 T(a) = not 4 T (n-ne 4s) T(a) = (h-r) + TC) = n-l4+l Ww [r= 0%] €f-G) Tad= ntfr(n-t), n>! —@ 2 | pret Now, Tle-t)> n-t+ Tar) —@© T(at)= n-2+ 7(93) —@ Substitating D in © 2. T(%) = nt (nt +T(a-2)) -O Substituting ® ty © tale nt (ae (nt T (>-9B-O Br AB + T{n-3 2\ 3(n41) + T\(n-3 = Le +T (be-k ot (Wet) 4 (n-2) HF (WK) FT (n- (UH) € - We hot te eliminely T to mako the eg. in teumo of n ty the Complordity . 2 of eH =, 7 con be eliminated - MW n-k-l= | nm ke n-2 Pustheng kin 6, Tln)= n+ (n-+ (n-2) ++ rth) ent (nit (nr) +. # 2+ Oey ppa. *4) 7h © O(e) Bro. Otiir way solve recursive fame, v teauulon bree Using this method, we carr solve soma of Ce sccuriive Bi: but, rot all. We mosfly we tle Master Theorew fo sole receuLnive furrctcons. gi) T@) = 17(4) tc, % a we tay to coe’ amount of toork , tex we Could produce 2 problems with, swvaller ek of i/ps and each 2/p size lo reductd to H. Thor should alicoys be an enchoy condition. Te) aT) we wh >t em aha 4 ST@)-¢ > e OT Ge e aoe ¢ 22c =(*/) - CH ict Yc + ede upper. L(y e(ttatutet... 2%) LS TW) TC) DO) TY) Ye) 8c oe 1 Dhan Ces poe 20 GED * c(2*.9'-) Ri ne tN " NHN 3 “hth th "ho * Feet ee ¥ Cet) bvelo cow how ln T() >h Be bree Assume, nog x (gyn +1) develo aw thew, Ae Pr ‘Zlevel ,workdonw wn. * Tene Comfotecity = © (rfog yn my) =O (wleg,n By hadi Keun] ROTE= We take Me mininuane of he tort coe complonity Value beeau beyord thal cane t a worl can- re, tote the tighter found value. rey Laxiow finctions to analyse time Cemplercity L NOTE = I Ge -fanctions diflex by uly constant veelue ,obynpboticn: thy, thoy axe Sone bel value whee ane difeust . But m the main mative io t fad tohich fine. in lexyer tn ony & tow , not only any rpbedcca tty, 5 NrRAMANnNMRARARReReee Px ued) g® "yb @) 3 Pa 2 Put log, ov both frurcion | Pulling leg on beth fone Klrg? — Dlegw tnlog3 whee R : =a 9 lean 7 out on, 2 Substitaling n= 9h 3 > leg2 5 ae) DYAEB log 2°° ewer: : 5 n> 2260 a Te fre. 5 ean a on. 2 : w bager farce . (ii) i ae (Wy) nw “Cony 5 nn W Fag wv Pat zg Conlin out mw peo Pe sD ij» | bola dig 5 Taking = t00 a 8 l i 5 =e D> qi - lao > 100 tog Clo to) @ ytgn ‘a nw ae (log Me Gj a i “ on wh ty “e 2 ‘. » al ") (eq 0 * (Lg a la (10° law) sa up ms ae ith (on > talgigd Potting lq on bel fine, Putting leq ow both sda 2 Vi legn te lle.) blegn by lg Con ie nto a leg Lee > hee Toking w ad (00, > ae ; B® FO= ws 08m 00 | f= apie feelin eu? 5 n> 0000 i aa (a= wn 3 0¢n< loo ay J 2H? 3 n>100 ae 3 > fp | 8-17] 100-4744 _Flo990 aye fete Te ap sight oT “ 5) e mo obi We io” 2 loxlo B ae r. th fy gi ak oe 2 fls)= 0G) 12 eae wher, ng 10000 a ae fu? tf NOTE? eg n)? ‘£ ~ Uepnigm gle ») @ MastecoTeoreny + HE i not applicoble for ald examples, only flex can be solved - T(x) = atm) 4 ont lah) tabexe g AS tan eto a1, b>1, k%O and p f wal number ® sf a> BY, then T(n)= © (w'Ie®) ® if a= bk, CY p>-t, thn T(a)> © ("DO log Pn) ® YP pet, then T(a)- (096% bg leg *) OH pct, ton THs 8 (wi'e*) @ ach* () if pO , thew Tln)= O(n" bea Pad ®) Y peo, thon T(n)= 0 (at) ef). T(a)= 37 (%) 4 a3, b=2, ke? , p20 Gmpau 0 ang bY agec yy 2 xd condition. of Masters Theorem sostisteed , T(n)= 6 (v2), se, p-0 @ er)>4Te) te o>4, b=9, k=2, pO y se gp a ond bs 2 Pe sey @ & where ee TEA) 0 (m4 Ug"n) = or Gi) To) TER) 4 a-Ol, be 2, k=2, p-O0 Coupar a and b* ‘ oy 3" condition, dst pa 2 TID)= 6 (WM, () T(a)= 16 Meg fn a=l6rb=4, ket ,p>O Comparing a ond pK (6 eu! 1K Condition soilesfied, 2 Ta): OCW RH) > O(n) Aw. (i) TA)= eons Peas © 9T ) + tb 6 az 2, b= pr ket, pot Compact 7, Ge L Ind Gnclitcon Cb) pat : : | , : Tn) » OWT", tg tq x) Gv) Ta) 2 9" Th) a 9 Gn thio ‘a’ han to be >t, bat hee ‘a’ rot of that fo. Thexsfore, Masters Toren cennot be applied - ee ne 1 x4 Qu idan * Ing Condition ca) fort sais (d= O(n"?. hn) 3 O(n (ea og n, a2, b= 4, L=8-S!, b-O Comparing a ond bt ne af Uo 3d Condition (a) pat 2D = 78 (0 oe &) T(a) 20-5 ~) ale 2 © (n Leg vgn) Any. peg ee gl aed yA bapa MT wot satisfied and x, MT cannst be opplied- 2tfw) @) Tla)= Pree) 225g W=G, bes, b22; pet Comparing a awl pl Cae a 1 Sd Condition ,@) part Tn) = OCW bey we) Bra, (ui) Te) = GH oe 3 a=4, b=3, b=2, p20 Comparing, 3 < 3° 3rd Condition , () bot, T)> ©( ni ey Ang, Gav) F(a) = AIL) ee i nv are ,b=2, ‘ey Comparrt &>9 Jat Conciion, Comparing pat 1H)? 6 tn to” Pee © (ve) « = thi) >ofn 4") = > 6») bo. x) TC) ata eee Gohenewr ve hate +1 2b meang that i) we donb dy ook, the roblew io geltbe Aivided. Bost MT states ee tohorn ut obo some work , Ho probhen gos dividel mRnmnnn sm: ic _| Se, hese UT coomot: te applied § (ei) T(~) > UTA) + kegn t a4, 29, ko p=! Comparing 4 > 2 a ae “Ala > 8 (nD) 28 Cw) bu. : CH) thn)= aT (8) + ve a=9, b=2, tot 1 p-O Gu) tla) = a1() +h 023, b=d, kel, pro Compa nt 103) 2 sEfee> {t to nd ic n, st(s) = O(n) Bs, (w) T(a) = at) +vh a23 be a bet peo (mPoring 3 > vi dt Conch don, T(n)> 0 (n'¥2?) O(n) Ano. ‘ ‘ ‘ L ‘ L ‘ J ' t k t 7 f : ‘ evil) tl): uT(A) ten [| Gy TEs) = 37 A + lg i a4 b=), kel, peo ts Cuong a=3, bY, bel, pel u ,4>yl textauct.” em | Sof coe iol ae ‘on, (@) pat T(a): ©( nh") “T= O(n ig") Pro = 8 (0) Aw. nee f Spa Complurdl Iterative ond meurotr alpoitts cea i og am, amour of “mevory colly utileed in orclu 6 firtih “the program. Thon hoo to fe! analy seek sn tome £ qn inpul R21 HED noon Y ® — ola), yp dit Ww —~ 0), xf size Wy cone . — O(n) Ss aed on the Sloe ip, the se bball shace an colt the fet t % | NOTE = Give Ape TR to peices ae cen lucy, we may eeu require mere poae and vice vee oe Bp OOD EE he) ee eee A. ntl opoe wo reauind 7 rChet ow) bat vn! n an Gu inpuly , so ee AC] <0; ® tagcat Ww a vedolde ‘i 2 space Complorty - 60) NOTE > Thy oxtra amour of Sone required doeort dpend on the siae tf by Yp- in My ofove Cone. ee 7:0; ain coat. spa tr viquivedl , © Ue ane. wing CI yi ade We bom-obld 4-0) MCR 2 Sy, aan | ! sak iy U) ied 2 toate 6 (J 3 —(n) a ee 2 : for (hz t tow) a Poce Complexity Ow) ( plel= nti, Met, Span required by th algorith 3 depends on the i/p gir. F th Hp hee x (00, we ned 0 exh cel. @ Ago (At. n) £ veents B(npn]s —fe) = Amousd f uders spo ere rsh aeg | i f t [ ak Uj, —— 0) rey eal = iF ' fe (Cel tat = Space Complexity 2 O(n) ; for (Js 0) ! BCL f= All; ; [ ‘ Recursive Vermory Space Congblexity 2 d ; ey. Ge) ACa)E Suppor , AC) O eg ‘ (714 x : A (0-105 [heat TeCWUDN printf 0; : 3 ' c Wott: Head reeucolor, 0 keeUrnlow ak He begining ; ai eet a a ob We ent. - Bo ” y " in th body. < Said atm Dale oO cs al gpsins SEE = Shenae Me Cast ti ne you visit S x We 2 the ity , hoe, by be thy ou Be He tna ie w os f eq i % Const. space Pa het oo voy spree required by evouy Hack ecord We alte & yf Kore are ‘Vv inpul, then : (mit)k colby space i requ veal t { 7 Spour Compleeitiy = ©(kv) ov zon) an k=Consb NOTE, se eat Ah factors aN inter hed hack. ond ip hor Wo some other sistrudtion, te exearke df. We then, duck Me sre shack. for tire @uplrity of abo, ae T(-1) —O TD thin be eas Tla-()= C+ T(u-2)—@ ‘ T(n-2)= 0+ T(n-3) e—@ Pubking D in O© t(n)= e+ CHT (H-2) Putting O in © T(m= CHct+Ct+T(n-3) > de+ T(n-3) Es Pox ewe Tn) = Ohect be + T(n-1) =D remove eerie call, n-h=0 nek -T(a)2 act TO) 2nctl “009 te | | : | Gi) Ata) § —T) ac) WP (apt) t nos ro) AY) Ali) Te) 3 BO 1) pride SAPO AO Mas 9) AC Almi)3 oS “ato Oortam ) PCL) Ate) y MoS PCL) ACO) } ~Tlat) + The order for lonploity > Coie olin atta = O(HK) i) = 0) NOTE - (de con vedere the fre and space complextt wir erbi | preg vaun wie nomic fr twhich mali enn aed wl a al i ow 1 On ame wth, the sone oy, a . eiaae % rr Dynewic programming is ae hee dy bow casey usher Now, tae tn) = a +) Fl —@ Tat): 27 (n-2) ¢1—@ Py ee hil { i ‘ 5 ‘ ‘ T(n2)= 27-3) +1 —© : ang © in © ‘ T= L(y i+ ' = UT(n-2) 4241—@ : Ditting © in O (oJ = 4 (91 (na) Se 4041 ; 2 aT(w3) AT Re®Hi 25 = PT (n-3) P4041 etre )e ote eet ; eee k wth uv, x sor rope arty ony 4974a41 \ 29" 4.Qhelg) 2 iaaieg t2 ft ; = j oR Gale therfore, Tox _Consplenity = © (2) = 0(9") Aro. i a t ( U f fh nef te ey fg E * oe may vey) high. ) beter temparad to wverbion ok ond evar sonelives better hon quik of. ‘i Lt! y ee Me 5 +H. eee es 3 cote sone wr" Me ees a(2]4 els J@ aloes Pub a hy lage ne, atte tty fleun of (02 ]u]s[e [ae la] thy placed into Ar nue away in XR mann - mcn@e CA,p.q,¥) Wie dept ly h, =4-q) feck LO. ond RO nyt) be new aways for (tel wy) LOij= ACb+i~1) + for (Lot n) RG eA CHT] > U[n tt) = 5 | : : ' Ve oealst Go te RR tin L be Compared with elon in R and : Rn, 41) = 0 tee <1 5 fox(kep o 1) 1 w (LI < R(yI) € ACkJ= LCi)s | L=l4ly doe ALKJ= ACIs Jays tm. Com turtle = Jn order t cepy chuments fink Land 2, O(n) tine w required. Thar, we have to make Ln} tomparitions fo tort Ue ele and Wn? tine fo place the eleorents Ulo th in ored fom. | 2 tase bey, f 2 ©() Ana. NCTE: Scbfow yf thee clovunts fr Land M lets tr PR. - Th bie complecity 7) jg to be O(a), Now, the spare required fe the vith - | | Space complicity - o(n), an we haw fo elke : Cook an ed Wy an | Order to merge ort then. Ris morye Proaduwe in eleo celled out of plore Procedure. | Blok, do uc kako M ap Che lant chon of eth fe amay Ut Land Ry Ht % Ed A (oho Polol T2181] L pope] = LT Tea y «| a fr [slela a) ties cilia: = ' j ' 1 ' ' ’ . Thopfore, Loving od at Ge end coil cnoure at if om Ug ewsirely gee copied 5 then te ofker Usk & obo cofted) an — tempore te 4, the elemento ir he other lish will sul fe les. A (1 Js [e [2 [iol ]20[4o] toe need nel cheek for enw list, wheter ib iw over ox rub everytione. e Nott: Ps ve 9 tits, uf edsa fare Dw giver Chay th tine couplexity = on). If no extn poe a geo, the e ” might increcse. We Cannel wae menging metiod fo sot Me elenunto in thet cam. We might howe to apply some othe sorti Now, we wll fottew divide and hove oy meltod- use, Ohh meen, if we Probl oF K2e WwW, ue divide the problem ote 2 eab-problims. We, fen, solve th sh-prohlomo , fest ond) then Combing He ‘olietion . mocae— Sob (6, py) t if bod q= LEY/2] murge- Cork CA, p.9.)s mur — Sor (Ag +1, ¥) 5 merge (Arp, 4.9) } “Taking Ueampl, ChE EPpy Teena cp qe _ i s mug fost (1,3) : mucoe-Sovb (4,6) _ Oneage ot (1,6) aus(r,3) - Ons(ae) Gn13,6) Pan 8) a aia usa, 1G, 3) 2; 28) Solus) Re, 2 Rens 546) Oi @t> ol. Or @ MSC) sn) (12,9) S(t) eres s) m(44,5) ene faa ne seth = We cay make a slobal agit fore the weep eloonrento tte 8 ny of a tae only 4 mage proadure 7 to ies rt pve fex mune 2 O(n) Now, thou a J6 ie required beck ‘Ge heeght of the recursion stark = heght of the PM ef-s BEV ih vh ar soe amoy = » (galt!) velo ox Vd My 2 Mac of Shack > (Clog nie ttle 2 Sues. Consplurcily = 0 (Lelog n) 099 hs 2 Maye procedure 2 O(n) Recuroton tack = O(log n) | er Sua “teed a = O(a4 Cogn’) Ouk ¢ procedure call, in followed fey momye work a we dy not pak the any inade te anne ih . Instead we. form new “anny: to BE Aeon. andl, thon loving thu back. Nowe, fos time ouplenity merge fo (A, px) { — T(m) ib (ROO 2 O(a), a w ir Clomi ned 1 pros eo (Arb 4) —— Th) =o (A, 4H, x) — 1 (2) Het C4, P47) — ot) COT (a): I ') + O(n) Using masher Theorem, as); Bee, Lane PG Cmpanng a ond bt if “d pro ees 2. Lh Cornditcow , ca) park sasisfied, TON) = © (n!642?D leg Pn) 36 orig) n) Bra. (Tine Conf xt] §. Giver nv clemunto, murge ‘thon Jaks one sorbed ist wat — the own elumenb bo be moxged, who sorted lost hen of wary hovel 2 noeeutive elemento one going to be marge ando on Uist io, J be Gi its ae * Ce Cc © wwlt n dovento , s said order ¢ wn teow, # Cos wey (wel. Asd=t 2. O(n) And in order with th eited clont fo Ww (uel, Ht will take w tm. 3 Ol leq #1) 2 Tie Complexity = 6 (alag n) ©. Guov “bogn” sorted lich each f de 8” what wp te detal fine sagui ved fo mange then ere ingle Risk. Tt |S (a oe aot TO sr Gh gerd yo Geo. Tp 0. ce strings ecu of leng&ty Sw Ow glue, Cen tolot ip ty fine daleen to sit hor. (2 ny merging) | Se how © fovlow Uopepice oder , ix, dictionaay | order in ‘a ie me a Sings. | ¢ Gal Oe) ‘onponiond repaired. ' ‘ a YP thaw an ‘n! Brings. BRS ww! Le pa e— & Na ash Gp <- "ae mH OC On. f aN CN > fox Comparison, Couportion time ykol fine Calken = pi 20%) © © {rey tompartion ill Lake 6(H) time and ro. ct coma atseona folun ©(a). 2 O}@) wl kh te time in ouller to compow thom and fend out chit ha» to be dst and which Ano to be dnd. We nto, hare ts ofy He clemedo to rort lel order to —— gork them. « Evewy &k io containing ‘ w' elomenta and there au bey) f H(E+) > (0); c=L-15 Ait = key; $ a 95>) saith oe i Seb) — GET lela3 69a) — Of2tsTela[3 (ra eas: G Sem ee]9] Note: The weertion sort ROLL, Ghak we arranged fore Pays oe prams 3 feu Co) i fox 2— | Grpasison, | vovenuk = 9 220) D wo laying coxda. (hen, we Pick upa cart) Ww to ie Ras. I cou. , aoatkion sok pxrooen Ge elements in eroluosion, 24 44 298) deat 26 220) (et) » 2D (nt) ~. Thal time tokens 2(1) +2(2)+9(2)+--..+ 24D = O(1 OF 84... n-L) 2 1 (nD) Be 2 O(n’) , im wont cox. Gr deat cose, “Lime Com ity =) (w @, cluady sorted list. a : (m1) couparcona, © mov. Spor Complenity = (0) , 04 onby 9 vartahlr aw wed. ROTE > COhenever we need constant Paro to seat ony go lis, seuch, sok ©. DL alto known inplece, a0 we Cee rok cons etre space te wit the given algoitio xe, Che fine covplow hee dipende on 2 Hing, fe, @) No. f Comfostsona Owoelved - @ Ne. of movements Lwolved- | Comparison, | Movearent aay Ceardh © (leq w) n 2 ae).&-D) dolor Linked Ol) 80) of) isk 4 [a4 G| Ne mevemut bred - Al Spe aa 2 We comnot reduce He Aime comploit Gf incextion cont a ine emf nly +O) fue Cay 00) DOuich fork > er” In comportson muge cork of te sie of He Up io small han marge sort io guing hove more comblert as th wes th gf es , but quick sort io er. Both follows Atle Gord conguot yulo- ss : We seluck, a Pevot clement (either from the hark ox any thera in the arsay) and pot it te postion in suck a oy thal alt elwenty & (opt Oo i in bes ban or equal & Kat And obit elemento to reg ht ox eee ii 1 ! PARTITION (A, 8) { ¢ is soy oe | ie . [alelsfole) i p-ts aval . “es | fox G=p + Ot ple + oP yz Heed eat DSLANS aL 2) wth ACT tt ond at { ks A(e) wrth ACjI We oe | Wwe hase te apply ouckey A(LH) wil AC) Boo again of bof. J vetum LH 5 | 3 | + Toe npaiy 00 | s Hore Set (A,pr) £ NOTE = Be next fonction call, (pee) t 6 quick sot depends ow q= Papcition (4, py: ¥)5 the retcu value Pari Quicesorr (A, Pi 4-05 untile in Mage Sot, ve ae qtt 45 hod eburoys Hr middle elument te sor algorithin. if C9) i (4) 6s (13) Sa me L. PC) OSC 9) PCs.) as(s® 956.4) x eat A (Sa]eT B]2)) Plea) $8666) Gele.8) gre Se Shey 6 oh : rig Ehh ie) ‘ feu LT) wy G [BIE Ie) Hah oan Hew, ee perform the forction eeontaly depending Hr the cheovent, present in the aw Jn ths bert tare, uke the Care) w palenced, () * Spoce Complotaty = 0 (log »), oot ) ie pay" fe 7 Ew Baan ae cal Cy) WC) Cs) In wort. cox, when te Ste io unbalorced , = ene (n-2) I (n-4) Tne tooxt Cone QureSovt (A, p-¥) f Se ea “# (pent 4x Partition C4-pex)i —— ola) | — O(n) Guiec corr (A, pe 9-s — 70%) | — Tho) Gurcefoet (A, qty); T(%) | —— TCn4) | ) Tr) = 21h) 40(n)] Te)= Trt) +70) Blnlag n n) =T (nner = T(n-2) + cn) £en Wort Case + T1MD= TH) £ Ot) Timi) 4cn , ae. eh) cen T(w-3) #CM-2) + C(mt) FCr The yaa (nay) + cn Ck-9)) + em. + CR Se POPS ton 2 Ofn(nit) ' Tu tou Caer NOTE: Hf thy put o in ancandling order, T(a) = (wm) + T(n-1) ole) — 4.= Prec TION(A, Pi) 5 = ow) bo. That} Gureesont (Ap 4-1) 5 ua (A, 941.95 $ eT in Aescardting onde I a “hae THA) ies rat 5 [2]0) = O(m) Ana, v H alt th elemento oe samt, GEER T(x)= O(a) + T(a-1) ee joes > EP EI = a Che Tow eat n a Ae : wee “By “O.- , of, > A ve ib “4 in ‘ ) “wo —hO Wo =O 3 tag a ™ : MR PN ee on 20 (eqn) Awe ay 1000 1000 Yo ty) uw In can Ke prt 2 OW cite cle wort splits and the neat level best splat and 0 om. Reels fey n Ti: cna crt wr ft) ene San i944 ERE 2 eee) Zor ® ae n-2 W-2 SPORE tothe nig : 6 (leg nr) Wo. NoTE > We we fy ac gt ota’) in cams chew the arty wo in auanding . doxcandling or all elemento in Be array ant OW ©. Te mudiian of 'n' clewvanty con be fecindl, J OCA) Erne « COhich owe cs he follovtag D» cowect abort ceomplecity ca quick, wh , in which median in selected an perl 2 =) Pak fend te mecliany , for ahich Aime = o(*) nek replace Cho lot cleonend ait medion = o(t), APly paxtution = 600, Afte.. paxtitioy wt Bie tf Sou en either side f the wedian. > 1%) “Mul Vive ep eee Cot OC) + O&) 4 2 T(%) eg “ieee a a. Satire Maskerd Theorem, - O(n leg w) Bro, Q WwW quid wk, pe sing ‘n! clement , thy ys molest cement io elected a five mor O(n) one algorttim. what to Ke worst cue tim car plictty of quick sort 9 P Seaxching (YS conalust clamat , kine = 00) Replaciag with last clam = OC) Apply ots = O(a) See | ey > <— Pf, —> : ©The) = O(N) 400) +0(m) + TC) + 10344) FO) T(Ya) +1 (244) Ceation 1:3) | for matioe (34 ax haw : Ta) = © (nlegn) 4 (23, T(r) -O(alegn’), wo alo fe aL | OL oe quid sort, fox corte: hod ee T, ond fer | Wel, Web, [> tee oT, , fend the velotionship tL T ond T- —> As ve have sean qui ee | for came element a O(n*). * Teh o. by Faking an algo. , paxtidiont fokoo O(n) Kine , we aro cpliding “the peblim “sto 2 Plxto. { part takes Yon ond eter pad take Yen elrrents. hed in the Hime Consplerity ss ttn) = of) # 0(%) + ore) 0(m) ¢2097(4"/54) eo SSR Ge. @ Tone Coup tity fox “ee spexabions hey a ey =] [ roeet seaxely 1 fed min | dakete min unoo vfeck a'r ot) o(n) ot) O(n) ent) on ana bln) 0 (tpn) 6) O(n) linked Use | Or) o(w) _ ols) o(n) min Heap t oC legn) o(t) (tog w) NOTE? I we want t& avout, fend minimem ard delete Mininuyy thon A best to ue min flraf dala fucker. thap no bimory tre or 3-nary tree ev Tae sts St we aml alimod complete binary bre a z complete « T fe gs gos pian vf moke 2b a heap, Aan. ~ Real ho heop in which te wool should olwoyt be maxinun. fox exery sabdoee- Min-leeb—> it io a heap in which tu rok should always ke minimum fos every sublace- re NOTE: We one nat gong fo so the clurenko uring linked fist fr tree We Ore wrteg array & doe Mr elements av we need les dorace, no potrlecs used We can interprete th anoy aoa be ; t = © ess) gs" 2 [repo [ett Te 13 2 fr Wf ol, locadion = Goof induc} ¥2) and Fow the right child, location = (soot Uden 2) +1 foe apathy eeepc ae | ia it NOTE = Miuthiplying wth 2 fr combeter i simply a tpt shaft. nt woth 2 wv, a right shift ion (90), ee > (10), ©. what in de dae fF the man tec powihir for the following? © 8,12, 16,15, t0, 8, 4 , Aap -ce~ 1, as th foe ab 12. * dluap - sae = le @ 48,4, 13,16, 1 &,12 Heap wr = 4, pose ab wf @D 25, 1, 12; 19; 0, lo Heap sue +19, falls ab 32, (3) @ 14, 13/12, 10-¥ —> Heap - ste = $ © 14,12, 8, & 10 Heep ~ 0 = S @ 14,13, 9/12, 10—> Reop-sie= +, falta ot 93, (7) @® 89,19, 40, ‘a 10,2, 5/4, U, 6,4, 79 lbs hela fol at Yo, (8) t ann dle it th of the e Or the np oe ae ho the SE SE i Ma. 0. of nodep DI 5 ip Uw Ye no- rodeo in 0 compute binasy Aree or alvest complete benasy Mree., thon UG kaw out tha ogi) he height ef Ue A Tarafore, otght af ory heap Lo (lop), oan. heabify and eghile binary Soret + = Iv comptite B Binary bee, we have a. property thet leap Sale Rat from o. pet and frow Bat pout cwords, Boy all will fo a feof. gy. toa) 3,445 Ts ndre Hak au going bo be “leaker ov, ee 40 WP hone , MAX-HEAPIFY (AL) 4 be 2, eh Tk t= DIF “ 5 “p e eae ond A[L)PALD is bs anit heap sine and Afr]> ACkargek)) largest = 3 f Casgel #2) ALi) wh, 8 Clara) MAX-HEAPIFY (A, laxsest), NOTE: Thy dd fe, eis. Mu LST and RST bo aluady oak oa ge. mour~ heap . We ok wees Shaie'ts i nub ai nt 2 comp 1a. WES RO ae cute ven mode, wll) ne hetght «f bee. j i NOTE > The tn? ion th veh comp plexity and space cenpladsby B te ro. of nodeo present: in dyee ov the subbee pr which i wy te yoot- Hew, i Ae ahow ,ux cw tata from Te Gwufort, NO. nodes are all nodir of ta! bree. the coup (nation cere Hr, f Hor WhUw Wwe WW calling te fonction, MAX -YEAPIFY() @® Build mar heap toe ond onal sto Buitp-Max- Heap (A) { 4, 655,0,%2,19,3 A. heab_si2e = A. length 5 4 fox (d= LA-ungth/2) doun 4) Max -ncpriry (4, t)> ci NOTE: 4+ ["h] axe row~baver. [Wh] +t tev au loower. be el of mnchapy foe pk noah dn down te {. a" vo ae os ne su rode peights e. hight ‘0's fe |e] 3 3) oy oH Relea (4,0 hatghts “is ore (9,0) =U woo ant © m- es hey had o time eS ah ony Riga): a ne TEE ats) ( Werlidane Lo | gale ght eye Oth) &. te en e from Olav ntsc . i 2h re. Ok) dare to incrare @ ® Ey 6K) ie 2 GE “f) sem becpat kanal Prog resion 0 ce 1) Linas. lompolecity = O(n) Ano Shoce Coup lenity » otogn) sie, tasheoy, you Cole Hr mant- Ss cee ak Ke highest height, tuhich meow Erkrock vs say ok yb ah (Oe axa qontete fhe, mascimuon prow thy mwac- hemp. Than oPlec, Ge Gil rept (ant induc elven in the heap “Bi in We vost foxtion ond Gun heap mohke the keapp, Sas “ey e : Heap Frbrack-man (A) £ YM Mohsive <1 envor “heap heap wndecfloce e more A(t); ian AltJ= A (A. bexpstre] ; twa Complexity, > © (1 A. heop-sive =A Mop elie~15 te MAR_YCAPIFYCA,() ; Co he os hei Ww eae aoe bg wv of te son nd at no. of nodes] . pare Heap —weneuo— (Arb, bey) § 4 Cley ) 22 ALT Tin tonpscty = 0(lg =) tb might have AVY” 4o'drewvel tb He rf RR fo shoe on elawent , ue werk -o (ie, a Note: Pind man | Delete mar | taerts | incre [ecreore bay | find arin uae OO” oft 9 olhgD | elegy) | ces 2 Seach | chiki 2 Man Map con be wood an fou 00) | 0C) —emreo whew te hae complex’ o(t) ond O(log ) othectot se wae come Blur fom of OS- _ | . PB Keapro® and analysts + Bs | HeapSork (A) { 6 Borp-Max~ fea (A)s a \ feo (i= Baling docon bo 2) 4 Oe | erchange ACA] wit A(t) ; fio} pofo [eT FI 10] AMwop-sire = #. hump. st2e -1) : Ma x- Heapiny (A,1)5 i 50 (7 [is Tie ]25Behco] Tne Couplenily = OC. logn), 00 max-lexbify én called, de, Ollege) for almost ‘n’ finns, out of which "h dimen max-heapaify tine rz) n- O. Sng hea with Ww clomento sith th matlest elenent ab the reoh , Ho F% smallest ebment tor be found a time @) O(wteg x) O(N) D(a) @ow > dadids Hk wien =O (lag 0) foal Hy min 001) * Bed win —O(leqn) — dooert — 6 O(log a) sae pet ie TOR) = O(log») Aug. Auteke BE min 0 (loqn) BUgiee brary man heap oe “ mumbero, the satel ebm’ con be fund in tine. “ | Loy (n) &) Olleg Ww) © 0 (leg eg wn) @)o(t) Nes of lores will be a) in ma heaf. Ne. of tormpartsond - Ole) Ana ©. Elemente axe tented info may. heop i fotlostng oder, 32, 15, 20,30 19,15, 16 What i Re coc heap look like 2 — @ : 30 s a to i) 0. Rect of a fiotg representa 0 ioe in the fexnory man heap @) 135,689 © %/b,3-1,8,5 © 4,36,65,) BF45,6,8,3, 1 Koco, F2,10,4 to inoated into te mar-heap, hab 1 Me ne scliing arnveuy 9 SG > fR = Ke = Pro. s ¢ Ta) @- lenviclic th proces of tnoerking an elunenl int a mor hop JE te perfor a binary seardv on tr petty from ney (eof rect to fend the Posttion “of meuly anoerted, element the no. of com parésouy pexfomed wa —> Tn order Anoert aay elemuvt , Teme ComJoleaty = O(log Der Btnany card dy apiued eg n eluwints ‘0 ford the rsition, = O(log leq w) Arg, But, ar ord to saveat the element, ha fimu censplersty twcll olewouys be olleg n). 8. We have a bing feof ow ‘n' elenanto and wid to toot ‘w' more cluvants (net necrsarily on after another) into this hemp. Te fatal fine reqerived fox thin i @ OG) MOH) OOlwleg O(a) > We caw adh ad ‘ww elemento of a tame ond call Build hoop ae But , may yenrove, eee rearlo ve Tony + O(%), ie,'n' Gveded and ‘n! elena alan dy ab = 00) hus, eg @ Trlaoduction to Greedy Agoritims Nove --64% OPEniration Problem: G) mintwtze toc @ marimize prof (i) maximie seliability . WY) minimbae rok. Greedy method and dynamic prog ravering axe 2 prograrvwing cae to wle hie. ee p a Nowe =U Gq i ai ee optimization pe yoblems , whic mpano quan & problem, ex might not get the optimal wan. wang greedy dina” Pymawise p posgravonieg tan ‘solve an cplimiseteon p soblem : bub somebcmes th gives erporanhial’ time ak af | he it of P no “aif url then solviney he p noatmally tipe con ss a dy homie a nl oe ecthoor i a Lan fo, O(n), ox Bhool 1%, 0 (24), ye wk in o(2), 4 wey Biot to apply erative &3 search (fencing ext ale powtble ways to teach a sola) ® Greedy Kap Sack Algerie A n=; Me DO ft | N : | I ob Job? [ob3 : Profita | 25 | mM | 1S { { | ( I | { f ; weit 1¢ is | 10 2 unto IF Le vie ee 3 ybereelee <5 [cba OURS Vc Lo! Z tte. fend te p et and ocrording to Hho retio ve toy ty mantmiae oat profct in hee Re Pa toeighty < poofet ee obd ie ou > co s ob aos “eg | 20S UO idiing ewe wOUW) 0xd lex 1 but thule compu 7 the pace ob be a compared to rterotiv ; et prept value ond 1 Iv Knap tack, a (ou 4 find 0 cet ae on a eh fa tn fe decor. order of thee ratio. : | Y a pe reow ton be ampluvented wi eration, it con . 4 ( be imp luvented pel AreLWLACON. / ¢ m=(S, n= Date S.-C. Greed Knapp sack ft + poofito (mia. tho eG LIS 3B: 1 for LP ou compere Pi, Be 5% objects in Aecreguing order of P olnlag) = ma : ¢ w fos tel bn okea Le { Ge is 3 3 2 (SH, 6/3,4,214) ¥ (m>0 MW acu) t web pep eo eC) Me MW 5 p- grote | + 3+0) € ow b- pt ne 3 i -. Tine ripley = Olw) + Ofmlegn) + Ow) +0(1) e O(wleg n) , &, Londis Len, NOTE? We con aloo wre heap in order to martini se pao fet in Knapp sack proflesn. Maye heap Con be ured and tive , the element ak the roof neode to Ie Moleted a order tb place @ inthe tock The elements wn the mor heap wel Po OY Ogee ot Sh But, how to Ke ll pa Hine oupleity of O(log) i fe wont cane: IF ten ol elemert of ‘the min height Of fhe Reap, Be complet wt be les than O(n lagn) bud Wp hon adb womplit binary rte then comblouty wil — be 0 lena) tohich do equal 6 O(a re, how 9 no advontace ao companod b sorting ®& mets, ness Se ee profit ® 2 hos a 4 weight { Ur ed Sy OS Vio Orr 1,4,3,5) be] m= KUKBOP Fe p-e4 ietos +4 a eee Ly | [2] Nore - Gf the weights au some, we con sot thew iy order NOTE > A-6O oso (0) b-O | ped Ge b-u0 (0) ae a c- 10 eed c-$ io d-U a at Cit oe NOTE Grey Coles, we con abc do | eentqusly encode hacen: (101101110) Fk mmc “thed, suppose Hf ‘a! vearto with 0, ne ofhen chorea cher shoulel chard with 0 likewtu, if ‘by? w ‘ID’ vo othn chocoeber should be ‘10’, Belo -eoe ty Send | feud, ste ercndling > 2x160 = 200 bho tertalole ste mee g® 2 boxe Gons) +60) sxe 2 SOFIOFIS EIS L 1 1 { ( | | | { | | { | 1 t | { { | { { 1 { ( { ih | 1 = (Obs { Texefore, wrtng untfomn encodi we get mox ne. yg isthe e Ue ‘ wal nen- niform encoding ue get bar no. of ety cen fot In on enfo am encod depen on by pegeney of ary Choracker cho the nod. of bite fv hod characker = Heffanary G@ding 4 av rithm cfuch in wed t fod the coder wring Mich we con compress Me sxe f daa. It in qe to gle ws beter results mn tewwo f sosage Methed 22 W= 0 charactors Sez.) TeFal no. of beta = b=61 (Soxt+4ox24 15 Hs) Cz ©00 = (Go bus A=001 2 ‘A o Bib/tharacter = & fqummey> 5X3 sK3 zhe diskarce from sock. [sk3+5%3 Fox +50xI)— Weighted, external Path length Mdthod @ + 4 f Bits | Characker, = YOX! +30X2 + 2OXS+ SKY FAxo aXe loo = 20S 100 = 20 | Huffman: (€) £ fi ee Nz 1s fC in seb of all characters 45 Bi | make a min heap “9 with o — [60%] ce fox izl tn-l =; (allocete a reo noes 2) 2Uf = 1+ Extinct -min (6) Of Fhe | y= Extrad)—min (6); Spey Cpa ty Pegs Gi) ~“nnerk-(@, 2)5 acho (futrect-min (@)); — (1) i oO (o-) 2g w)=> (reg ut) @ CoD n)—> (why ») 2 @ ad) > O(w lon) . : Sa leue Co ity = O(n w) , ohich w ecbyact-min ao oe ee haa highest olus if tne Bo eee is Re y ie he AO Eman welt te O(S) Sh ge Set re, we have a. pro rato. ee se, ie ot ep Bub we hase : to pul ouk ond arrange ain fn heap. in co nek fake Y(t) but aoert iv ee oe a” =. Tove_lomplurity_> 0 (eo) >o(w) he in Ka pseu prblenns Wwe eh Co mb py ‘puts ih Buff war coding, We have to & aot a arrongp | Hem back iv te list. Therefor, fox (nepsack problems am ip wed. ee toding saiegle wp wed- 32, 132. U) Whi the followin to Oe Ler wor code for du letter a,b : yy fetlorsng f f AY ©LO,UO, NO, WO, HH ©) 11,10,00, O10, ©8t, 000 © U1, 10,61, Oot Coot ,0000 @) 110,160, O10 ,O99,,O0t , 111 > a-@n7y 16 ba DS eT C= @12-S% | 100 1X0 d>c-2% | 1011 * €=3-437. | 10 100 DEES f= 3-I37 | 10 Lol (CD Rab io the ang. lomath of the jwrred, ono bh quution © @)3 G)I1AIS WIS LAH1-439¢ (e) > SOFSOHST-SH ISH IS CIFIC GIS SKID KSB 100 = 1-93 Bit/chow Ang. Q. “rato ee atl! ow 23 4 3] ae ae ke oy, who o= Lott (22 10018 Lz 00 po A eke tet eee Bho Dy Seen ean Se LOS aU es waite $201 Nowe : 9b nob be abooye a code, eat Ae thea dinghe bree and ib w af ae L & Top sa wth deacdtinen- (Browne and, Pound Probleen) OTE fhe Jol outh thy Reghuot pape ar far ao porte bub before tty Avaclbine . Buty Je hao £ unit of tine altoted CAS rain TD Oth Z d Suc. t 3 ws . : Ch e te] i ie cc 10 Gaw chery -. P= 1048 ot Z IE mein Ola: > \aSeeregSs (Ts eT Pz 140+300+140 + 120-4 200! Thfal jobs fe be pad 5 = 990 manimizes . Tewe Couplentty : $f thew axe (w jobs, rooting hao to be dene fest, whic welt take @(nloyn), Thay, we ed kako he jobs 1 by 1, in ih, ancl , He Aradtire of the fal al Nee fer dae lot In work da @ May howe ard oft 'n’ oll. “Therefore, ps ww jobs , due o(nen) =o) ti ep ' " 0 ae ays Ss e fsery ‘ ' f p:|200 180 MO 360 120 160 to yee! pe forsee) “Tefal jobs te be placd -4 =U] manimioed Woh > We get dratinwo Carper than the ne df yobs ovcilly a ee koe high, ae read rob cwate thal ' be quay. We tan work oo, wb the ro of jobs & Wx than th § highest eadlint » thy we tow Cemik the sire of the acta ett, no. f Jobs, which b “y’. ay (Fb YR EG ER Dp (Se Vor Sger Ie (8. OPS Tag 1S Auadline| F 2 Gaend) y She. 3 3 + a Sin 6 Tiel js to be placed = 9 ‘ala elalalal) (Gi Fq Fe, TJ, FIR) p= gotre4094 10 H+ lots @Optinal Merye patteranr The aw 3 file wet differnt no. 4 coed weorls in tu te have to merge them in such 0 Hal the final recovd tonbcrnn he sum of seconds of all files an wrted Order: (éQ ie flea > a b c M vetordaoLB] [28) G5] @) -. No. sf fee reid movemuty = cu pr = 90440 + 30 =O record movement , which vo alec equal to artexnal nodluo NOTE: We fay to fond) the animal) merge foster. toe take he Cenak frosehle fire fond we rmucne than, than ce take he vert lect posible fer and mucgt and, so en. Sash tke thy Yuffinan, code: Hin, we aw no ieroded th the Plecement af te noden, ante foufisar code Ot Rl agclen mie Mab SC) k 1 onin extract = nay dane fv ~ =e Rete ee Oe. G Bb os db ef NOTE = Here, ee are Interoated 5 4O 10 I$ 28 30 in chad is Ov pfaln. ef yerord movement, rel ta thy Placeonent of np Aor. ¥ ~ Tefal wp. of record = (ov) + (sx4)+ : movowent, (253) + Hors) + _ fo) + (20%) _g “146 1 > WHCOFISHIOFE Nore: The fely wtth (us no. of records wl fe — moved more compari fo fole with move = ee tea ee 59 Bee |® Trdroduction to forwing Seer and Kirche “Teprem= Nore = 9 Ahi we abwok F edge edigen bekreww nodes in a qaph, wernt Ch we eee: ie bekwecn 2 noctes Sf hue! ae no 2. rey nodw, ik nell gsephr, vi 0 0 ‘ Mi edge Hs wf gop 0, Max-M, » St) © Genk Care corsb iyi z O(n) ue. mate € = (VY) .wluu ve verticen, F< ~ edger. 4 APP lying log. on ele siti, We get ' vee (lo) 5 a oe a The am 2 2 f qe bard on edger, @) & bted | ed CO weight - ()unneiginted, eclyer do aol carry elyht Spanet bee i a face wed connect aff the 2d vertices of be rope. oy mintneum no. of edn. oh ile NOTE = 9t far cut Mot He minimem ho. edly in wut. Sn node, fo conneck all noden ir always (ni). Te Jing Jone in alin termed av the ceab graph of the giver ae Lobelia hina ty cohicl every rod har @ nome: HF He groph io complete, ie, af i bao tbe 1 hay te no. of Ie ee ae tee, ne no of nodin q Ki =a ae 216 Yr cane a gral io not cow let, he «ne. anning freed aa recluced - oy. ® pe 7 hab. 1 Ghee 7 alii rang the Ard. to find out te no. of spoming em 0 nom complet paras Fe et tit cen makrin of onde raxn, toh nip He no, of nodyo in he gph. 4. ifeo1d In Simple gropho , Ye diagonalo S10 0 |. fom any enbote uit te 3 Roches Rules We need) to eu 3 ruleo to the ee fo-cency modbrin- ie, D Dingonals 6's to be rePlecodt woth degree 6f the node GQ) Non dicegonals "s @2>to fo rep raced with, 2-1 (iit) Non die OS to be sptaced with, ‘Os! ony - he adj mols now, NOTE > Te ee of @ry node in cam of unclivertedl grape io Ws 20. Seed es Snes frcidentl ar the sode- thw, (f2 04-7 Gb ho ata Ponti las 2 | Om d ch ct to-fadox of ay len qi he ~1 @o- factor cae 2-1-1 DAR 3 4 yore: je CO dk My alk Fast * Tew axe 8 bal 3 bs preserb in oe 0(4- 1) 4iC3-HC4 De 4. @ Ey TAM 11 M9. | 2 16-44 | 28 WD. 7 Re eo) eco eh 3l1 1.0 Sade clas han 3 “ti (9. 4 (a —_— eute > Cero truck Am, Repose bey ee ce -14 hes, G -(v) bD % d Gfaclor of Cut) 34-1 416 3-0)-1 C43) > O4-y-y 216 Bro, Ov, Spoxnt trecino, SE a> Neen mnk caseral co a ae @® Minium cost Showing Tree and ex. or pats algorithms We hose to Find “Be Gaming Aree fem Gu raph hot kas minimum cost - Gre meiod 7 J rv Ror bi sean ee cy alr file fos se Tee oe 2 alee. prpoxd © solve thes problaw > @) Prt ftgo. © Krushtol Atge. @) Prine Algo sethan ABS. 3 Lule 2 On tO te I er aa \-S) 3 I I 0 | SO SSeS G) Post Ache the mints cost, les 2 nod of a < get) Bafa edges of Hu 2 e cho wv edlgen and aya ey, mininnune O Aacin compan adja edge of Tus qt hit edger ord ik den @) do Hy ep (Wi) wntid atl ee roden aw 10 ovwad- a 1 OH = WF+2EHO+ IO FIG +14 Pic He neighby wu thr ladt wei os We J at oo 2 edge. To om sedge thew should be only 4 focowiung edge.

You might also like