I am trying to implement binary search with the following function:
def buggy_binary_search(input, key):
low = 0
high = len(input)-1
mid = (low + high)/2
while low <= high:
if input[mid] == key:
return mid
if input[mid] > key:
high = mid - 1
else:
low = mid
return -1
The above function when run, gets into a infinite loop. How can I correct that?