COMP 352 Data Structures and Algorithms midterm tips complete update- Concordia, Exams of Advanced Education

COMP 352 Data Structures and Algorithms midterm tips complete update- Concordia

Typology: Exams

2025/2026

Available from 06/07/2026

studyroom
studyroom 🇺🇸

4.2

(5)

6.1K documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4

Partial preview of the text

Download COMP 352 Data Structures and Algorithms midterm tips complete update- Concordia and more Exams Advanced Education in PDF only on Docsity!

Midterm Examination ‘Y COMP 352: Data Structure and Algorithms Winter 2017 “€oricordia University Time; 70 minutes Department of Computer Science & Software Engineering March X 2017 Name LD: At I questi Tota’ the exai 2. All.auestions must be answered inthis examination booklet in the space provided 3, You should use pen in writing this exam (you can use pencil for doing rough work) 4. Simple numerical calculator is allowed 4, Use the blank back pages of the exam booklet for doing your rough work 3.this examination booklet includes a total of 4 pages 6. Exam is closed book eZ —#-Read the questions carefully Go &V Part A [52 marks] There are 13 multiple choice questions in this part, with only one right 4 answer to each question, To choose an answer, draw a circle around the bullet (¢) of the AV. angWer chosen. A right answer for a question will give 4 marks, A wrong answer or _prarking more than one bullets for a question will give a 0 mark. 4 / LZ 8) Consider the following pairs of functions f(n) and g(n). For which pair, the functions are such that f{n) is O(g(n)) and g(n) is not O(f(n): Fr) = n*,g() = nlogn @ F(~) = logn, a(n) = 3 log(n*) vf) = 10,9(n) =n « f(x) = n, g(n) =1000n +5 b) Consider the following pseudo-code: Let A be an array of n integers for i = 0 to n-1 do for j = 0 to n-1 do for k = 0 to j do Ali] = Afi) + Alj] + A[k]; Which of the following characterization about the running time of the above code, in terms of 7, is correct? * O(n) © O(n?) © OQXn') J® O(n’) c) Consider the following pseudo-code: a= 0; for i = 0 to n*n do \4aaX+.. en for j = 0 toi do aea+ iz Comp 3$2, Winter 2017 — Midterm Exam (A) Page | of 4 Which of the following characterization about the funning time of the previous code, in terms of n, is not correct? * On’) * O(n’) © Ont) _/ Oo’) 4) Consider the following function on input n. Algorithm Fun(n) Input: A positive integer n Output: A calculated integer value if n> return n * Fun(n-1) else return 1 What is the tight big-Oh time complexity of the above algorithm? / OOM) + OM) Om) + OW) wv ¢) Which of the following statements about recursion is not correct? © Recursive functions are executed with the help of a stack / A recursive function without a base case may run for ever uy © A tail recursive function may use binary recursion : ~ © A tail recursive function can be easily transformed to an iterative function Tin) = Cx Tho) f) Referring to the following tree, which of the following chronological sequence of visits to nodes of the tree does not correspond to a preorder, postorder, or inorder traversal of the tree? Note that a visit to a node prints the node’s label. pe A, 8.0 6,C, FH, 3, 6,06 hep, 8,6, A, 3,H, kb, F 0,06 g) Refer to the following pseudo-code: Algorithm MyAlgorithm(r) Input: Root r of a proper binary tree. Output: 277 if r is a leaf return 0 else AY MyAlgorithm(left child of _r) Comp 352, Winter 2017 ~ Midterm Exam (A) Page 2 of 4 J front = 2, rear= 4, array: [(_T [LT MEN] _] The following operations are performed on the queue in order: dequeue(), enqueue(P), dequeue(), enqueue(Q). Which one of the following is correct after these operations? © front = 2, rear = 4 j @ front = 0, rear = 2 / front = 4, rear=0 ‘front =3, rear=5 m) The following keys are inserted one by one to an initially empty min-heap in the following order: 15 7 4 20 9 8 5 23 12 1. Subsequently an inorder traversal is performed on the heap to print the keys stored in the nodes, The inorder traversal will print the Keys in the following order: Sin Fi Ws ia PON TORE / 223 201215941875 aac: IS a sate 4 i | ©23 122041591857 4 “oi ONE V0 12204 1519758 23 4 TEAS ‘ ©145789 12 15 20 23 a ee ei "i PES ar ay i Kou it ee a ihe - ‘ Part B [8 marks] In each of the following questions, specify if the statement is true or false. )% if the statement is true, explain why itis true, If it is faise, explain what the correct answer is* * and why. There will be 0 mark if no explanation or wrong explanation is provided. 4) The maximum height of a proper binary tree with 11 nodes is 4 (Note: In a proper binary tree, each internal node has exactly two children). 0 True False Thr is senge Explanation: bine, tree oth of Widen dart Pd s% Nae (oie, R y heeght of S. ay wis Ow = fin) © C (gun Yn Alga) ar Fl Y Eloy) b) IF f(n) = Sn? + 2", then f{n) is O(2") 4 True 0 False Explanation: i. Dany 9 ec4® \\ Pact ff) « O(2"): Bova £ $344 t= (sed = 6 ; GQ % n Pook Fda m(e): Sat 8% UI Ang C - Thee, fix O(2") Vv Comp 352, Winter 2017 ~ Midterm Exam (A) Page 4 of 4 ‘