Created
March 13, 2021 17:26
-
-
Save anonymousmaharaj/34f69b78d6492be78382ea580a126075 to your computer and use it in GitHub Desktop.
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 binari_search (list,item): | |
low = 0 | |
high = len(list)-1 | |
while low <= high: | |
mid = (low+high)//2 | |
guess = list[mid] | |
if guess == item: | |
return guess | |
if guess> item: | |
high = mid -1 | |
else: | |
low = mid+1 | |
return None | |
list = ["a",'b','c',"d",'e','f',"g",'h'] | |
item = 'f' | |
i = binari_search(list,item) | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment