Skip to content

Instantly share code, notes, and snippets.

@RamonRomeroQro
Last active December 12, 2018 07:41
Show Gist options
  • Save RamonRomeroQro/c43f3eb438910cf687e8a3b73c2cdfdd to your computer and use it in GitHub Desktop.
Save RamonRomeroQro/c43f3eb438910cf687e8a3b73c2cdfdd to your computer and use it in GitHub Desktop.
Binary Search in Python
def binarySearch(alist, item):
first = 0
last = len(alist)-1
found = False
while first<=last and not found:
midpoint = (first + last)//2
if alist[midpoint] == item:
found = True
else:
if item < alist[midpoint]:
last = midpoint-1
else:
first = midpoint+1
return found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment