August
1999 QUESTION 1 (Compulsory) Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
(a) | Briefly explain the following terms : (i) Sorting (ii) Searching (iii) White box testing (iv) Black box testing |
[1] [1] [1] [1] |
(i) Sorting is the action of arranging elements of data into a defined order. (ii) Searching is looking through a collection of data for a particular item of data. (iii) White box testing is a module or program using a knowledge of its internal workings to see if the outputs are correct given the inputs. (iv) Black box testing is testing a module or program without a knowledge of its internal workings to see if the outputs are correct given the inputs.
|
||
(b) | (i) Explain, informally, how a selection sort
works, and state how many passes of an unsorted list of length N it will take to
ensure the list is sorted. (ii) Explain, informally how a binary search works, and state the maximum number of passes it will take over a list of length N to find an item. |
[3]
[3] |
(i) A selection sort works by:
(ii) A binary search works by:
|
||
(c) | Given the following definition of a binary
tree, and the procedure FooBar TYPE
PROCEDURE (FooBar VAR root : TreeType; item : Integer)
END; (i) Describe the effect of the procedure FooBar on the root of a tree like the one above. (ii) Assuming an initially empty tree, illustrate, with the aid of a diagram, the tree resulting from the following code fragment : Foobar(6); |
[2]
[4] |
(i) The procedure FooBar will:
(ii) The tree will look as follows:
|
||
(d) | Write a recursive function, Power, which takes two integer arguments, x and y, and returns xy. You can assume that both parameters will be greater than zero. | [4] |
A sample definition of
Power follows: FUNCTION
Power(x, y: Integer) : Integer |