next up previous contents
Next: Solution Up: Procedures and Modules Previous: Solution

 

Binary Cut

Write a module containing a function which returns the position of a particular number in an array of sorted integers. The function should employ the so-called ``binary cut'' method. This method proceeds by determining in which half the number is and then concentrating on that half. It is easily implemented using two indices to point at the low and high positions of the current area of interest. It is assumed that if there is more than one ocurrence of the number then the one with the higher index will be chosen. This method is very efficient for very large arrays.

Algorithm,




next up previous contents
Next: Solution Up: Procedures and Modules Previous: Solution

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 14:10:26 GMT 1996