December
1999 QUESTION 5 Total Marks: 15 Marks |
Click here to access other
questions
Click to access |
(a) |
Briefly describe the Binary Search algorithm.
|
[2] |
(b) |
State the worst case number of comparisons needed to perform a complete Binary Search on a list of size N.
|
[1] |
(c) |
Given the sorted list x below, show how the positions of the indicators Left (L ), Right (R )and Middle (M )evolve during a binary search for the number 23.
|
[5] |
(d) |
Write a function BSearch, the signature
of which is given below, which takes a sorted list x of type ListType,
a integer y specifying the length of the list, and a search term z
of type ListElement, which is the type of data held in the list, and
searches the list for the search term using the binary search algorithm.The
function should return the position of the item in the list if it
is present, or -1 otherwise. In your function, you can use the list
interface function DataAt, the signature of which is also given below,
which will return the value of the data item stored at position y
in the list
|
[7] |