20.3 Y1S2 PU 08sep2021 Algorithms and Datastruct
20.3 Y1S2 PU 08sep2021 Algorithms and Datastruct
3) Time allocated for the examination is five (05) hours (Including downloading and uploading
time). Please type your answer unless a diagram is required. Diagrams can be handwritten
and attached as a figure.
5) Download the paper, provide answers to the selected questions in a word document.
6) Please upload the document with answers (Answer Script) to the submission link before the
submission link expires. Answer script should be uploaded in PDF Format
7) Under any circumstances E-mail submissions would not be taken into consideration for
marking. Incomplete attempt would be counted as a MISSED ATTEMPT.
8) The Naming convention of the answer script – Module Code_Subject name_Index No (E.g.
CS106_DSA_100065)
9) You must adhere to the online examination guidelines when submitting the answer script to
N-Learn.
11) Your answers will be subjected to Turnitin similarity check, hence, direct copying and pasting
from internet sources, friend’s answers etc. will be penalized.
Page 1 of 4
01. The following questions are based on the sequential data structures covered during the module.
(Total= 30 Marks)
II. Graphically illustrate the insert (push) and remove (pop) functions. You may insert each character
of your first name into the stack for the illustrations and remove the 2nd character from the stack.
Note: You’re required to mark how the ‘top’ position changes during the execution. (5 Marks)
III. Graphically illustrate the insert (enqueue) and remove (dequeue) functions. You may insert each
character of your first name into the queue for the illustrations and remove the 2nd character
from the queue. Note: You’re required to mark how the ‘front’ and ‘rear’ positions change during
the execution. (5 Marks)
IV. Write down a code snippet for push() function and enqueue() function. Put careful attention to
the order of steps. (4 Marks)
V. Derive the DFS and BFS output of the following graph. Identify the suitable data structures used
in these two scenarios. Assume it starts from “0” and follows ascending order. (6 Marks)
VI. Evaluate the following postfix notations and derive the final output. What is the suitable data
structure to be used in this scenario? (5 Marks)
a) 2 3 1 * + 8 -
b) 6 2 3 + - 3 8 2 / + *2 ^ 2 +
Page 2 of 4
02. The following questions are based on searching algorithms. (Total= 20 Marks)
I. Compare and contrast linear search and binary search algorithm. Note: discuss where to apply
these two algorithms best and justify your answer. (6 Marks)
II. Graphically illustrate how to search for value ‘30’ using linear search. (5 Marks)
III. Graphically illustrate how to search for value ‘30’ using binary search. (5 Marks)
IV. If there are 1024 elements in an array, explain the best case and worst-case scenario in linear and
binary search algorithms. (4 Marks)
03. The following questions are based on sorting algorithms. (Total= 20 Marks)
I. Graphically illustrate how to apply the bubble sort algorithm to sort the array. (5 marks)
II. Graphically illustrate how to apply the insertion algorithm to sort the array. (5 marks)
III. Now take your birthdate (e.g. 2018-10-02 as 2,0,1,8,1,0,0,2 so it will look like as below array) as
the input. Graphically illustrate how to apply the merge sort algorithm to sort the integer set. Note:
We need to make the integers set in descending order. (6 Marks)
Note: If you have born on 2018-10-02, your input array will look like this:
2 0 1 8 1 0 0 2
IV. Where to best apply the insertion sort? Discuss the worst-case scenario of this algorithm. Now
write a code snippet to illustrate the algorithm. (4 Marks)
04. The following questions are based on Binary Trees and related concepts. (Total= 30 Marks)
I. Draw the binary search tree that results from inserting the following sequence into an initially
empty tree. (5 Marks)
40,30,15,35,20,45,98,42,100
II. Derive the pre-order, post-order and in-order traversal output for the above resultant tree.
(6 Marks)
Page 3 of 4
III. Identify the path to node 98. What is the depth of this path? (3 Marks)
V. If there are 33 nodes in a tree, is it considered a perfect binary tree?. What would be the
height? (2 marks)
VI. Using the resultant tree in “I”, explain how to search for node 100. (2 marks)
VII. Derive the equivalent expression tree if the resultant in-order output is a+b*c (infix notation).
Then derive the post order (postfix) and pre-order (prefix) notations. (5 marks)
VIII. Derive the equivalent expression tree if the resultant in-order output is M, N, O, P, Q, R. Then
derive the post order and pre-order output. (5 marks)
………………………END OF PAPER……………………………….
Page 4 of 4