Cosc 325 Exam
Cosc 325 Exam
Cosc 325 Exam
CHUKA UNIVERSITY
UNIVERSITY EXAMINATIONS
EXAMINATION FOR THE AWARD OF DEGREE OF BACHELOR OF SCIENCE IN
COMPUTER SCIENCE
COSC 325: DATA STRUCTURES
STREAMS: BSC (COMPUTER SCIENCE) TIME: 2 HOURS
DAY/DATE: FRIDAY 07/12/2018 11.30 A.M. – 1.30 P.M.
INSTRUCTIONS:
b) Asymptotic notations are commonly used to describe the complexity of an algorithm with
respect to the input size n.
i) For each function f(n) below, give an asymptotic upper bound using big-Oh notation
i. f(n) = 10n3 - 7n3 + 14n2 [1 Mark
ii. f(n) = 10n3 - 10n3 + 7n2 [1 Mark]
2
iii. f(n) = log(7n ) [1 Mark]
ii) Describe the worst case running time of the following code in terms of the variable n.
Explain your answer; [3 Marks]
void looper (int n) {
for(int i=0; i < n; i++)
for(int j=0; j < 10; j++)
for(int k=0; k < n; k++)
for(int m=0; m < 10; m++)
cout<<("m !");
}
c) Describe briefly [4 marks]
i. Any one sorting algorithm and
Page 1 of 3
COSC 325
d) Illustrate the operation of the sorting algorithm described in part (c) i above on the following
list of integers [4 marks]
D A T A S T R U C T U R E
f) Suppose we begin with an empty stack, and perform the following operations: push 7, push
2, push 9, push 6, pop, pop, peek, push 1, push 3, peek, push 8, pop, peek, pop, pop, push 5,
push 4, pop, pop, pop, push 8. What is contained on the stack when we are done? Write out
the contents from top to bottom. [4 marks]
g) Given two scenarios: the first in which a problem solution involves a dynamic list (i.e. list in
which there are a lot of deletions and insertions) and the second in which a problem involves
many accesses to the interior values of a list. State with reasons which data structure will be
suitable for each of the two scenarios? [3 marks]
d) Name the three traversal orders for binary trees and show the result of each of these traversals on
the above binary search tree. [6 marks]
Page 2 of 3
COSC 325
e) Describe any two methods for storing binary trees in the computer [4 marks]
c) Describe two principal methods for representing graphs for computer algorithms
[6 marks]
d) If a graph is sparse which representation will you use and why? [2 marks]
5
a b
1
7 1
c d
2
Represent the weighted graph using the two representation methods described in part (c) above.
[6 marks]
---------------------------------------------------------------------------------------------------------------------
Page 3 of 3