Computer Science Tripos Part I
Computer Science Tripos Part I
Answer one question from each of Sections A, B and C, and two questions from
Section D.
Submit the answers in five separate bundles, each with its own cover sheet. On each
cover sheet, write the numbers of all attempted questions, and circle the number of
the question attached.
SECTION A
4
3
2
1
0
0 1 2 3 4
Here horizontal and vertical bars indicate walls. One can step from a position to
an adjacent position if there is no wall obstructing the move. For example, one can
move in one step from position (1,1) to position (2,1), but not to (1,0). Diagonal
steps are not allowed.
(b) Use next to code, in ML, a space-efficient function that checks whether it is
possible to move from a position (x1,y1) to another position (x2,y2) in a
given labyrinth. For full marks, make sure your function always terminates.
[6 marks]
(c) Explain, not necessarily using ML code, how one can code a function that
returns the shortest path between two given positions. Here path means a list
of all the positions one would visit en route to the destination. The solution
must be space efficient and practical even for large labyrinths. Briefly explain
why your solution is space efficient. [6 marks]
2
CST.2011.1.3
(a) Write brief notes on exceptions in ML and on the functions and control
structures available for programming with them. [6 marks]
(b) Code in ML a function called cannot which takes two arguments, a function f
and a value x. Define the cannot function in such a way that it returns true
if and only if evaluation of f(x) causes exception Olive. For all other inputs,
it should return false. [Hint: evaluation of f(x) may cause exceptions other
than Olive.] [4 marks]
(c) Consider the following ML datatype and functions bun and cheese.
3 (TURN OVER)
CST.2011.1.4
SECTION B
3 Discrete Mathematics I
(a) Write down the introduction and elimination rules for implication and
negation. [4 marks]
(b) Using the rules from part (a), give a structured proof of
(d ) Using the rules from parts (a) and (c), give a structured proof of
4
CST.2011.1.5
4 Discrete Mathematics I
(a) Write down a set of ordered pairs that describes the graph. [3 marks]
• state whether the formula holds of the relation in part (a) (when the
domain of x, y, and z is the set {a, b, c});
• if the formula does not hold, exhibit a relation over {a, b, c} for which the
formula does hold.
[14 marks]
(c) Write down the introduction and elimination rules for the universal quantifier
in structured proof. [3 marks]
5 (TURN OVER)
CST.2011.1.6
SECTION C
5 Algorithms I
Mathematical hint: the following series converges to the indicated value if |x| < 1
∞
X x
mxm =
m=1
(1 − x)2
(a) The binary min-heap provides a decreaseKey() method that, when applied
to an element, decreases its key while preserving the properties of the data
structure.
(b) Generalise the binary min-heap to one where nodes have not 2 but k children.
6
CST.2011.1.7
6 Algorithms I
Mathematical hint: the following series converges to the indicated value if |x| < 1
∞
X x
mxm =
m=1
(1 − x)2
(a) You are given an unsorted array of n items of which you must return the
top k, in any order. Give a clear and accurate description of two efficient
algorithms for solving the problem, following the hints below, and derive their
time complexity in terms of n and k.
(ii ) For this attempt, start by finding the k-th largest item, as when
computing order statistics. Describe all the steps in detail. [8 marks]
(b) You are given a hash table that stores n keys. It has m slots; collisions are
resolved by chaining (each hash table slot contains a pointer to the head of the
corresponding chain; no elements are stored in the table itself) and no chain
is longer than L elements. Each slot has an extra field giving the length of the
corresponding chain.
The time complexity of a reasonable algorithm will not exceed O(m + L), but
solutions awarded full marks will improve on that.
[10 marks]
7 (TURN OVER)
CST.2011.1.8
SECTION D
7 Computer Fundamentals
(a) What is the key idea behind the von Neumann architecture? To what extent
do modern computers conform to this architecture? [2 marks]
(b) Explain why modern computers contain both Dynamic RAM (DRAM) and
Static RAM (SRAM). [4 marks]
(c) How do modern computers represent signed integer values? Why? [2 marks]
(ii ) What are pseudo instructions? Why are they used? [2 marks]
(e) Computer A has 32 32-bit registers, while Computer B has 16 64-bit registers.
Give two advantages that Computer A possesses over Computer B. [4 marks]
8
CST.2011.1.9
8 Floating-Point Computation
(b) Modify your answer to part (a) for when a hidden bit is used. [3 marks]
(d ) Describe four different rules for rounding a floating-point number and say
which is generally used and why. [2 marks]
(e) Give two techniques for determining the number of steps used in an iteration.
(Do not describe iterating until no change.) Say when one technique is
preferred to the other. [4 marks]
9 (TURN OVER)
CST.2011.1.10
Consider the following Java class that is intended to represent a specific day in an
eight-week University term.
(b) The use of two int variables to represent the day and the week requires
64 bits of storage. How many bits are actually required? Adapt
EncapsulatedTermDay class to achieve the same functionality using only one
member variable of a primitive type. You should justify your choice of type.
[4 marks]
END OF PAPER
10