University of Western Australia
Data Structures 201
Final Examination
June 1994
This paper contains:
Questions in Section A each carry 5 marks.
Questions in section B each carry 10 marks. Marks for this paper total
35.
Candidates should answer all three questions from Section A,
and only two questions from Section B.
_________________________________________________________________________________________
Answer all three questions from this section.
_________________________________________________________________________________________
Draw diagrams representing the results of evaluating the following expressions:
__________________________________________________________________________________
continued...
Draw diagrams representing the results of evaluating the following expressions
__________________________________________________________________________________
_________________________________________________________________________________________________________________________________
continued...
Answer two questions from this section.
_________________________________________________________________________________________
This question uses the following declaration of a type of binary trees:
datatype Tree = Lf  Nd of Tree * int * Tree

We assume that implementations of the following heap operations are provided
val insert : int * Tree > Tree
val remove : Tree > int * Tree val downheap : Tree > Tree 
These operations satisfy the following properties:
Draw a diagram of the result of the operation downheap(t), where t is the tree
Nd
(Nd (Nd (Lf, 1, Lf), 4, Nd (Lf, 0, Lf)), 3, Nd (Nd (Lf, 5, Lf), 8, Nd (Lf, 2, Lf))) 
Give an ML signature QueueSig suitable for a Priority Queue of integers.
Write a functor with header
functor HPQ(
datatype Tree = Lf  Nd of Tree * int * Tree val insert : int * Tree > Tree val remove : Tree > int * Tree val downheap : Tree > Tree ) : QueueSig 
that uses these functions to implement an integer priority queue.
_________________________________________________________________________________________________________________________________
continued...
Describe the operations on these datastructures that are used by Kruskal’s algorithm. (Give the type of each operation, and briefly describe its effect. You are not asked to describe the implementation of these operations.)
What are the complexities of the priority queue operations, if the queue is implemented using a heap?
What is the complexity of a suitable sorting algorithm?
Consider a graph, G = (V,E). Compare the complexities (in terms of the sizes of the sets (V,E)) of the two implementations of Kruskal’s algorithm. You may assume that the operations on a partition are O(1), (this is not strictly correct, but it is a good approximation, adequate for all practical purposes).
_________________________________________________________________________________________________________________________________
continued...
What is an efficient hash function?
An implementation of sets of integers as balanced searchtrees is “improved” by
hashing with a hash table of size 117 and the hash function
fun hash n = n mod 117
(each entry in the hash table is itself a balanced searchtree).
For each of the following set operations, give the complexity (in terms of the size, N, of the set) for the original implementation, and say what speedup (or slowdown) you would expect to obtain from the introduction of hashing. (Assume that the hash function is efficient for the data encountered, and that the cost of computing the hash function may be ignored.)
__________________________________________________________________________________
The End