binary search python
# This is real binary search
# this algorithm works very good because it is recursive
def binarySearch(arr, min, max, x):
if max >= min:
i = int(min + (max - min) / 2) # average
if arr[i] == x:
return i
elif arr[i] < x:
return binarySearch(arr, i + 1, max, x)
else:
return binarySearch(arr, min, i - 1, x)