Created
March 5, 2014 02:51
-
-
Save globby/9360259 to your computer and use it in GitHub Desktop.
An implementation of an iterative Binary Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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