Last active
September 10, 2020 17:11
-
-
Save Svastikkka/7d9b3e17f129c32774bd95f9c9dc1d04 to your computer and use it in GitHub Desktop.
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(a,x,si,ei): | |
if si>ei: | |
return -1 | |
mid=(si+ei)//2 | |
if a[mid]==x: | |
return mid | |
elif a[mid] >x: | |
ei =mid-1 | |
return BinarySearch(a,x,si,ei) | |
elif a[mid] <x: | |
si=mid+1 | |
return BinarySearch(a,x,si,ei) | |
a=[1,2,3,4,5,6] | |
print(BinarySearch(a,4,0,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Binary Search Recursive Way