Explain how to modify the recursive binary search algorithm

Explain how to modify the recursive binary search algorithm so that it returns the index of the target in the sequence or -1 (if the target is not found).

Solution

Here is the code for you:

Recursive Binary Search:
Algorithm RBS(array[1..n], low, high, key)
if low <= high:
mid = (low + high) / 2
if(array[mid] == key):
return mid
else if(key < array[mid]):
return RBS(array, low, mid-1)
else
return RBS(array, mid+1, high)
return -1

Explain how to modify the recursive binary search algorithm so that it returns the index of the target in the sequence or -1 (if the target is not found).Soluti

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site