0% found this document useful (0 votes)
9 views6 pages

2010 Ce 204

Uploaded by

Somya Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

2010 Ce 204

Uploaded by

Somya Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CE204-5-SP

UNIVERSITY OF ESSEX

Undergraduate Examinations 2010

DATA STRUCTURES AND ALGORITHMS

Time allowed: TWO hours

Candidates must answer QUESTION 1 in SECTION A


and TWO questions from SECTION B.

The paper consists of four questions.

The questions are NOT of equal weight.

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

Candidates must answer Question 1 in 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();
}

Write a method that takes an argument of type BinaryTree<Character>


and uses a pre-order traversal to calculate and return the number of upper-case
letters in the tree specified in the argument.

(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%]

exp lp exp rp | exp op exp | number


op plus | minus | times

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

Candidates must answer TWO questions from 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();
}

The class should provide an implementation of a standard first-in-first-out queue. The


objects in the queue should be stored in a linked list of objects of type QueueCell.
QueueCell should be written as an inner class. If applied to an empty queue the
frontValue and removeFront methods should throw an exception – you may
assume that an appropriate QueueException class has been declared. A no-
argument constructor should be provided to ensure that a newly-created queue will be
empty.

(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;
}

public class BST


{ private BTNode<String> root;
public BST() {………}
public void insert(String i) {………}
public boolean find(String i) {………}
}

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

END OF PAPER CE204-5-SP

You might also like