Skip to content

Instantly share code, notes, and snippets.

@Hemanthkumar2112
Last active July 1, 2021 14:34
Show Gist options
  • Save Hemanthkumar2112/df602aca2cabbc59a2f6505939d25bea to your computer and use it in GitHub Desktop.
Save Hemanthkumar2112/df602aca2cabbc59a2f6505939d25bea to your computer and use it in GitHub Desktop.
binary search in recursive [o(logn)]
def binary_search(a:list,target:int)->str: ##found, notfound
if len(a)==0:return "NOT FOUND"
a.sort()
mid = len(a)//2
if a[mid]== target:return "FOUND"
else:
if a[mid] < target:return binary_search_re(a[mid+1:],target)
if a[mid] > target:return binary_search_re(a[:mid],target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment