0% found this document useful (0 votes)
34 views

AA

Uploaded by

Santhosh B M
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)
34 views

AA

Uploaded by

Santhosh B M
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/ 53
Dote mae ED Page. Etherenty p ime . Space T | Time complenity depend on t= » Togut ene I a> 2a bik or Gu bit opacity 6b poceian ay Single or multi proetising J Algorithe for addition of two given numbers + i v Algorithm Sure (a,b) UL“ compute cur of given two numbas i topat + jwo numbers o and b y output t cum of o ond b yelurn. atb s total <~ ath yefurn total Time complenity Be Lis 4s “Teum = ag ie constont time [Time by LYS *s TH ath -----5 2 unik of Hme churn fetal uni 3 uni Tum + 3 units of dime be. conctant time TET q umber ¥ “aad int of gum 1 she jdolourrbes (an) ee ule gut wen [ict af number * i elements = if welpet cut ot tet of 9 numbers fi nt dojo! 4-0 te ee ile oe otal & jotal + oli) 7 ydayn Heda ee a - te ye > Cost 8° eee a a Ce — (oe ee tonal a Luni Nd unit unit by doce | Tiotol« toto! rai] 2 unit Hi | eekare total) —>_ Luni 7 SS = No. of dime St ereceten= a cee ip torel a O ae i by i eo to a7! = nti ait cerdition T qetal @ total taliJ—> 0 i 4 vdurn (tote! “fctusl cot? total time complexity Histcom dvd ta(nH) tan 4nd + s dtont a+ ants ae ALN Ta f cranjps tf nis ee Ne soo, : = 4 tyls) SH +4 (Sc) = Oy = yraoed f = 2004 i i compute sum 0 pote 14/42 3 Page 2 Alger to “cum of matrices t- — {f Algorithm umf -marvices (A,B,n) { given two marr ices of cine nxn t JU 3ogut+ _morvicer A ord B of cine 0 Cum of A ard B n oulpot - for 420 +o 0-1 for jeo to ot cele Aly jt Bly] stun _¢ ol] Cock ge po-0F times he 420 to n-| —————._ 9 n+) » ba yeo ton) —— 2 n (on) » hile < Ali t eli, jJ> 2 ovo Sl ghana 2 —————— > tt Nembey of mess > nel > atn#t) By open aly of cum ot. elvices:- 2 Time complexity “Tourn ot = matricet 5 fo xtor)]+fa x nidnel) [-talnxo) +24 ondat anrtant ante t bn? + 4N +3 Eee 4 =e linear €qUeHons a une | pas un? eh, a pa nee - ie Actually conctonls ganeed not be joker con of yon’ Mmeors aekeal values of conctants clo rot doties Yee cute. qust tobe _conctont volun. a Cl C2 ete. x rtling oem fhe cod oF Sum gt malice s- Teum-ot-merrices = [elo EFreloT ‘fo (nxo)]t Cy xi] = 10+ + Co(n*en Jt me vl EOF CG + Cont Qh t Can tly = (1G) ni t(Gt@ Jn C+ Cy) a Order Of Growth: Iaelot +The order of growth of On algo is an appre timation vot th dime required fv? Fee _Lompulty pregram at fre input-erve oreo, i : the order of growth fqnores the conttant THackoy needed’ tor fixld operations and Tocuses on the operations frat incre ate . proportional jo the Input cre, ++ t _ Algorithm Por Segue atial ov Linear Ceoreh : [| Alqorithen Sequmtilassod CA,9,k) 1. Storch the vet ocenrvance of the key element t Sn an array Wtoput: An array A siren key element k Wl output + Print tke gosition ot ¥ offen He ly ie 0 cpl 4 * okie AL +k and yen dela G)| n+l petit al)|_ 0 gf 2 fe3 Bote 5 45 Tots Ox3 6 | ies BY oct +6 x24 Te eK atk W Stet: sure a0 7 Tee ee Ae: al G if a Or Gale) F te(ray+ OG =O 4Q+ Qr+Gnelen-G+G = (Gyele)n t+ Gt Q+QtG-& kt Cyto eC ond GtatQ@tG-Cs=c! | [Tot = Co +e" 1 «Worst cage t Cote! * | Best corer © obey ( i) - = 1a] 23, yi Classes of ‘Tone tion a “Fypee ot Five tog Na ee Sy, aa constant time or conctont acs f > IIneor funetion 7 _ rie quadratic Function a cubic funetion ce i fog a /logavithete function oe : a — 3” b> exponential Runction — ie : 0 E-nty 2 log 7 Ls 1 t I 0 2 eae gE aa 4 | ey 2 Ib ——— 8 | ey | ar | 3. | ase ~ Ue | ase | yoqe 4 Lecsse — 32 | oay | aame | ¢ a 1. le a MIeP ¥ | Order of geet ot diff time functions : | f hs o 7 jaa A ae 1 . oa 7 = 7 i i “et T oe | a Y A> minimem noed time the alge — Asympte ttc Notations t- epg € | cyecuter s oboys £20) Ch) > proximum na. of finaes the vate hy = algo exeeter — order (0) 0-7 By oh > upper beand as omega —> hower bound G@ — “Theta — Average hound % Sequenti al Search: 7 Burt cox Time Complexity + Th the clement ic! present oF the firck place fn athe list, : | The time complerthy Fo ye 1— > conctant 7.6, 1 Wort Case Time Complexity + TE the clement t not present in the list, T The +t ity? 2 The Hime complenity Fs > n+1—> O(n Average Cate “Tine Corn plenty 2 - 4. rata tot... to 2 OY. n+l 0 if 2 = 6th) @ > Whn oth best cose and wont care Ore Came oi fale ==> | Express athe follow? fisndtons using. ‘ipl retatiod I D[ FOS yn@eang oS S by) 7 Yynrt 3n 42S 6 prt 3p tan? > Finds 9g xn» i yy nyt 1 4 at) y [ {o)=. off) ~ nde 9 alway, He <¢ xq). epueet Tats =p [itso fof AG gh ay Fl)= ywtin+o uertant 02> 10? yay ane da Sl Fln)= nn) iG * 9lr) S $0) = G raln) 7 ae 6 Gb) pee, 6, DW Leos fo) loan a oe “3 Te ans! a is a 2 ¢. 6th =| o tin) = 0 G@ beqn) | iG log nh he F[n) = cl logn +9) bea 4D Lidice roar Fa | — D+ mlogny 1 * ne legn v y c (n) [oJ = (leg n) g ¥ qh) fo = Gx gl) 1 Le Mlogn = Te) <2 ene d Te, | af) ate) oy Tle) = 8 (a2 109) | Fle) = (0? ay" LO)= off Tole) 1 » {oo Dan vox pat case Se ze ae go) 1¥ 0 Ene 1 = Fn) = Lata < fl) < cox ght) | v. [tv 0 < {0 * that hovld get fn): 35 gi ses get ee eel), ~ el ~ fn) = o (ns) : L[ey= 3p"3" + n logo a0 Baa 4 nlogn > 1¥ 3 v c Ynys on Cots) ¢, aap edi) ss _ 6 rh) V 44903) 2 tly) 5 Yan's? [it = 6 (8a7] a 60") = eth) 1S wrong, oie eevee ania te Waite ave following Ymequalities endicale | that Correct ov not. as O(n") < 0BW jake lng on bs re < log_3° loqn Nog 4 fitgnt ame Batt ard wn nbn con) Tt ts corvee [_* finalyiss of Reacurvonee relabioN or T Reeasive Alger ths U Algovithe at (nh) —————> TO) di at (050) piatt (4 [ Torte: a | } : Recurwence velotion + - ieee nz0 [+ ot)+2 nso qubsi terion mnetheg ol Time cemplevity by ‘ ' yy (on) = T(o-1) +2 Ane ae (ily pho qloJ= [rlna) +0322 nae 0-3 a(ny= Tln- th 1(n-) A (n- aT Elna *y Tn-3)+h tn): T(n-1 eo th): aie 3)43K9 Tina) -t(n9) p> : = 3tP woe be ay ot Nps he continue kl -Aimes , ae Tiny: 7 (nk) tak a mhun _ 9-k 56 alo) 4/03 nek : T Tlr)= T(n-0) tan Thy = ++ on Tin) = ant Fa) an) gpa 3 2 pote 24/7, 23 Poge fie complex ify S| Aigothes Ted tn) —> TO) Tose) { qo [isos icny w= n+l print td ( yd" Oo); — An so ect (071) 5 — Tir) Flnd= Tha) +o Fol pad) Tin=t(n-1) Kant) ara mer Fi DAG, ais Yo for Th) = TiNs Ss A f wey) . Recumance yelation? = [ay = Jot n=p | [tle +N Aso 1 Time canine using dubditution method :- a [att 0 Prt Cra) to Ale) G0 qin: Tt (na Jt ana > (a2) 4m = TY 03 FO) AINA n-9)e CATIA = t(n-3)F3n-3 ~ ins tina) eT t(rJ= Fre") an 3) ] 139-3 Ain) = 1 (ou) + (n-3H-2) + (n-1) #9 continue took titres Toys Tha [nC Oe + [a -(e-3)J +9 phen a-k =O ik, n =k Tn)= t(n-n ah -)] + [0- 2) + (f-ha) J +9 4 41 4243¢e-- $0 2 o(nt) ' oe CV tbe oF (n)= IH nt Q T(n) = on aa iHiads tom ates Seienee always assume 169 bow © if Tots givn thn oF tog iPiF AS |. as,q7a3 not _bwnhoved It is candenctood thot > Page pa Nah 1 freee com plenty Atgorithe “Test (n) Jn sTt) i (n>0) — ot [— 7 7 Br(itt; ten; t-1¥2) —> fog +) v gntt (hd Wi Ign tat (n-1) 3 Tr) | Tn) = T(n-1) + alogn + 2 hacia #7 g 2100 ato)eatn) + Tog fey t=) yin 4 y boy t= ‘punks for joy prin § =B prints & bain 6 sss ee | 2a|2 R ele =a rints 39 fev Fegy prints 6 fov 7 =DS —S exits Recurvonce velation t- [T{e) = fa N=0 FlpayFteq aso So w Ned to englicitely puntion ogg, 25171 R3 on -bosk cm Time comply aang cub stitution methed - [t(n)= Thr) + 1099 To) lot lege ne nel T (= fina) + Ion (oJ log Aro) =o-) “rte J : T(r) +! He (n= + [n-3) 4109 (n-2) + log (n4) 4 Ing : Oe a Talis * kK Himes Tn) = 1(n-¥) 4 109 [n--) 4 oq [-E3)y~ Plog n true Tor n-K=0 Le onek foJ= Tn = 9 (f- Ge) pe af a Saye maT ~ + |og0 ‘ee Soruey au abd test [90 7 le ig 0 leg b= ra) ] in b= TFly [ee XN) tio) = Vt to 71 ge To) = 1 4 nog [ray= O(n Tony] Yo pote 25/4/23 Poge Express follovorng functions by_airg ‘eayenplotte Rotation +” DI tle) = 4 nq! | — q Cryo x3 Xe YP) | ig (ia x3 xn) < log (nx nxn a~ xn) 7 | < log io ES ! i Sn beg? ==> tiod= #6 legn) {TY log Cre Kee 1) {. > gtant J(n) =. le o! bya ge eteey Sig Cat) 2 Wy (1x NX yy) Ce cdoctant Tose: 4 fn) = cons tart Tin)= “a Contant) ih)z a0 fie TP =k LZ Tet) th «= iB) sln)- Tint = ote) lo) = tle) + loqn = 0 (nleg) To) = at(n-D th — sclih3 B)| Rigowiten “Tetfo) —> Th) x = at(ps0) Fate), —s th) — i Tels (1-1) —> lo) iz } : to } . Recursive velatton 2- St) 2 ee if nz 2 Tn) +1 if nso . Time coat by backcubetitution method 1- J rte) = ath) +1 tl) = a fat(n-2) +t Thl= gtlo2 bag | : to): g Lot 3+] +2 41 or le) + ai (03) 4074041 4 | poe 26/1/23 | Poae a at coe eee a | py yee : The) a T(n-k) to tom ter tt | dor n-k =o | poor ree ol naa To) ot (Pp)t+o +a +t wea) a i : 4 n-t 9-2 ie =o yeodto 40 +2--- 4 oat 1 f Q=0- | Sy oe oo fg eet ot i Il (eomebic series: J ; rv aT oto tart. tar = aly zip) Tei Ge yD o-l 1. ttn). on (nJ= 6 GV 96 (7193 o Po so Algorithm for fectoial ¢= S : Trane compenity “Om +S q 7 . Algorithm Fact (0) = O(n) if iP if 7 ~~ 4, : rey yon TOD #5, Soe 0) OD ED TO . FRecuscive melted toy factorial t- = LAY gorithm Te T Algorithm Tact(n) TO) — | /Z “computes _ o\ ol veeuncively 7 | | | all | ‘ons en eo Cae ewe cles vehinn Fadi kA—> T(t “E(n)= T(n-1) +3 oe Toe T (ns )+e [Recurrence relation s~ fell isy Sato Fod(n-) xn TE ato «Time compleetiy by using back substitution method +- TO) = TM) te tin): Erna) +c] +¢ T(n) = Tln-a) + ac T(n) = ft (n-3) +e) + 8¢ Th) = a (n-3).43C continue fo, kb” times inde The + ee Vey N=keo. je Nsk to)= T(n-) 4.00 1 Tin): Th)tec 2 Tin): Lane | alny: act! = Nyide an algorithm +o find nth Fibonocct Number + pels fs prisinlieg 2. Yoush Hee” cock 10: +4 ding M Algovishon Fibonacet (n ! } peal nth fibbonace’ num Toguts A non negetive old i inkgel 0 ~ Output: n* fb omacet num ~ Wnt e1 G1) i vrtfavn 3; | Jea @) ae, else - - 7 Fr. 1 Otre nGl (ee ae) Time compely + TFr[ Rime) = ( vi) 4 (ca! eA “4 O(n) +t (nis (ny | G4 tg ttn t GO “oy On - te +04 tc )4 Weigh, 140446 = Custer) Dd eel oa, let Cater: cond . 7 0, tata 's- Ce tC Be [= (Cfibenoeei ) = Gate: a rT ( Fibonacci) = O(9 | Recursive algorithm to find nth Fibonac- —number 1% | Algaithm Fibenoe'(n) ——» ln) I Ting) nth _fibonace num _reeurcively ~ LGnputs A non- snegeti ve Snteqer 0 I putqul sth Fibonacal num eh on st yun n => elect acon FCN) 4F (N28) ae etiea| Tln)= T(o-)+T Ine) #6) dn by using cubsitution method ) 2 make th eqn soe > To)= natin ies aliwoys Jobe oppor vale .n-asas TD = oTlo-1) +¢ _Recurvance relation + - Fib(n) asco = Ki no 4 Tama eT Time compleriy Py gubeti tation mathed ; qln)= at(n) +¢ = ~ 2 for (noyac) +c =o Tina) 4+ ac tc Th) = 9 Lat(n-3) tC) € CFE TUn)= 97 Tln3) 4 ahe +9 tC Pos q-k=o i continue hie’ fim ath): 2° TN + Pe tat t. a Ct 7+ $6 zk Tl) = asd __tet c=! TaD + oO O)t a) te 44, ; (Th): a" Tf) +a pga et eS I tn)ie 3 Reo ae Gumbic, ena = 4 =) a) tin) rj a =a] “ Tin): o(2 | satan coll HW: fhe ° Ni Wyte on algorithee and tind time conn plex : qhen a ore for Toy Pending! prime i Di Nake on atgovitim & ited Hine cate Fy mint factors Wonk the determining Common I orien: uaow ects cof plone nee EE iy” th ae 2 inputs a dss OS | pee 0053 ap +2 tind ime complenity fey Ms finding Idhgat number i given aray, [WS taaite_oh_algbithn ard Bad Rme comity #5 defamining whether de all the dementt'n > o diven tray ove aickinc - : Coal gaint dnique 1 urque clement dye Faw not unique) ae 5) | Kite am Colve the following veurvanee’ veal: ute cubthtudion meted 4-7 ~ Dal) alo) +0 yao): 3th) 4) - 3)| fhite an algo and A) Gores the Pefowng Fanchons using. teeyraptot SF te. notations + i (n)= 3n° tn” : We qt): 3P 4 art al) A= 3a +4 A) Prove that O(n) < O(3%) Bind the firme _complerity ty dhe zi t cum + 0 Jolie 0; Spat) { fotae petat 5 A feito, ep RD gum tty } av . ye? UnzT2 : Review OF ae “Techniques 4) [Brute Foree : > a ciedtel cpuiblem Dynamic Fogramming + PPynamic programming» means that degntiritte oplirel colution can be evaluated Grom optimal colution of its sub-problem, : Cx:- Recursive alge fos Prbonacet ceriers All. powys shortest poth Cosegle mop) t | leu r date Pl A, 23 Page gad. hacking alah TS “Jn Anis: app*ooch tt vies @ colution and on fertuve velaras fo a eampley olution oc the bosts for new aticmpts. fp] ee Preudoker puzrle. — crosword qurrle } * } Branch and bound :- Fits used for solving he opkimisation problems T | and minimization prablerts, . = Te ts aiwilay +e the back tracking | te hnigue where as ft fs used fo colve the deetston’ problem put bronch @ bound kehnique fr uced ® colve she optimisation problem. : Tesi Network —floud probleme BFS t q| Lincar prepreg t- method o: [with come constrot Abs, +P The main obsective of linear Programming fe Moximire oF ‘minimize numerical Value. © +) De censtsh of [ineay functions ushich ave | eubjected fo the constrainb tn the form of linear equation: for tn the Form of facet G1 Colenloting he optimal production evels jo montmatze profi aiven the Yestaetions a supplies dnd punginl a | THis. optimtctng the operations + we” ~ of) | Brake Foree:- 3) Celection cont ti) Bubble tort iS | Algorthen By Selection sort +- Higertthon Selection Sort (ALo.s.. nl] -.. (BA Lf cork given array by selection sort Y fopeks An avray ALo...n-1] of ovdevalle clemenk| U/ outputr Arvoy ALo... 0-1] sorkd én ascending ovdey dev to to A wi hos 2 for loopy minet : n deliniiely fox fein to n-l Hiras compexity : alr): iF aly Jeatuin] min = ah s When inexmnta) value dittere forex + Se Av] ond Alen) for $20 to 121KA tt will be eg on othr forms Pee eee 1 gai fos jz dis 420 +0 ce itt ri fole 4 hut | \ 2 Yes ) Q 3 Yes Sj | 3 y Yeu oa | nals exit tor ‘CeCe Fre ala: \ a Yu i} | 8 3 yes | 3404 No : [ | Bie: exit tov 18,345 [2 }a|3 No | aly No | als exit for 18, 3,45 3 [3 [4 No [ a|s | est fo a cas: 4 Giik. for 1 | L a Time Complexity = 6 (n®) Output t= 18 8 F | sh | Algovithm for Eubble Sa t2= = Algowih Babble tot (ALO) = Can sorts the given array by bubble cor! YW input: An ovvoy Alo--"n-1J of ordeable elem enf (outputs An orvay A [0---n-1] sovkd Tn _ascending oy),] y FLO 40 N-9 ov Jeo to n-2-7 { Woaljtil [I | af. 4y © foro and Ss4y-Ya | 45 3 91 ~t feipoerd _ eno} y $3.21 | ets Fa cliyeed each e a T | “10 [ore and ysya-vel 34 S24 fi x1 |ay0 and = Nol 34 So J 3 2 R 270 and Soyo Ya] B42 5247 L [570 and oo=Yaloa ys 4 r o oye and a>0- Ye J23 YE 4 a) 120 SNOUL2 SY 6.4 4 4 8 B70 Od >t -Ye [234145 2 fexo and usi=ves [23 5 YS L 3x0 and 3>1=Yalorsys Oo [0% and 2r1=¥u [1 2 3 4s le Tl 70 ands>s=No Ti 9 B 4s Ss Exits for loop fixthime it data 4 de 2 than rh Te 4[3 a4 Second tina 9 elim 2 sors Tas 3/2 1 wad the 3 cements © conts Bus aly Sh hes GY elements & cov Rau os Sh Howe 5 denunk 2 sorts 1S oe Qtputt: 1 2 3 Y Tart 7 ee a Myo SS [im Ycore —~ Im vy sJo RE i ne Pyare a 7 [M_o Syerle Morsye] — EM oRSY — D+ | BES ond Dre ie DES & ie @. Qutux e a eT eta wo- BFS Cponnig-Wee EE a, | BESS DES 7 pking | ey 5 3 2 ah ant 3PS* Deda Ctructure ree visits 194 S73 O89 a Br Fs Ps Cu, cfock chudtot Stosting nodes L Allg ovithmn DEs Cy) LL ep\eroent O_Axpth- fire cearck of o Given —Syarh : U Ul Toput 1 Groth og = @ 9) Uf Output , ubpad Graph G with tb vertices t morked worth consecutive integers fn the order tay have been ict eNCounter e, i nteved oy the DFS 4roveral, d mork each vex in V WH 0 Oa mak of _ being Tunyicited” Coum, <— 0 oy each vertx vin V do ik Vv ts make in Vag { df: Cy) dfs WV) evisits veeursiv ly all the Unvictted vertices connected to verte V by a path ond numbers thers Inthe order Hney are encountired vie ge bal variable eount. caunt = count + 4 movk vowith count for each verte tn V adjacent 4 y do \ if w to marked with o 4 3 dfs (10) © my Dato chuckuwe + Stack gtoting vats 4 outputs 14 310 GIS Say Spanning tree pote 8, 93 Page | Bes. algorithm + Algovitho Bes) UW “Tmplernents oO RFS travercal ob a given grenh [| Toput 4 voph G =(v,€) L Oulput * Tod Gh vertices mosked voith con cde live integers fn the order hey hove been” viciked by she BFS tyavercod. mor each vakx in V with Oat a mak of being “unvisited.” could <— 0 foy each vat ¥ 5 V do yee iFov te moked vith o {bk WH I bec (w) Ue viet oll unviciked vertices connected Fo vata _v by o pale p ocsigns them the | numbers fn the order they” ove Visited via glo) variable count. Z v count <- count t 4 mark. cunk vy with. count & Tibi eThe @ queue with Vv while the queue ic net empty do 1 t 7 | \ for each verkx vo 19 V adjacent to the front vertex do \ a if wis marked with 6 count < count +4 Mork 6 voith count add WwW to We Queue vernove the front vertex tenn tae gueae 40 fo clructures Quewé rio Ly 235 7/8 09 6 ¥ 1 el) Coanning vee t— f T J Fo» adjacent matyix Foy adjacent ict 6 v vi + ler) ate) i U al s]az ay Topategi cal Berting Tordertng el We compulcorily peed . dhvected ‘graph. [ie ie Not “postibie to cot 9 we have | ey clic directed cyclic graph. 7 fo «| Dedns Te is on \ineor ordering of the node what foy each diveckd Vedbe Gn ao direckd acyclic grap (PAG) | y hodeA 0 node B_fredevl_appeare before nodeB tn the Ordering, a \3 | a x (NOTE a ol] A ror ghould be diveck oayclic_qra Bl evety DAG wil_hove oFleock one -thpofe 1 [ DFC bated 2S Couree- removal metred WN] DFS Bored ¢- Ef a ont eho cy he nied tev dvae eS (4 = ) cpg arew cA a Airc cee, 63, 04,65 Cinclude all nodes sovkd ‘o palogued order), 2¥| Source removal :~ i> Remove co C aoe not having inceming eda ) ~ 7 - Rerove ow i> Remove C3 @ | cS) ws Remove C4 V> Delete Ce : c Cyc Aas Ca, 1, C3, Cr, roll? + golve by froth BES 2 coucesac sy Se 3 t basef ¢- Ans = J 124 365 U 24 63 Source removal ¢- delete » delete both 3,5 (bez looth’ ave ‘pele pended Anse 1,2, 4,35 or 1,2,4,53 Latgce Ang TE is a divected cyclic graph. fe “Topolegicol sorting S' pot ‘poceitle. lee) J t D wi (8) b= 3 A D € u)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy