EEX4465 2020 21 - Final
EEX4465 2020 21 - Final
General Instructions
Page 1 of 4
Q1
(a) Briefly explain the terms: [02]
Time complexity and Space complexity
(b) Explain the following notations: [03]
i) Big-Oh ii) Big-Omega iii) Big-Theta
(c) Find the worst-case running time for the following expressions/functions in Big-Oh
notation in terms of the variable n. Explain your work. [15]
i) The growth of the sum 1 + 1/2 + 1/3 + . . . + 1/n.
ii) An algorithm takes an n by n Boolean matrix as the input. If the running time of the
algorithm is O(n log n) when n is used as the input size, then what is the running
time of the algorithm for n2.
iii) When inserting n elements into an initially empty binary search tree.
iv) Sorting n 32-bit unsigned integers by using Insertion Sort.
v) The function T(𝑛) = 2T( 𝑛/3) + √𝑛.
Q2 A lower triangular matrix is one in which all elements above the main diagonal are zero
of a square matrix. Assume we have an n by n lower triangular matrix L. Answer the
following questions:
(a) What is the maximum number of nonzero terms in L? [03]
(b) If each element can be stored in a 32-bit signed integer, what is the memory size that
would be needed to store all nonzero terms stated in (a). [02]
(c) Since storing a triangular matrix as a two-dimensional array, is a waste of memory
space. Therefore, write a complete pseudocode algorithm to store only the lower
triangular elements (with the main diagonal) of L in a one-dimensional array called,
arryL. [15]
Q3
(a) Describe what is a binary search tree (BST)? [02]
(b) What is the maximum number of nodes in a binary tree of depth d ? [02]
(c) When constructing a BST, what is the method you use if the sequence of numbers has
duplicates? [03]
(d) Construct a BST for the following sequence of numbers by taking the first element as the
root: [10]
{45, 32, 90, 21, 78, 65, 87, 132, 90, 96, 41, 74, 92}
(e) Use the BST in (d) to find the: [03]
In-order, Pre-order, and Post-order traversals
Page 2 of 4
Q4 Consider the following directed, weighted graph to answer the questions below.
(a) Step through Dijkstra's algorithm to calculate supposedly shortest paths from A to every
other vertex. You should consider negative weight edges as well. Show your steps in the
table form. Cross out old values and write in new ones, from left to right, as the algorithm
proceeds. [15]
(b) Dijkstra's algorithm found the wrong path to some of the vertices. For just the vertices
where the wrong path was computed, indicate both the path that was computed and the
correct path. [03]
(c) What single edge could be removed from the graph such that Dijkstra's algorithm would
happen to compute correct answers for all vertices in the remaining graph? [02]
Q5 Consider the following operands and operators with their precedence for logic
expressions. Note that you must consider left and right parenthesis as well.
(a) Write the pseudocode algorithm to convert a string of logic expression into its
expression tree. You can use any data structure to represent the tree and should explain
how your data structure logically relates to the tree. Since ~ is a unary operator, you
should put its only operand to its right child. [12]
(b) Draw the expression tree of the following logical expression: [04]
~ (0 & ~ 1 & 0 | 0) & 0
(c) Obtain the prefix and postfix notations for the given expression in (b). [04]
Page 3 of 4
Q6
(a) What is hashing? [02]
(b) For what purpose the hashing used in data structures? [02]
(c) Describe another two methods which can be used for the purpose written in (b). [04]
(d) What is hash collision and how it can be handled? [02]
(e) Construct a non-collision hash table resulting from the hashing with the given keys,
{12, 44, 13, 88, 23, 94, 11, 39, 20, 16, 5}
by using the hash function,
h(k) = (2k + 5) MOD n,
where n is the number of elements. [10]
Q7
(a) Write the complete pseudocode for the Quick Sort algorithm. [06]
(b) Use the Quick Sort algorithm to sort the following numbers. You should show the step-
by-step procedure. [14]
{2, 6, 7, 5, 10, 9, 2, 4}
-- End –
Page 4 of 4