datastructures2
datastructures2
a) Write down the algorithm for merge sort and state its big O.
[6 Marks]
b) Performing operations such as delete and insert in a doubly linked list is not easy.
Explain.
[4 Marks]
c) Explain how the divide and conquer technique works. Give two examples.
[4 Marks]
d) Represent the following expression tree: (((A+B)*C+D)*E)-((A+B)*C-D) and write
the prefix and postfix expressions.
[6 Marks]
[4 Marks]
c) Describe two applications of binary search trees.
[2 Marks]
d) ) Explain why a queue is a two-point structure where a stack is one point structure
[3 Marks]
e) What is an algorithm?
[2 Marks]
f) Describe the following properties that an algorithm must have: precision, uniqueness,
finiteness, input and output.
[5 Marks]
[4 Marks]
d) Describe two ways of representing a graph ADT.
[4 Marks]
e) Construct a directed graph with the vertices A,B,C,D and E using the information
below.
A B C D E
A 0 0 5 6 0
B 0 0 4 5 2
C 4 5 0 4 6
D 6 0 0 0 0
E 5 0 0 0 0
[5 Marks]
f) Briefly describe the depth first search algorithm as used in graph traversal.
[2 Marks]
QUESTION FIVE [20 MARKS]
a) If two or more values in a hash function, map to the same key, a collision is said to
occur. Collisions are not allowed in a hash table. Briefly describe the following
techniques for resolving collisions.
i. re-hashing
ii. chaining
iii. linear probing.
[6 Marks]
b) Differentiate between dynamic programming and backtracking algorithms. Give one
example for each.
[4 Marks]
c) Describe the guidelines for developing an algorithm using a pseudo code.
[5 Marks]
d) Describe the procedure for insert sort.
[3 Marks]
e) Re-arrange the following numbers in descending order using insert sort.
2,4,8,6,10,16,12,14,20,18.
[2 Marks]