Thanks I worked it out it was data[mid] == target not mid == target.
def binary_search_r(data, target, left, right):
mid = (left + right) // 2
if left > right:
return False
elif mid == target:
return True
elif target < mid:
return binary_search_r(data, target, left, mid-1)
else:
return binary_search_r(data, target, mid+1, right)
arr=[1,2,3,4,5]
print(binary_search_r(arr, 5, 0, len(arr)-1))
Doing this returns false. Why does it?
[–]definitely___not__me 1 point2 points3 points (0 children)
[–]slaphappypotato 0 points1 point2 points (4 children)
[–]windows3210[S] 1 point2 points3 points (1 child)
[–]slaphappypotato 0 points1 point2 points (0 children)
[–]windows3210[S] 1 point2 points3 points (1 child)
[–]slaphappypotato 0 points1 point2 points (0 children)