def rec_binary_search(array, target, low, high):
if high >= low:
mid = low + (high - low) // 2
if target < array[mid]:
return rec_binary_search(array, target, low, mid-1) # left half
elif target > array[mid]:
return rec_binary_search(array, target, mid + 1, high) # right half
else:
return mid
else:
return -1
Time Complexity: O(log n)
Fact
If all the names in the world are written down together in order and you want to search for the position of a specific name, binary search will accomplish this in a maximum of 35 iterations.