Skip to content

Instantly share code, notes, and snippets.

@arpit-omprakash
Last active February 12, 2020 07:23
Show Gist options
  • Save arpit-omprakash/839059c3eef6724ca06f9e38f47217a1 to your computer and use it in GitHub Desktop.
Save arpit-omprakash/839059c3eef6724ca06f9e38f47217a1 to your computer and use it in GitHub Desktop.
Binary search recursive
def binarySearch (arr, l, r, x):
if r >= l:
mid = l + (r - l)/2
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)
else:
return binarySearch(arr, mid+1, r, x)
else:
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment