THE OPEN UNIVERSITY OF SRI LANKA
FACULTY OF ENGINEERING TECHNOLOGY
DEPARTMENT OF ELECTRICAL & COMPUTER ENGINEERING
BACHELOR OF SOFTWARE ENGINEERING PROGRAMME – LEVEL 4
EEX4465 – DATA STRUCTURES AND ALGORITHMS
CONTINUOUS ASSESSMENT TEST #2 (ONLINE) – 2020/2021 OPEN BOOK TYPE
Date: 01 October 2021 Time: 0730 – 0845 hrs.
Read the instructions below
• Use A4 papers to answer the given questions.
• Write your registration number, name, and course code on the top right-hand side of
each paper. Number each page of your answer script.
• Use a mobile device/Camera or any other to scan each paper (handwritten answers) and
make a pdf file. E.g., Adobe scan app in mobile device
• Rename the file in the format below:
eex4465_registration number_CAT2_20-21
• Upload the file into the Google drive link provided. You have an additional 30 minutes.
Answer ALL questions.
Q1. Assume the elements of a n by n matrix stored in a 2-D array called array2D[n][n].
The diagonal elements are inside the two dashed lines.
𝑎11 𝑎12 𝑎13 . . . . . . 𝑎1𝑛
𝑎21 𝑎22 𝑎23 . . . . . . 𝑎2𝑛
𝑎31 𝑎32 𝑎33 . . . . . . 𝑎3𝑛
𝑎𝑟𝑟𝑎𝑦2𝐷[𝑛][𝑛] = : : : : : :
: : : : : :
[ 𝑎𝑛1 𝑎𝑛2 𝑎𝑛3 . . . . . . 𝑎𝑛𝑛 ]
You need to store the corresponding elements from the matrix into three 1-D arrays
called lower[ ], diag[ ] and upper[ ], separately as below. [30]
Write pseudocode algorithms to store the elements of:
(a) The lower triangle (without the elements of the diagonal) into the array, lower[ ] in
row-wise order, i.e., 𝑎21 , 𝑎31 , 𝑎32 , 𝑎41 , . . . , 𝑎𝑛,𝑛−2 , 𝑎𝑛,𝑛−1
(b) The diagonal into the array, diag[ ] with the same order,
i.e., 𝑎11 , 𝑎22 , 𝑎33 , . . . , 𝑎𝑛−1,𝑛−1 , 𝑎𝑛𝑛
(c) The upper triangle (without the elements of the diagonal) into the array, upper[ ] in
row-wise order, i.e., 𝑎12 , 𝑎13 , . . . , 𝑎1𝑛 , 𝑎23 , 𝑎24 , . . . , 𝑎2𝑛 , . . . , 𝑎𝑛−2,𝑛−1 , 𝑎𝑛−2,𝑛 , 𝑎𝑛−1,𝑛
Page 1 of 2
Q2. Consider the set of integer values given by
S = {56, 85, 48, 90, 72, 6, 87, 36, 22, 15}
(a) By taking the first value as the root, build a binary search tree (BST) for the S. [05]
(b) Write pseudo code algorithms to:
i) Obtain the post-order traversal of the BST in part (a) and write the output. [10]
ii) Insert a given value into a BST by using recursion and redraw the BST in part (a)
after inserting the value 65. [10]
(c) Redraw the tree after deleting the value 85 from the BST obtained in part (b) ii). [05]
Q3. Table 1 shows the time (in minutes) taken to travel between each town (8 towns) that
denoted from A, B, … H. The time taken to travel between any two towns is not
always similar for the reverse direction due to road conditions.
Table 1: The time taken (in minutes) to travel between towns
To
Town
A B C D E F G H
A 0 7 5 - 20 - - -
B 10 0 - - - - 10 -
C 5 - 0 20 - 10 - -
-
From
D - - 10 0 - - -
E 20 - 10 - 0 - - 30
F - - 10 - 10 0 - -
G - 5 - - - - 0 35
H - - - - 30 - 25 0
(a) Draw a directed weighted graph according to the information given above. [10]
(b) Calculate the minimum time to travel from town A to town H by applying Dijkstra's
shortest path algorithm (single source all destinations). Show the predecessor and
distance arrays following each step of Dijkstra's algorithm. [20]
(c) Write the pseudocode algorithm for depth first search for the graph obtained in part (a)
and give the sequence of the output nodes starting from node A. [10]
-- End –
Page 2 of 2