0% found this document useful (0 votes)
68 views31 pages

CTSD Week-9

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)
68 views31 pages

CTSD Week-9

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/ 31
COMPUTATIONALTHINKiNG; FO rh, Week-9 Pre-Lab What is the difference between a and a[0] a is an anay & type ink (6) , thereBee kA isa poleker array of type Wk WATE] ond KALE] VSO Pointer to ay” Fave elemerk & @ go its Aik mH. ‘What is the difference between array and pointer? The main Ailevence between Array ond Minkes ig yy, Grek sine f Ke memory blocks When ovrays ane _Soreh she Creaked Re fixed Site 14 aliocated- But with pointers ¢. memos is dynamically allocaked. ‘When is Linear Search preferred over Binary Search? Linter seardy can be used on oth Single ancl mull dimens's: array, wehevean the binary Stark can be implemented»: on tnsdimensiona, anvay: Enea seavdh 6 bss fhewe fohen we Emsicley the orrge data sels » Binoy SO care of lenge date ks. %% move efficient in the When is Binary Search preferred over Linear Search? Lineax search can, be vse on both sicgle ad mndlladionens Gray whereas the binary Search can be ienrplemented Gn cme dimensional armay- tinea rare 6 SE -offieient * ae We consider the large dala sets Binary gearch ; a a 4 pe Ban Knear search in case of lard 4 What is the maximum ‘number of comparisons if there are 5 elements in array x performs sorting? lo ang cases, (oerse cage te ae 1 HUsk Ose oF average tl < MSE in standing ae the num be % Comparision 3 . ll \ S between elemenes is the 20% hee i ‘ sot SES with 5 elements Med 10 Compavivions € all doke. tt toca Te Of the sees ‘. to, pe ; Nate soa sion: ‘ corte Ses inct integers and a target value, ere eae if the target is oe i scurmeindn where woe faa 7 pen rte the in re a 90! ‘turn sa sstiic soe not, Fel ‘om/problems/search insertpostion/ ‘ou [[eetcode.com/prob! ne tos wou ; cy : etl aly cal pempatouet + se et a ons fi Se] bangee re I ams Gh 7 ek =p S (55167 Long Li, steak keg sof sbep-t a, ae Declang steer. Algorithm hey an, 5 Read a) stee- h, > pens, seg ca 3 Biel) break sheprus Flowchart COMPUTATIONALTHINKiNGg ‘OF ‘ Uy Execution: -# include < gtdio h > ey Yn enain CY snk a fo) skey 85 prinke Center how many Valves!) sean (id, Wn): prince Center valves ir array) ; Box (ie, van ja) scant (id kati) ne key vale). ‘stan Cra” se leon) 5 Fou (670, tem \a8) z EGET >> key) i break +, 4 4 BROCE 49" 9. Yetvin 0; : 5 ‘Testcase Table: Testca: sel Test case] Input] Expected Output after | Testcase Result: ss ar} Output execution Pass/fall “ick kins Q 2 Vinkegey oo ’ . Tas SHE \ Pass Leger bon u 4 pass rr wine session: ; A um is an arr ot: form of an integer ni ‘ peor Y Tepresenting its igits in 2% ge qum =1323, the array formis (1,32 1) qe Dum, the rays 1 tr einteaer k, return the array- form of thi eat and al fs nee Tight order, 1, the artay-form, of. in mY © integer num + ,, Pad om/Problems/adto-aray-torm-t integer sink: WwW" wer! [output] k au | Praag ie cuss) wean slep-1\ SEawk - i — bep a: Declowe W,i, push alepa: Read aN, step, fos Gite, (vals 45 for Geielyd es 5a) Shep-§ + NEI + push—bacte fj} SEP } Ei step-6! print elements ak jndex eo Step-1 sine Flowchart. Bx Goi $65 33M + ‘ ab _ Ll ag ene COMPUTATIONALTHINK; INGFORStp Ih Execution: 3 intluded gkdio-h> te te include < std lO-h> yok v Cel 5 Tne naka Oy ¢ Titer Qak i <0, 1aSy N49) = Gok gevgus ¥eSs ate) VEL = gush —back (J. 3 4 % Ine prsintElemencsd) fox (int ed, 1665 Itt) z Prov (“Clemete ak Sadex:") for (O71 145,444) Peistely.g" a5 4 Sok maualS axray of VecterSl), Testcase Table: q eluting 05 z Expecte | Output after | Testcase doutput | execution | Result: 1__| pass/fail ' He Inkeaes, Gre Bad] Fa.34 Pass > Ave (nkeges, nl Gag @ au] Pass | 3 | Ae tekeges ees) | Bust Testcasell| Test case Type | Input SOMPUTATIONALT INKINGFORSTAy, PO ssn Hf ; oe arene Se ™* OF the Session: ° , ni — in array of integer’s NUMS Which is sorted in ascend en inction to search target in nums. If target @ One a Aa must write an algorithm with O(log nr w 1. eu .com/problems/binary-search/ jennifer w ng ks and an j reer then Feturn its Mkeger target, untime complexity ™2€X. thant ode. put Output sone pitta etait SS Input sill. Sstask Dedese |,u,mid Read 120, U= romSite=| while (2< 74) md (+U-D/>) 1 (numsfmidl -= eaxget) leomid +1 else ve mid-) Skepre: prinke (Eacget retvrn) Sly? op Execution:#? in (udu < stdio-b > Yik gear ch (it ¥ quam § Vek AUS gite int banget) 2 Yr \=0;, rk Vs nUMsG ve -1y, Ink aids, whe (ve te) 2 mde ele (2; VE (Quens (wid == Laxget) reborn mid ase ¥€ (avons Gri] baxget!) le enday « ase vemdels 4 bem -\, 5 Test case Table: Testcase# Test case Type COMPUTATIONALTHINKING Fog U Input | Expecte doutput Output after Testcase Result: 1103,5) +ve \nkegey (es 3" 4 execution y Pass/fail lass | seat “"\ Pass _) (For Evaluator’s use only) ee ee TS AVTHINKINGFoRSTeUcTUREDoES ( Time of the Session: ——to__ pone ® array of integer’s nums, sort the array in ascending order, en sc tntps//leetcode.com/problems/sort-an-array/ punk it & Output sgnole Output 1/2138 agorthm = skepe\. Stave Guna: Dédbee"acnely Read afi] »9 step 3 step-u: it atl 27 aes batt ava aD aed et sep: poe ad skep “6: Pee 5) Flowchart a Peod a foc) ay . © y : eat) afd -oGe) eGed et Execution: + ivelude < stdioh> Ht toelude tt Include < mathe > \nk maint) t ink aloo] jays jit nN: @ Clea (+7) £ e-a(l, af\~ a; aia} eb. peste Crd"a TY, 4 selven o- 4 Test case Table: Ui: Testeaset | Test case Type | input | Expected Output after Testcase Result: output | execution —_| pass/fail z tr lnbeges | far] Ga ah} 621905] Pass 2 [ave toteges | Einrad@or 00, Pass o g [ernest COMPUTATIONAL Thy tt eee id arr2, the elements of arr2 are distinct, and all elements in ope rrays arr a arr such that the relative Ordering of item i" seg ld oe he erat do nat appearin Srr2"Hs 4.501 that jr ents uy me! ale 3112 ate also in $ iN art are the Same as in © placed at the end of arrt i, Atcending order relative-sort-array/ oa tcode.com/problems/elative- ps://leete je hit un ye?” Output snp tmput & — = [ Output Ir m oF, a aT a) 1 SnS ue, Fa aT] ele lar 3 = Cu nae aT 31288619 Huy 18 6:2 2,8) pads ergs 5 Storck i atrd, 941, Count, acel, eclase “3 D s eeep 1,0, 3. Read okep- 3 (120; jer, sae) skeg a (i205 5495 ap) x 52 ‘ans * Sok ‘ans! Skep-F: prio step-t stor Read. precution: #f inluda + Co gcdioh> cpunt (00d? 40% geen foo 2x7? (ees att ("enker 0 value") scant (“-d", ke) : eCenten values fos cet aeeauy’) 1 fen (1805 tan yiet) stan? ("4", Hacet oy. Pract (Nenter m value "5 seane ("1-8 wes); printt (“enter valves Go acer axa"); box Vem ye) Sean (“td Kare s Gl) , for (120+, Ve 001 for (i204 ten tad) ; ‘ adele. Count (i]-- >) coun (ater (il) #45 : ‘ ‘ ey mt index x20, ans(ol; ang (index roy , Cort G20 j seen yA), : é ae while (count (avy +a] -->8) fox (20; sets ist) priate ("\n ta ars(i); ang (index si) sare 201; cae 3 D ener 4 fe Testcase Type ‘| input | Expecte | Outputafter | Testcase 7 execution | Result: output Pass/fail b__| He Integer _ [4% at GAS20| Baar, 22.045) 5 Ae Inkegey ster = trl » Aye Inke. ont {Faro 4.6. 4 ated] eu) tajus) My, nese V0mG, 6 som SI MNFRS TMT UNECE 1% gee Te othe Sees 9s mye —— iiyand Ron, want to share a chocchate bar, tach of the sis3t es has an waren share a CONLIgUOUS segment of jes to oI the bar coeiches Ron's birth month, and, the sum of the reaped tat The lenge on the cid rent rh ay. Determine how many ways she can divide the chocas, ares is eons sa oips/ortr nackerrantcom/ challenges] the birthday ow pr cttemy ye! -1) Skoxt Declare n,i,0,m x a Reah 1, m,x,h 4 agen 120 5344) print ‘count ’ sto COMPUTATIONALTHINKING op TU, precutlon: #inehe 4 8edio“h > He tedleds 4 stsing h? Hincioda emote b> joe main) 5 nen scane ("td "! ko) vat a(n] its fox (204 ben yer) while (x< em) 2 sean (‘“ha" kaliT); gue ese talil, ‘ine dye, sey Seane ("4d fa" kd ers) 4 : xe IME count 20,41 Sum.%, Core (420, ten y 44) i¢ (sum ==d) counk 44: 4 es ‘ PrIACE ("ea count); Testcase Table: Sum 20), Sekuxn 0; ashy ae Testca: Test case Type | Input | Expecte | Output after | Testcase Result: d execution Pass/fail output As e Inbeges | rin 6 6 } wv egec | NN 6 Pass ——] | a [ve taceger | y \ q Pass _ = (ForEvaluator’s useonly) Comment of the Evaluator (if Any mment of the Evaluator Evaluator’s Observation Marks Secured: 0 ot_—— a Full Name of the Evaluator: pate of Evaluation Signature of the Evaluator UCTUREDDESIGy ; conducted in two different Balleries o oeiton ha Event organivers have announced tg divi ements Oe aleninthe two chosen galleries. 4 at note, all the oy the COMP! code as an even number will go Put in one gallery ie itation © another gallery. Help the OrBanizers to fin, “nr will ae .s and odd registration codes from the total N. a fe en cO fai istration code need not be unique as each child wit st the resi se ilThave a unique se ye Input & Output somp! Stast ep-8: Declaxe in, a, Uw £208 7, a0e, 225 fox (ine; Ten 5 wat) # Ay 2209 ae else MH SEEE-G pre 2,4 skep-9: Stop COMPUTATIONALTHNKiNg OF Execution: Hf jnclode < std forh > ink mainly yok aca fee) ,220,420 stant (*-1a", 80); Coe (520 hen 4444) t seane (pa, xaCi]) 4 for (Oi en 348) i VE GIy S 2 ates 4 else Yet, 4 : Prine (dpa) 2,4), Beborn 0; 4 Test case Table: Testease] Test cae Type Output after | Testcase ———_| execution +VE nttaes tye wteaes_| AWe_tntege’y “OMPy; 3O coon FT TATONALTHNiNGr aed Time of the se *STRUCTUREDDESIoy 8lon; , to. nt he candidates are waiti oo ees en ere referral candidate, Gites Sutside for their tur en Containing the list of candies Me is given 9 TONE these cong, een? eas the interview he wall Bato attended forth cman 10 fant sip attends ill be in the sel £0F the interview, jp LOMR start vdaxe of the HR staff is lected list. Gi ew. if the ete the eS ID no. Hal ot! P HR staff to Input [230,40 S300 1-7 apr Sa) 210" u 2 [2830407 St ope 1: sbase a: Declave kv, atm, a1 Read k,¥,7 us for (i260 Fea sia) 5. i@ (kee atil) , breale:, reo stepre V@ (e220) Clement 3S present In arvay ek pesition else Clement 1 rok Present Ya annoy Ton Skep' 4: stoe Fut — 7] at gosition sea Fiat prow) —> COP) Tense ot WO COMPUTATIONAL TH INKING; FORS execution: # include & sidioth> Me we 3,6 ok mand) 6 e yt kK, 78 pane (Memder 0-0 clements:*): seané(“4d", Kol) , ioe a G1, print Een eer ehemnends\o =") Cor Geo remit © seare C1d" K ACT); 4 PRN (Nenkey the elements be be Stav cheal"'), Scaune(".).4" &R)5 i tor (i g (kee at) L Tro, Sten 2a) breale 4 ie e205 POLE (‘element is Greseat ta Aa axay at pestis ase PENE (element i¢ not Present in 440 aseay"); Test case Table; 4 Testeaselt ] Test case Type | input | Expected | Outputafter | Testcase | output | execution —_| Result: Pass/fall Le | Ve Nokegex| sy. q iG fass df Hve loteges| 4o 3 2 Rass dD |tve_\nkegex | 30 2D D Pass COMPUTATIONALTHINKIN FORSTRUCTUREDDESIGN Gk ui i Time ofthesession; ito, set sessi ier h ratttend MONK Mow Ou of aninteger " the owthe rules are~ of the student is eq! aquestion. ahout skipping n weg allowed 10 SKIP IU as an exam that has quite weird rules. Each question has a di ji Monk can only solve the problems that have aitfeain a evel Ity level less than ual to the maximum number of answers he/she has attempted + "one" question that will not be counted in the continuity of the GistoTS ye student knows the solution to the problem he/she attempts and always garts the paper fromfirst question. baink:https://wwww-hackerearth. com/practice/data-structures/arrays/1-d/practice- bank = ornsaigorithm/mark-the-answer-2/ sample Input & Output vo | input Output 1 | 36 3 o | usa etm orithm ei. Sbarse . fome) ree nba y) covet, SKE Declare Kod 7, Ea gon 704 180 1A) ie (asitezt ve okie \ >) count +4 ene 2 Suse + Sleg-G. prine covne Flowchart Shep-2 = eboe v Beak 1, & | ost, weivae ; COMPUTATIONALTHINKINGg Execution: ne main O 4 wnt OE 4 Seone (ka) amo We); int afo1 3, Care (Feds Leg a8) g sean€ ("-ha", & afi)» 3 Ink eo ont <9 skie =O; Fox (iso hem iat) W(alil< =e *¥ ie 122) count +45 Clse (ald oe xk skip Skip tt, iNeed", ; Testcase Table: ae count); Testcase#| Test case Type Input | Expecte Output after | Testcase. a execution Result: output Pass/fail r He Inbegey a 3 4 Poss a 2 [ave Intern [OP] og 3 Pace (ForEvaluator’s useonly) out of ——— Marks Secured: as Full Name of the Evaluator: of evant Signature of the Evaluator Date Lge ee eee a yl sei" fel gine Time ofthe Session to ums1 an. ees soe me ni and nums2 of size m and n res, ve ra) oye sorted a yt Pectively, return the med fan r pirate conten dn shewo-ertetarey/ vs ert output ya NO [Seg tease ee tome ae Seeiay [os emsis Git}. nem sae au} 3-5 0000 | clepe\s Skast er step 33 Peclave 9b, Cum Oi ryil slope Reach abc (asia < oD de} = af) kat iH else om ~e 6) kat a+ Skep-5: prin” oid | walic J skep 6! StoKE L a ke “A FF sa + WG ee of 368 T_ —__ COMPUTATIONALTHINKINGFo RSTRUCH, he oh > +e sfpicclude < skdio yy ink main) 4 $ 4 S yak afed, b¢e) <7] une (ac Yate mas ak % pence ("hw many values ieqarvay’),; A -agy. scant (ha, kn): : kre, Lott (Center Values bor anvay a4 igh Price Cent sovted torent |g Fox Gods Leven) Wave Gece) stant Cha" KaGd) q PRO Chew onany valves ia 6 array’); <= eG, Scant ("4.4 rd) ke, ‘ dee, PRnte (enter values Fox b Array $9 % ‘i Se a eee OT GPG § cen ga ime (224 seane td", Ke GI, Pine Ca 4 - Heat oid ; initkeo, while Gen kk deen) le @y-r2s0) oid: (c (2he-Jre (zie) pe i (203 7 1a execution: H# include ink main) | ong long HOE A, 1,1, Kemer, SconeClAN A-ha", ko dl), long long tot as], fox Geo Neo a8) Scac€ Cr va" ha (ise dhl) fov(is0 rise taay paink (rd aC), Tend. 4 Testate Table: Testcasen Testcase Type | Input | Expected | Output after | Testeave Rest = output execution Pass/fall . ane u : \obeger nu) 512384] 612 By ass a. es We Ietege | igure] 68D 4d G19 aus Pass Bs Thay c ua MEN Linayl urea | wird Pass aaa eee cal oe skill 4: Date of the Session: / / Time otthesession: tg problem 2: nan array of integers arr, return true if and oe aliticintain’Sriaiit antl only i tergth - 1 such that: arr[O] < arr[4) <.,, le -1) only if itis a valid mou arr. length >= 3. There exi +S arrli- 1] < arr{i] arr) > a ntain array. Recall that ists some i with 0 > arrfarrtength rs https://leetcode.com/problems/valid-mountain-array/ Web-tink: https: sample Input & Output i [sno [ep out 3 ace > [ond eis 2 aces C815} | Algorithm step-1~ skask ayn Size eclase cc, step? D Read < Skep- > Hele Step > elec ll € are$ ize] =!) skep-: 7 a veri Fale Sive-y KK Ate Cel parceel) while (e€ accS\ c+ ‘ ee o$iee <0) <6. it (e== at ‘ see peioke “Eve else _ ” prince “Fake step-6 1 stop aes t si L —> J Print bave me / —+>Geo faGe 253 of 368 COMPUTATIONALTHKNGFoRSTRUCTURCODESIoN COMPUTATIONALTHINKINGFORSrg Ue von aude ¢ Sediowh> oe lol abd Movant Ri stay (Jak are, sok ace$i te) ink © 20: ie (ae Sid) ferurn false; c-0 while (ce qaSive UK ate] are(ean) 4 cre 3 i (c+ sareSine) (eure be, C\se fauen Calse ; 4 Testcase Table: Testcaseti | Test case Type | Input | Expected | Output after | Testease Result: e output _| execution _| Pass/fail v_|rve Wnteges [ental false falce mie. ae B._fave wtesey [B51 false | Falce ss Bl ave Inkegey ora oe Pass bove COMPUTAr; 'Or the Session: / / NALTHINKINGFORSTay ite of ICTURED) ba Tren DESIGN problem 3 ; ss given an array of integers nums sorted in ascend Order, find the st ofagiven targetvalue. If target isnot found in the array ren 1, ING aN ending postion ink: ://\eetcode.com/problems/find-first- Web-Link: https://I st-and-last-position-of ele ‘Ment-in-sorted-array v/ sample Input & Output Input Output nvm = (519, 8410 * Buu 2 [roms $7579 S810) tang Aigorithm = step-1: stack ckep-as Declase 7H: 3,4, mnial —_ | af) a mid giegen Kel 4) . k -© Skep-u: ie (icy M! eM QHOle 2 afer) chep-5: it (z= alr ES search 21; breaks else ié (ex a@riel) ureid-) I ee pesiaeh Slep-or stoe Flowchart eae L 6-7 =a— execution: include < stdie bh > COMPUTATIONALTHINKINGFORSTRUCT ype DDE, vere, ena while (ies kK Ura) 8 4 neo Aid pense Canker “A! value) mid = Culpa; Seared Res (es = afmiaqy yeah, ine Vs, Stat 2), GREE Center raiees fe amas"); : break , “ Gedy)

You might also like