Professional Documents
Culture Documents
PRG3201 (F) Jan14
PRG3201 (F) Jan14
PRG3201 (F) Jan14
This paper consists of SIX (6) questions. Answer any FOUR (4) questions in the answer
booklet provided. All questions carry equal marks.
Question 1
(a) Explain in terms of efficiency, why the binary search algorithm is a better technique
compared with the sequential search?
(5 marks)
(14 marks)
What will the following function returns if the value of x and y are :
i) 28, 24
ii) 20, 10
iii) 7,8
(6 marks)
Question 2
i) Hashing
ii) Collision
iii) Primary Clustering
(6 marks)
(b) Explain how probability search is different from the general sequential algorithm by
providing both algorithms. You need to include only the parts of the algorithm that show the
differences.
(9 marks)
(c) Given the following keys, calculate the home address using pseudorandom technique for
each key. If there is a collision, use the pseudorandom collision technique to solve the
collision. (Assume a= 3,c = 1 and size of the array is 301)
i) 123456
ii) 123556
iii) 124615
iv) 124916
(10 marks)
(Total Marks: 25 marks)
PRG3201 (F) / Page 3 of 6
Question 3
String getName()
{
return name;
}
int getId()
{
return id_num;
}
Write a class to implement the above interface using an array based structure.
(25 marks)
(Total Marks: 25 marks)
PRG3201 (F) / Page 4 of 6
Question 4
(a) Figure Q4 represents a circular linked list. Answer the following questions based on the
diagram.
first
first
Figure Q4
You may assume the following definition of Node used in the linked list:
(i) Write the implementation of a method called addLast() to add a new node to the
end of the linked list.
(10 marks)
(ii) Write the implementation of a method called removeLast() that will remove the
last node from the linked list.
(15 marks)
Question 5
Node()
{
setNode(null,null,null);
}
Node(String name, Node l, Node r)
{
setNode(name,l,r);
}
String getName()
{
return name;
}
i) Write the method to insert a node into a Binary Search Tree structure.
(18 marks)
ii) Write the method to traverse the tree using the Inorder() traversal.
(7 marks)
Question 6
(a) What will happen when 3 and 1 is inserted into the AVL (Adelson-Velskii and Landis)
tree in figure Q6(a) ? What must be done in order to correct the situation? Illustrate
your explanation using tree diagrams.
73
28 111
5
Figure Q6(a)
(8 marks)
(b) Show the traversal order using the breadth-first traversal algorithm and the depth first
traversal order for the graph in figure Q6(b), given the vertex A is the origin vertex.
A D G
B H
C E F
Figure Q6(b)
(6 marks)
28 5 73 2 100 20 14 3