Skip to content

Instantly share code, notes, and snippets.

@Svastikkka
Last active September 10, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Svastikkka/7d9b3e17f129c32774bd95f9c9dc1d04 to your computer and use it in GitHub Desktop.
Save Svastikkka/7d9b3e17f129c32774bd95f9c9dc1d04 to your computer and use it in GitHub Desktop.
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))
@Svastikkka
Copy link
Author

Binary Search Recursive Way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment