0% found this document useful (0 votes)
81 views34 pages

DSA 2019 Solution

Dsa solution
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)
81 views34 pages

DSA 2019 Solution

Dsa solution
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/ 34
University of Dhaka is eo. Affiliated Engineéring Colleges Department of Computer Science and Engineering | 2" Year 1" Semester Final Examination 2019 We CSE 303: Dati Structure 7 Marks 70, sats “ mai Hours Answer any 5 of the following question: eat oe lst Lat . . fay All sacs ace lists But ail Tiss are HOI stacks"-Explain this statement with 2 example | LF Show all te steps to evalae the (llowitig postfix expréssion using posix: 2 ‘expression evaluating algorithin: | ABC+*CBA-+* assume, A SEF Convert the following infix expression into its equivalent postfix expression, 6 i) (A#B)*C-(D-E) (F+G) | . ii) A+B*(C-D)(P-R) poe 48), Write Algorithms) to perform PUSH and POP operations fora Stack an 4 array based structure, i ‘ a ‘Consider a circular queue with 8 meni locations, What will be the states of = § ‘queue in order'to perférm the followirig operat Initially empty. *"'5,7,10 and 3 inserted, Sand 7 deleted. * 4,12,15 and 20 inserted,. v. 10,3 and deleted. vi, 17 and 23 insertéd, vii," 12,15 and 20 deleted, __ PF, Explain stack and quée with example, Write dovn an algorithm which 5 ‘PUSHes‘t ‘onto a'stock: 7 Using algorithms translate to postix expression and evaluate the following 4 infix expression: % P=12/(7-3)#2*(1+5)-° 3. (a) Whatis linked list? Explain different types of linked list with pictorial view. 4 (0) Write some differences between linked list and 2 (© Write an algorithm to perform the following o} 6 i) Searching a node from a linked list" ii) Create a Circular linked list i (@) State some applications of linked list, = . 1 4. (a) What will be the depth of a complete binary treé which has 3000 nodes? 2 ()_ Howa binary Tree can be stored in computer memory using array? Explain 4 with example. . (©) Suppose the following sequences list the nodes of binary treé Tin preorder 4 and inorder respectively: . Preorder: A,HE,F,G,B,D,C,LR,P,Q Inorder : RH,D.EP,GA,F.CKB.Q Draw the diagram of the tree (@ Consider the following tree 4 aN MN o™ ON oN aN \ “fie tor? F Scanned with CamS tes be ae s List the node sequence that will be \raversed when we use (j) Inorder (ii) Preorder. (iii) Postorder traversal technique: . AX fay Define Heap. Write down the pro} pertics of max-heap and min-heap with 5 example, : Construct a max heap from the given set of elements by showing éich'stepof Construction {26,33,19,15,7,35,17,10)- _. AY Insert (36) ini the resultant Max-heap. sete vate sic. AF Show each.step of the Heap sort over tho resultant May-heap. (ACRE, Wats bash function? tlastrate tree popular Hash funstion, an PF What is Hash Collision? Describe enaining iiethod that is used forhash {"". collision Resolution, ’ onan EF Show the steps in bubble sort algorithm for the following data: 4 "39,52,29°81,67,22;15,59 eM mas 2 Tad §@F “Write selection sor algorithm and explain it with example, 3 4 BY Define the following terms with ai exampl 3 raph and (iii) Strongly connected Graph 7 pr Drae the,graph from the following adjac ency list Node Adjacent list ]° 1 56,7 * 49 7.8 [25 149 1,10 i TTT Find:th followingsin:. ea oe the Adjacency matri: i ite aii, a one ix of the Graph, iv DFS and BFS of the Graph., = « t \. ; S > Chae ang, 6 t 7 1 A ‘ .& e 4 “y 1 % t ® wv 4 % 2 2 at. 4. ‘Scanned with CamScanner A(b) ABC+*KCBA-+* given, Az}, 2%, C=3 Step-t + RU sh Q) 7 push Q) 7 push(s) : Hear vor | | pop (2) puch +2 25 5 \ 1 Step—> por (5) | poet) gush (5% ) GF \s\ Shep — 4", push) push(2) push(\) Step -5 gop) \s| a eee) 3 push (2-1) =| \3| Stop 6 pop (1) \5\ gor (2) push (5-1) 2Y \3] 5 -tE pop (4) =“ ope U push (4* 3) = 2.0 \,5| The resulbis 20. Tee yo — © D prox view) - ar(a (ea) /0-9) = x (8(es)*@8)/) = ASG Qa) /* = Ag ep-*Q-R) [+ = AGED-* PR-/t D xe) -0-£)" (8) = (ein)*e 0-090)" . (es) ex) ~ (o-£) (+4) ") - (aver) -(@-£) (r+6)") = AS+CK (b-£) (F+6)" - - AB+e® DEX (F+4)* - = ABrCKDE- FG+*- 1 (dD ee PUSH: Adds an Mem bo tye staal. Th the slack is full tn V4 is saad -\o be am Ovens\ow condition . begin prtocadurre if slack Vs dull retunn nul end} ele \nonament op stocl| +05) assign vane end alse ans pro cadre, ; Pops Ramoves an Ve rom tha back.. Tre. thems One popeed: in she raverceed ora in akich thoy One pushed of Aha dack is empty stam it \s said -lo be an Ordonett ova condition : Agorirtben fon pop: begin prroeedune if stack is amply neteotn mul) end \S else Sone value af stack (09) deoramunt wp return value end else end prrocediang 2) sxe pd the airnevlon queue ls 2° @ TuRally The queue \s empty oo 2 Me oe daontt = neat = | ® ye 5, %, \0,9 - front = © ere Ddleting 5,t. cut ce Be PTT trond = b Toan > % Q Gnsescting 410,15, 20 ~ v Or ake 3 Ws a Bt yo} &@ | 4% | to fd | 20 * ponte Bh. Roos F Qg Deleting (0, 8,4 v ON 0 8 et i iat, 12 | 15 | 20 ay Sionts 5 & Toanr co Ft ) Ansar 4 \q, 2 Ort B s u : 6 + eT bte Neate GB & Near = \ Deleting \2,\5, 2 vy Anon ten 0 & Reo eh 2G) Slaeks Stack Vs a Vimar dele strcehine onieh dollows Qa pant olan ondare tn aie he opertalions OF porrbrenad : “We ondon maybe LIFO (las! hn Pra Oel) on FILO (Finst In Last Out) eram@e’ Considering mary ples Seecked oven one. anodthen in ctha gontean Thx plate Dich is atthe top 's ts fad one to ba ramoved . The plata akidh has been raed ak tre bottom - nest position amains ‘inthe stack don, the longest pertiod ot dime. $0, i+ Com be ghygly sean to Sulla LEO (Last in Fret Out) on PiLo(frst In Last Out) onda. fltoas a partoulan onder in whieh he opartastions ange garforemed Thea ordon ts FIFO (Frs4 In Fret out) . @xarple> Any Queue ae Gon sumans dora rwsourtes ahora she Consummen thot Carns. inst \s sonved hast. Sree A queue is Vian Hrneture ahich he Srdrlanan: bodereon Socks and Qyuaues \g We in Remon Gy a shek Remove =the thon the mosh ruemnity altel, Wa quent, We Namove ‘tem We \ates} a natal aa? Algorittm Jor_gush’ begin prrocgduree if stack is dull relunn nul ete else. increment top Heale{ top] a. ssign va\Va end al $e end pro egdune 2(e) P= tn /@-a)r 2A Gas) . (AG 9) /) 2* (145) ° (a(#-9)/)-+(2 (1+5)*) > (RE) +GO49*®) = (ap\-1) + @l8**) x (Aste) HICat 5+ 9) Evaluate * Sep-1 push (@) 6 push @) + push (®) te Sep -2 op?) pools) Lal qush(a-9) <4 |] ty ; Step - 3 gop (y) pe plz) UI push (ws) 23 \,| Sep, push GQ) —— puch) | 4 push (5) u nud pps) . pep) LI push(i+8) =C E] Step-¢! pop Ce) pp(2) | 5) push (2*¢) 7 |: Slep-t; por yr) pr (2) L| push (3nd) -15 ls] The rasul} \s 5. le) Pre-orders AH EF, Gq 30, TR, ~ g bi cabee ae Cr—ordor RH, DEP G, ALP, & {6g | i| © © Dw | ae | © Srondor: DB FE ALNC, [ee — CD Pe ondin : A, 3), &,f, Go WLM, K,N Yosh ondont y e EB, &, LM, 3 Ny, \, We A 426,99 19,15,4, 25, 1F,10Y Salt S-2' S-3 sou) = Grsoak 26, Gnsent 33 7 BO>2’ ~ go swap 26 and 83 Snort 19 - @3 @&) Enserct \w, @ SB) Great F, @3) Gy G © S-C} (nsent OS - ee >) Ges DD) © 6 @ Bey 19.) swap. BSand \9 BS 8%, Sap 25 and 22 [S33 Gneontt V7, au 2 > 15, s8ap BC amd 1, ~ 5) Gs) @D. 6 o©©® @ CG & HL>2B, Swap 36 and 26, 3) 3) 33 a OO WO CY & BC> BS, soap 2 and 25 , OQ GH H 9 VY © wD \ 9,9) 4.5 £28 oe | S41 Deleting 96, 25 > 33. amd B57 \5 , sap BE and IF, WH, 26, sep Wand IT | 38 | Gey G3) (99 G@ io) 26<93 amd 19<95, SMap 33 and Jo, salen IF end 9710 , Sap Sand 10, S81 Deleting 33, A Y © & 26719 and 26719 , $Map 26 amd 17! & . WD © © O©® a ee Galilee 8! 25 Lledo Te Ts Lee ls3]95|26( i se Deleting 2k, F<19 amd «9710, SMep 19 andlo, SB. Ddleting 12, @® @ A> le and |#>F, Sap Itandt \S>F , sWap Ht amd 15 GR (5) © @ \ 2. 9 4|eg t8 % pe podels [ee ele Ted Sh Deleting H, Oo WY Iep}o and FSIT sap F and 15, 1 2 e\r% 6 +39 (ie [ee le [2 20 ler]oe] ( $-7) Deleting \y, joo 4 5 6) F 8 [> fe ls [7 Le [ne (29 [os [96] ie Deleting q , to § 5.6 Ft? PDh eb bls L®© S-o0} to |p 9 [safes Ja [eF]o2 |e Tsp | ts 1 [oe Proper] [er pa] is [9 | tF fs Vn fe 9 bras pel Teale We [62 ppeee ll 1 1 BpREREDSH > BEER + BERL seeks 5 SEEREE 8 ele bslol. 59) +2 |i] [3] Bal 1] $27 [Pe o[so]r [= [is oles Ter) (\ folplabelsTele# [ar] feo (eoleele tee saa] ‘eo [eplso laa 1s2 ls Tm Ve 1 ‘ 24 alsa balssler | sh 4 pels keller eo Dbl kEmale TT 1 Topple ole] tee [aoe] wleslsalvolerl 4 J alas [ale] eI a - $ f:o rao lan ome # Let 1 i Taleo Ee i Lv Vor [sl 2 paypal ler | At ErbPRbiel wlspaleloferl a 1 cs 12d oe / EERE Epp bles | $-6' ie oleae o ce Selection Sent Algorithm: Oe | Selection Sont (Connery, size) repeat (ize=1) mes sete dust unsorted clement as the rinlnuen fo cocks of he angonted cloments i deront aurrcent Minimum set element) as New Wialmum $aap minimum wth Sask uncorted position end selechon sont example. 2, le, lS ,% $-0 \ vo \nye le lt a) OU) Adjnacency matte od the graph! i | @ Li) Guanes [flit Ws, 1% ¥ Vis} ” us ; ‘sited: 7 56,4, 4,9; 10, % ; 7 10, 32,8 DEST shack: NEMA IM BEE # Nish 5 1,9, 48, 8 | Ae ®, G

You might also like