Binary Search

Photo by Markus Winkler on Unsplash
def binary_search(lst, low, high, key):
if low<=high :
mid=(low + high)//2
if lst[mid]==key:
return mid
elif lst[mid]>key:
return binary_search(lst,low,mid-1,key)
else:
return binary_search(lst,mid+1,high,key)
else:
return None

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store