2010 Ce 204
2010 Ce 204
UNIVERSITY OF ESSEX
The percentages shown in brackets provide an indication of the proportion of the total marks
for the PAPER which will be allocated.
Please do not leave your seat unless you are given permission by an invigilator.
Do not communicate in any way with any other candidate in the examination
room.
Do not open the question paper until told to do so.
All answers must be written in the answer book(s) provided.
All rough work must be written in the answer book(s) provided. A line should
be drawn through any rough work to indicate to the examiner that it is not part
of the work to be marked.
At the end of the examination, remain seated until your answer book(s) have
been collected and you have been told you may leave.
CE204-5-SP 2
SECTION A
Question 1
(a) [2%]
(i) Explain what is meant by the term binary tree.
(ii) Explain the difference between pre-order, post-order and in-order traversals for [4%]
binary trees.
(iii) The following interface specifies the binary tree type. [8%]
interface BinaryTree<T>
{ boolean isEmpty();
T rootValue();
BinaryTree<T> leftChild();
BinaryTree<T> rightChild();
}
(b) Describe what is meant by the halting problem and give a brief outline of how it can be [12%]
proven that it has no algorithmic solution.
(c) Describe the mergesort algorithm and comment briefly on its time complexity. [7%]
Question 1 continues…
3 CE204-5-SP
Question 1 continued.
(d) The following grammar describes a simple language of arithmetic expressions. [7%]
The symbols, lp, rp, plus, minus and times refer to the lexemes (, ), +, - and *
respectively and the symbol number refers to any non-negative integer.
Provide a declaration for a set of Java classes that could be used to store parse trees for
this grammar. The methods of the classes do not have to be declared.
END OF SECTION A
CE204-5-SP 4
SECTION B
Question 2
(a) Provide a complete Java class that implements the interface [28%]
interface StringQueue
{ boolean isEmpty();
void add(String i);
String frontValue();
void removeFront();
}
(b) Comment briefly on the time complexity of the operations provided in your answer to [2%]
part (a).
5 CE204-5-SP
Question 3
(a) Explain what is meant by the terms connected and acyclic as used to describe undirected [2%]
graphs.
(b) Explain what is meant by a spanning tree for a connected undirected graph. [3%]
(c) Describe Kruskal’s algorithm for finding minimum cost spanning trees in connected [9%]
undirected graphs.
(d) Show, step by step, the use of Kruskal’s algorithm to find a minimum cost spanning [16%]
tree for the graph shown below. At each stage you should show the connection sets.
10 9
A B C
T
4 3 7 2
5
H
D E F2
5 6
A
5
D
8
S
2
CE204-5-SP 6
Question 4
(a) A class to implement binary search trees of strings is given by the declarations [12%]
class BTNode<T>
{ T value;
BTNode<T> left, right;
}
Provide a complete body for the insert method; it should do nothing if the argument
string is already present in the tree.
(b) Show, step by step, the results of inserting the following numbers into an initially- [18%]
empty binary search tree, using the AVL rebalancing algorithm when necessary in
order to ensure that the tree is AVL-balanced after each insertion
3 5 16 36 27 11 14
END OF SECTION B