Last active
July 1, 2021 14:34
-
-
Save Hemanthkumar2112/df602aca2cabbc59a2f6505939d25bea to your computer and use it in GitHub Desktop.
binary search in recursive [o(logn)]
This file contains hidden or 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 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