Question: boolean binarySearch ( int target, int first, int last ) / / Precondition: first and last are legal indices of values / / / /

boolean binarySearch(int target, int first, int last)
// Precondition: first and last are legal indices of values
//
// If target is contained in values[first,last] return true
// otherwise return false.
{
int midpoint =(first + last)/2;
if (first > last)
return false;
else
if (target == values[midpoint])
return true;
else
if (target > values[midpoint])
return binarySearch(target, midpoint +1, last);
else
return binarySearch(target, first, midpoint -1);
}
The sorted values array contains 16 integers 5,7,10,13,13,20,21,25,30,32,40,45,50,52,57,60. Indicate the sequence of recursive calls that are made to binaraySearch, given an initial invocation of binarySearch(19,0,15). Show all recursive calls in order.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!