Last active
February 12, 2020 07:23
-
-
Save arpit-omprakash/839059c3eef6724ca06f9e38f47217a1 to your computer and use it in GitHub Desktop.
Binary search recursive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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