def bsearch(arr, x):
def recurse(min, max):
if min > max:
return None
mid = (min + max) // 2
if x == arr[mid]:
return mid
if x > arr[mid]:
min = mid + 1
else:
max = mid - 1
return recurse(min, max)
return recurse(0, len(arr) - 1)
arr = [1,2,3,4,5]
for i in range(7):
print(bsearch(arr, i))
To embed this project on your website, copy the following code and paste it into your website's HTML: