CS470
Programming assignment: Recursive binary search
In this MIPS programming assignment, you will write a
program that will do a binary search.
Specifications:
The inputs and the output for the main program are:
Inputs:
Output:
-1 if not found
The array starts in location ARRY and the count is in location CNT. Assume that the minimum size of the array is three. The
integer toFind
should be input interactively, and the result should be printed.
Documentation: Use
comments to document the program including the use of registers and the
inputs/outputs of both functions.
Psuedocode for the subroutine
int binary_search(int *data, int toFind, int
start, int end)
{
int mid = start + (end -
start)/2; //Integer division
if
(start > end)
return -1;
else
if (data[mid] == toFind) //Found?
return mid;
else
if (data[mid] > toFind) //search lower half
return binary_search(data, toFind, start, mid-1);
else //search upper
half
return binary_search(data, toFind, mid+1, end);
}