The purpose of this lab is to understand the concept of a recursive divide an conquer search algorithm by writing the function. For this lab you will implement the recursive binary search algorithm for a given sorted integer array.
Given: sorted array, start index, end index, key to search for
Returns: index where key is found or -1 if key is not in array
if start or end indices are invalid --> stopping condition
return -1
end-if
if start is greater than or equal to end
if array[start] is equal to key
return start
else
return -1
end-if
end-if
calculate mid = (start + end) / 2
// or mid = start + (end - start) / 2
// this avoids overflow of int value
if array[mid] is equal to key
return mid
else if array[mid] is less-than key (search right)
return binarySearch(array, mid+1, end, key)
else (key is less-than array[mid], search left)
return binarySearch(array, start, mid-1, key)
end-if
Show me your completed code in class or have lab12.cpp the files within your depository directory. ~/2020_S19/wk12/