Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 5, 2014 02:51
Show Gist options
  • Save globby/9360259 to your computer and use it in GitHub Desktop.
Save globby/9360259 to your computer and use it in GitHub Desktop.
An implementation of an iterative Binary Search
def BinarySearch(lst,key):
low, high = 0, len(lst)
while low <= high:
m = (low + high) / 2
if lst[m] > key:
high = m - 1
elif lst[m] < key:
low = m + 1
else:
return m
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment