You are on page 1of 1

def binarySearch(arr, l, r, target):

if r >= l:
mid = l + int((r - l)/2)

if arr[mid] == target:
return True
elif arr[mid] > target:
return binarySearch(arr, l, mid-1, target)
else:
return binarySearch(arr, mid+1, r, target)
else:
return False

arr = [1, 3, 5, 6, 8, 9]

print(binarySearch(arr, 0, len(arr) - 1, 6))

You might also like