The Open University of Sri Lanka Faculty of Engineering Technology Department of Electrical and Computer Engineering
The Open University of Sri Lanka Faculty of Engineering Technology Department of Electrical and Computer Engineering
General Instructions
Page 1 of 4
Q1
(a) Briefly explain why the Time complexity is significant in algorithms. [02]
(b) What are the Asymptotic notations and explain them briefly. [03]
(c) Each of the expressions below gives the processing time spent by an algorithm for
solving a problem of size n. By explaining your work find the lowest Big-Oh
complexity of each problem. [15]
i) n2 log 2 n + n(log 2 n)2
ii) 3 log 8 n + log 2 (log 2 (log 2 n))
iii) n log 2 n + n(log 2 n)2
iv)
For (int i = n; i > 0; i /= 2) {
For (int j = 1; j < n; j *= 2) {
For (int k = 0; k < n; k += 2) {
... // constant number of operations
}
}
}
v)
For (i = 1; i < n; i *= 2) {
For (j = n; j > 0; j /= 2) {
For (k = j; k < n; k += 2) {
sum += (i + j * k);
}
}
}
Q2
(a) Write the pseudocode algorithms for the following standard operations in stack data
structure. State any assumptions you make.
i) initialize() ii) isEmpty() iii) isFull()
iv) pop() v) push()
[10]
(b) Convert the following algebraic expression to postfix form using a stack as in the table
below. Show the steps for each character:
[10]
Page 2 of 4
Q3
(a) Describe what is a binary search tree (BST)? [02]
(b) Construct a BST for the following sequence of numbers by taking the first element as the
root: [12]
{13, 3, 4, 12, 14, 10, 1, 8, 2, 7, 9, 11, 6, 18, 15}
(c) Use the BST in (b) to write all three traversals. [03]
(d) Draw the new trees after deleting:
i) The element 14 from the tree drawn in (b), [01]
ii) The element 13 from the tree drawn in (d) - i). [02]
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. Show your steps in the table form. Cross out old values and write in new
ones, from left to right, as the algorithm proceeds. [16]
(b) Obtain an adjacency matrix for the above graph. [02]
(c) Show the above matrix as an adjacency list. [02]
Page 3 of 4
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]
Q6
(a) What is hash collision? [03]
(b) Describe three hash collision resolution techniques? [03]
(c) Use one of the techniques you mentioned in (b) to construct a non-collision hash table
of length 13 for the given keys in the same order,
{4684, 4879, 5651, 1829, 1082, 7107, 1628, 2438, 3951, 4758, 6967, 4989}
by using the hash function,
h(k) = (sum of all digits of a key) MOD 13. [12]
(d) Give an advantage and disadvantage of each of the technique that you used in (c). [02]
Q7
(a) Briefly explain with illustrations, the workings of:
i) Selection sort algorithm; [05]
ii) Quicksort algorithm; [05]
(b) Using the last item as the pivot in Quicksort, explain with illustrations, why Quicksort
performs very poorly (in terms of runtime) if the items are already in sorted order. You
can use any sorted array with at least eight (8) numbers. [10]
-- End –
Page 4 of 4