defrec_binary_search(array,target,low,high):if high >= low: mid = low + (high - low) //2if target < array[mid]:returnrec_binary_search(array, target, low, mid-1)# left halfelif target > array[mid]:returnrec_binary_search(array, target, mid +1, high)# right halfelse:return midelse: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.