Skip to content

Instantly share code, notes, and snippets.

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