Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
23 views
Algo Lab-1
Uploaded by
Joyshree Misra
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save algo lab-1 For Later
Download
Save
Save algo lab-1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
23 views
Algo Lab-1
Uploaded by
Joyshree Misra
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save algo lab-1 For Later
Carousel Previous
Carousel Next
Save
Save algo lab-1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 32
Search
Fullscreen
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Name: Soumya Now ds Student Code: Qwy/ATH/2t/ HR Course Code: PLC ~CS M440. si. A Date of | Signature No Topte Name Experiment | with Date Trsexsione Soot algosilim| #0 /09/2023 Reo wi qvaeag ogc 29/02/23 fae in aaag DAC 06/03/23 Kurge goat. weed abgor-| 13/03/23 Fradhonok knapsack | 15/05/23 Off Kmepsact « 15 /05]23 gut k Sout 29/05 12.3"|| Bs potimend i d Mote of CG pop fe implement Trsenhon Sont. Alo visite puedo code olong with Hme & space comptenity . esoaeet gtinelude £$tdiow hd Void main O) 4 me ny pint CERO the assey aize + w')s Bont Cd") 8); nw paanth (ER fd umber) 5 ind ose Ded, 1=0y Key 95 fox Ctaey tens, TD | peand CEH” VAMETAD; hn Ureos tens 1) keg = oor Eth 5 oo . hoe Lipeso ae sno 917 FY) WwW Pow Ciao, tant, tet) print? (red o> as Ct) sPa uedo Code » boo t=o0 Nesey Kege atid yea @ whike, 75 lie 4 Enter 4 nan POS 39 ao MW Wy oukeuk athe sosled offery Ht NW 5599 WRrcalyais 5 Tame Qomelerciby | Suppose every Une of the code requineda 3peuhic Hime to envtnter Lek oxume thod Hrme is Ce. \recosioding fo He psucdo code, dine O Y durning of pequbad B (ere Hme. Sethe Hme | as gre @ ond LineOig Huwping Foox ret) Hmey . Se \ thee requined Br Cert) and Cgth-') . fe. how must Hrme \ i oe, fie tenet & One then srequisced Hee 3k we considar he worst Cost : \ oe iB ee = nos aA eee \ | Tre can neg teed % 1 © ans ure © B alfo smning Pos nt Hees. | ¥| Line Bw (Oe a ond Ce We ; | So saequined Hone | 9] Line @ i sessing. FY (rey Hime, Bo fee METIS Mee oy OOD: lo Be ee 2 (gine Gate tea) | ae Cy 4 Oe nrt Cen | + eam) ce pttarts tes) = ne © we wow negieed ceri | | : | Center est Ca) | amd L&uets* 66) Ube yep lent Srcae Se fhe Tela fime gomplencity ig Qont) s Pace Gomplercity: | *8 we ade Uting only One OBO 30 oe SPACE compbercity wit be OL) Ceonslant’) . Oukeut © f\ | Rowe = \ Step | | (« ey a sy ster’ ali | [i] — (w= bol) Final oven +Alte | Excronime nt Ve ge inding Minima Md Mvimume jr an cere | Petagnam: {a ine lode &StaioshS Void main oy inky, izoy ; coy \n’) | Poinl{ C Enter the Size of ayey 5 Soonf Cord’. 8s = int ofr), moar = O03 ymin = ; in 3 eye nl )s Patintt Co E nelese the ehemend in avg ) Pos. Cisos f4n5 fee) grou (yd, abil); EES Por lary idns i++) | ; if CATIA > mare) es mon SOL g Zh - Oe if CObia emi eg min = acids $ 3 Y finimum = hd “SD mene, min)» | Parirelf (" porimum = fedBram seock'g Neo | Oulpals Ender Me Size of the away 4 Erden the tlemond 99 1 4o 60 Monimum = 99 Minvnurn = 1 Psuedo dock + ) Mane pins ale Vhexceary iqavoageize s i++) ) if caria > max) / | trans OL Uhte if CAT I
mint) awn = 5 3 3 3 int ynain ©) ink ty WES Pont? Cw Enter Hee size of oseery % 2); Reonk CO Fd", {nM );, Pants (SER er Fre number + Ln"); Poss Ci aly igenemy ies dE goon Chad”, RAEI F mons afer) min = ACOA) sprayer, C12 RMN) 5 parted Co Mordinns Padre CPL Clement in the asucy i #4”, mar): ehewent in the covey ved? min): fetus 0,Ente the gtee of the cows > Enters the yumbety : eco (oo yoo sD 90 800 Mordwnumnre element in the aBeey, Goo Mind elements te the BY. 50 Jf1 Patudo cole! minemoe CA,1 5) Wo Gte=0) min = WETS mone = ALI ete f Cis =s-) i CHETAN ew) vin © AY moe = AEST eb§e min = Abed yro= ALI elSe wid = Ctrs)/2 PAC EA ts mid) DAC Cy widely 3) WS Crmined rind) pain = WL alge min = miy — i€ Creo shox) yoy = mor! eye + save = ROWTt 4 - Me Complerily and Space Comphenily { ec Faom Li to ty i wilt folke a. comlard Kee Jaq ond has will fee T(m/2) © t(nyn) sospectively tia and Lig fe dos fakes [tt =2 go, the overall equation 3 | TO) = 2T (yyja) +2 | tUry= otin/2) +27 O | gupakitare 2 place of n in equahon® | toys) = ar Mb/s) +2 | = ay criy+2 7 ® | Subakibuke equakern. Gin equadion OD Thy) = TET uy) +2) +2 = aT Liga o> @ ae subaktute equaken WW) in equadiok C) 2 4Tyy)* ae ; aS a Burgh tute equator iw equakon © ws n= ancs TH) =40T (ng) 2) rae 2 ae = ot (yg) + gr ee Aenlying 329 on bol Bide stn) 2 PT nf?) + 2a! Sogn = Soy at) * ghaats ane a = Kay Legit = kt ke Sogh!(cr | he kK volus \ 3 ‘ ZS subsktute MW equation G) TOR) = gon TONS = BE Cy op gata ety ce MOT | = athega® a Barra r SOT | Wow. using se \ Ro snnhors > io) ath LHe | pease = nr Log ewer So eae leqga-b = aS D gadeada ----+ 2%, otra) oe 4=2 heconding te terumnbos oo o © Ww tog Es 5 > pees) he \ ee mp + [2S 3 =| Q ee anes eae {/ es = mae 3 a) Yale = yn ~ [gta 23 ae = Waen —% en ae gn -4 so He = Be = ett ao qo) = SR ocx) So rhe Ree tom phe ity RS) &):Erpeniwend oy Merge Seah usin @ ao ainas a JS, And OMI Tee and space conplocif. Legseoy Winelude (sidie.hy Winclude Corti hy vod merge (int wt, int fy ind my ind r) ° t int Lay ind nee medal; ind nes pow; int Lary, PER}, jf Gis; fant, ft) | Lrg san Ceti; Bow Cg e053 dhe gtr) REG] = oteelmt ie F 5 f=o, 326; koh; thle (rn 44 T Snr) 8 7 © ip cin & AEP t aulki ATI; itt s 3 eke age CKD = AEST; dtr 3 kty>— While Gi dnt) no atk =potl: LOA | Ks +5 a while CF On) § . Ce a toe Ty katy 3 |* . ca, int 4, ind P) Void merge Sost Cink ola, t ie SY) @ ing Meher mL) /25 mega Soak Corse, Lom) 5 | merge Seat Cas Wt! 2v)s ve nee eer ety ae J 3 a void print foray Cint ALY, int size) ° t int iy box Cro, Po aie y j++) painkf Cod”, Abid); pain FONDS aPA rein 0 1% : ink osu FA = % 12, 13, 6-683 2 inh a9 -A1ze = sizeef CH) / sizeof Carne] ); Faint Uoiven atray bs wr): Paaind Rocrag Comes at — size); wmene Sot (a%rs 0» asmr—siee—1), Pacwd® Cw Seated asmey ig Ww"); Paint Rowe y Coser, ase sine, Attu 0;a et ee puudo sole: Weoege, ook Ci) ne Length Ch AF ORK 2) gcetogure — wid & WY/2 | Lett & aseay of size imid) \ ight & asawoy of ize Cu-mid) v| bes. i 0 Bo mid 1 ba} kePR TVA NE Se| Pos {= mid to n-\ hy Sight Ct-mid d+ Avid tre | Merge sort Cae8t) An presage gost Coriaht] tral mesgegankl del # sight, A) 3 Tine Qormplenity: ge XL, te Lg have Aemwined “Gi ammount ef lime fine Le fe ba one exceeding Rx n hime, 40 neyuined Fime | 4 Ga.hw Sine Lio ond Li HKequisced of dime. ae TO) TOU/2) 850 ammount fud fine hia nequined — Cqine CH ormmound of Hme8, Tokal Hye. 7 TOY = atten Op) t (Cate) nr CoytCa) Hat (np) + clr ec! [ Lek Ceates)= ef, Gate = C7 fgein ! ton) = oT Ova) *CR eo atin) + 3 +h =4T OM) + 26'% ce g atlr4) Oy Fa oon Het (vg) + 3eh = 167 OMe) + acln wat (rfss) + eden | Hose Zerh OK =n, = Ka Sega h => ah cy + hoggh COR / f= hes ec whoge = 6 Crtegr) / TE ye. do nak qeate elo enctoia memory Pox Left and sight then, px toghe = 6 (mtog nr) H we ear enter memayy in each call’ nt Nar Myr ot Ol > om Gees dag on) AF KS sO) KAR, —@ Space cownelenity + @ cn)_.|_ Ew periment 5: — pal en vo eae Waike a pstogsram nw do poxdosem, knapsack pstobLem Ayo waike pseudo code akong wih hme ond space Cormple eiby . =| Codes. itindludedSidio-h) ight fa» Ptook bag) § , ak weight £1) Void knar Sack Cink rn, Ptook pool FT Ho Pjook 16 Pride HO des de=bag + in ty fom (=o 5 1dny itt) @ : ETA = 005 if Cweight L71 > bog) e é boceaks, a Be @ peri = NO 5 Ip < tet poogit [115 bag = bag- weight 11 3 if G Ary @ acti] = beg /weight iy lp mip = Cepia PORETS J;sien, teh oe,” ope . Pats CO Your bhen Clement veehess B ¥.2d,", yr): b Beek (renter Pe wondered element s\n"): Seont U Rd, EN; Etoak ag. poodit DM], weigh Ont sake [°3; faint? (Senden Pre bag capatity A"); Pe Seomd (" ¥F °, gig); Pamtd C Enter the weight and prod it on #d element ch” 2nd: ka (izes; ign 5 it?) 8 poof C Enter He weight of element rd ih “ott )s seam CO AE" A weight FIT); Paint? (Enter me PHONE od clement ed 71); Seond (or $7, &xeke FIT); Sako Li] = (pxobttl7 weight Li 3Jor (ino, wy pre) ° fon CB att, HOw, dee) e Ep C melio PET > nalio [9 1)4 leme = stio boa; golio fey . xolio hits walioE tds leme ys temp = weight £3, weight FW) = weight rds weight Lia = tome ; femp = prodid £31, profit PIA = psodil pia; peoht LIA = deme ; 4 kmapsack (nr, psofid , weight » bog ); Soutpuls Enter He number od element : 8 Entes. the, bas eapacihy 5 3 Evkor Me veight and profit of 3 clement * Eno the weight of element fi: 1 Enon the profit of element 1: 1 Enter Pre wetghk of clement 22.2 Enter pre profit of clement 2222 Enka Pee weight of clement 3 14 3 Enter the profit of clement gi 3 Toteh prot i, 2. 3 Youl. token element veel ig LO 1.0 0.0 aI y Psevlo coder fox iat bow | do wet so weight “0 WHIe weight 4w do y= best scemmod ning thew 1$ weight + WLM dw hen x CHT =) weeght = weeght + WET ee we Cid] Dh werghh) wei) deem weight = w 0 Keke we . Thme cometerciby Time eomoterity of catealeing Me Rotio (Pao bit/wershl) 320) Tiwe covpherity of sosetmy — o(nJogn) Tiree compdercity of comp ubng He fol purodit —0Gu A) Tol Tire eomphenthy = = Bl nog n) rp for high ext orden * periost ty Space gEomplenity: hee we have b weate om uy of pp colly Pose Rakio computation . be dhe space tomptenify = atn),Ex pose nt C Waste a ¢ pogser do implement &: 0/7 knapsack. Alyo wunite. p§eudo code along wilh kine and space Cowplenihy # inelade AStdiohS int marGint a, int b) F sehon Casbd1 @. b> ink knapsack Cinta sink m, int WEA> ink PET) . int knapsack mEmery fer; paint & Co Weights. ") 5 Poa Cink icosy fem, 14%) & part (Ad, WEID IS 3 Paawt§ UU PHoHE! "Jy fo Link Peep iderrs tre) pained Cad" PETTIS YG ~ Pxink? CW") > dose Cinkieos Cems I Pos. Unk Woy whee, wert) if Cero Ww==0)e mEIVEWI =e | 5ae (wria 4 wd . weidd), med); else m ciarwd = anenc cp lid + micic! TCM" 7 _ ciycws = mEictdeM ds 5 5 S seh mre) pel) 8 jak mae OD ine HC, paint CERES number oh ehomenk avd capacthy )5° eong Uo fd rds BUS BC); ink wOretd, P Dred + painet CE or purokit ond weight "ye fos Cinkizo 4 idem, i seont Gd rds a wlidy § PDI), 3 paxined C' rd) Rnopsock Cesmyws yr 4° 7ubpal \ Enter the number of chementy ond Capacity . 3 6 Enbuc wetght and probity : be 3 7 5 3 6 tuokt =Thee ty he 16, Kay i$ bj =BCi-1,w-wi DT) BLi-t wy B@Ciswls= bi+ Gietete Wer | Be BLi,wl = Bfi-t, wd Me ciws Ee ot eel. Tire Comederc thy» we need fo fill am asuay of ob opdese Cri) x (e+) where m iy the ne of iter and € knapabel eapacthy. Tiwe eomplenity = 6 ( 1) (e 41) ) Oo Cme+ meer t) = OCme) [dow highest onder PoriosityFi. extn need by mohke on OSH CO) of andes (m+!) yeti) So RPoce Complerity = oft) ¢e41)) = oCmc) =on Cink oawey E Ty id Jew, int gh) | asses [high 5 = Uew -1); Cink $= Low; TeWgh y Ft IE iN Cassoy ba d= pivot )§ tees swop CH oKoy ET » &axxay CID) 5 5 . oeop (Hasson LI+11, & ansoy Chight ); deludn Cis); % void qeuick Cink osseay £1, int low mak Wah)? if Clow £ high) ¢ ink pf = pas Kon Cas how s high); Tiek Coss Jou, pi- 1); Guie kk Casscoy, Pit, Wigh),; 4 a oid padytesueasy Cink agseoy C1, ind size) § fa Gnki=0 5 idsize ptr HIGPan (“Xd ", ages LTV), 43 IW wain © +4 ee Oe 2 8 We Sire of Cdaa)/ size of Meda Cor ) 5 frank (CO Unrsonted o9vcay \n") 5 Print ooeroy, (dake po, nt); rscnkt Uo Sonted atmoy ") 5 Punkosseey dada 1) 5 S oubpak’. ae Unsoatted Asecey zsq7a2t1ogyg eG Sosated Pusey oy oe Ge oS Sect Pseudo codle > Guiek Cassray, leftmost index, xightnosinder ) 5 (eft moghindend sight most index ) Prod indere ( ~ posi Hon (asscay , tefimostindert » sight mest indere ) 5 quiek Caray, Jef trnoat index , Pivot index -!) Guiele Casseor » pivot mdere » sxightmoes} index ) Posctition Casecoy » LeStmost vrclere , sightmog} inde.) sek saghhnost index ag pivet indereStone andes, | ae indere < Jeftmosl index —! rx Toinden tt fo rightmost) ndex iF clement LI < pivotelement at [ stone inde swap eloment LIA and elemen shose indere ++ i 4 Swap pivolelement and element [ soneinder: t Ke huor stese Wndere + \ THe. Comolercily * Cofal, Uher exther great ext od amallest clement Cate l the Ume gomplerity will be s O(n’). Care 22 is middle element ox neat LE occusy when pivot element fo middle element: So the com plenily will be + OCnt Logn) . Goxe 3% ease 3 When obove Pe Govaptexity will be + 0 (r+ togn) . }wo condion do not eceus er | Space comp oly : Space coms Se iy wite BO Space, comoteri
You might also like
HRN HD 637 S1
PDF
No ratings yet
HRN HD 637 S1
132 pages
Shrikant Sir - Java PECE8
PDF
No ratings yet
Shrikant Sir - Java PECE8
119 pages
python model practical..(set 4)
PDF
No ratings yet
python model practical..(set 4)
65 pages
Untitled
PDF
No ratings yet
Untitled
64 pages
DAA
PDF
No ratings yet
DAA
34 pages
DAA Module 2
PDF
No ratings yet
DAA Module 2
37 pages
Untitled
PDF
No ratings yet
Untitled
32 pages
Java 1
PDF
No ratings yet
Java 1
31 pages
class 11 complete notes computer science 2025
PDF
No ratings yet
class 11 complete notes computer science 2025
80 pages
java sneha
PDF
No ratings yet
java sneha
19 pages
Computer Graphics Insem Notes
PDF
No ratings yet
Computer Graphics Insem Notes
25 pages
Assignment 4 MA2101
PDF
No ratings yet
Assignment 4 MA2101
8 pages
Unit 3
PDF
No ratings yet
Unit 3
28 pages
DAA Unit - 1 Notes
PDF
No ratings yet
DAA Unit - 1 Notes
28 pages
Data Structure(DS) Important Questions 2025
PDF
No ratings yet
Data Structure(DS) Important Questions 2025
10 pages
BCP AB
PDF
No ratings yet
BCP AB
65 pages
C++ Fundamentals (DSA)
PDF
No ratings yet
C++ Fundamentals (DSA)
33 pages
Nitu
PDF
No ratings yet
Nitu
16 pages
ip notes full class 12
PDF
No ratings yet
ip notes full class 12
61 pages
ML (Unit-5)
PDF
No ratings yet
ML (Unit-5)
34 pages
Python Programming KNC-302 PUT Sol ODD Sem 21-22
PDF
No ratings yet
Python Programming KNC-302 PUT Sol ODD Sem 21-22
22 pages
C Language Handwritten Notes With Sample Codes
PDF
No ratings yet
C Language Handwritten Notes With Sample Codes
103 pages
圖說演算法
PDF
No ratings yet
圖說演算法
258 pages
Unit-1to9 GTUQuestion Answer
PDF
No ratings yet
Unit-1to9 GTUQuestion Answer
51 pages
AD Notes After Midsem
PDF
No ratings yet
AD Notes After Midsem
12 pages
GET 261 COMPUTER PROGRAMMING
PDF
No ratings yet
GET 261 COMPUTER PROGRAMMING
26 pages
Daa 20231209
PDF
No ratings yet
Daa 20231209
63 pages
DSA Compressed
PDF
No ratings yet
DSA Compressed
65 pages
C Lang Notes 1to 39
PDF
No ratings yet
C Lang Notes 1to 39
38 pages
Data Structures Python
PDF
No ratings yet
Data Structures Python
27 pages
Analysis of Algorithms Notes
PDF
No ratings yet
Analysis of Algorithms Notes
80 pages
Python Photocopy Jul 18, 2023 3-16 PM
PDF
No ratings yet
Python Photocopy Jul 18, 2023 3-16 PM
34 pages
Python Note PDF
PDF
No ratings yet
Python Note PDF
35 pages
DAA unit 1,2
PDF
No ratings yet
DAA unit 1,2
33 pages
Data Structures UNIT-1
PDF
No ratings yet
Data Structures UNIT-1
32 pages
My research
PDF
No ratings yet
My research
244 pages
DS Notes Unit 1
PDF
No ratings yet
DS Notes Unit 1
32 pages
18CS752-Python 4
PDF
No ratings yet
18CS752-Python 4
16 pages
DAA
PDF
No ratings yet
DAA
61 pages
Freedom Writers
PDF
No ratings yet
Freedom Writers
8 pages
Digital Design Unit 1
PDF
No ratings yet
Digital Design Unit 1
50 pages
C++ Programming Notes
PDF
No ratings yet
C++ Programming Notes
184 pages
Python Notes
PDF
No ratings yet
Python Notes
49 pages
Python programming ST-2 solution
PDF
No ratings yet
Python programming ST-2 solution
12 pages
Unit 1 Crypto
PDF
No ratings yet
Unit 1 Crypto
23 pages
Daa Mod 3
PDF
No ratings yet
Daa Mod 3
33 pages
Computer Science Basic programs
PDF
No ratings yet
Computer Science Basic programs
25 pages
Mobile Communications
PDF
No ratings yet
Mobile Communications
32 pages
Ict 5
PDF
No ratings yet
Ict 5
9 pages
DAA Unit 1
PDF
No ratings yet
DAA Unit 1
58 pages
C Language 1
PDF
No ratings yet
C Language 1
44 pages
pps unit4
PDF
No ratings yet
pps unit4
34 pages
Algo Bef Mid
PDF
No ratings yet
Algo Bef Mid
18 pages
Data Structure by Ghanedra Kumar
PDF
No ratings yet
Data Structure by Ghanedra Kumar
51 pages
C
PDF
No ratings yet
C
25 pages
pdf
PDF
No ratings yet
pdf
5 pages
Chapter 3 (DS)
PDF
No ratings yet
Chapter 3 (DS)
34 pages
Maths worksheet 2
PDF
No ratings yet
Maths worksheet 2
19 pages