Skip to content

Instantly share code, notes, and snippets.

@juanitobanca
Created March 2, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanitobanca/842d5b07821b6ebd789d7098df36b4e5 to your computer and use it in GitHub Desktop.
Save juanitobanca/842d5b07821b6ebd789d7098df36b4e5 to your computer and use it in GitHub Desktop.
def binarySearch( alist, anum ):
low = 0
high = len(alist)-1
while low <= high:
mid = (low + high)/2
if alist[mid] == anum:
return True
if alist[mid] < anum:
low = mid + 1
else:
high = mid -1
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment