Skip to content

Instantly share code, notes, and snippets.

@anonymousmaharaj
Created March 13, 2021 17:26
Show Gist options
  • Save anonymousmaharaj/34f69b78d6492be78382ea580a126075 to your computer and use it in GitHub Desktop.
Save anonymousmaharaj/34f69b78d6492be78382ea580a126075 to your computer and use it in GitHub Desktop.
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