Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def bsearch(arr,key,start=0,end=None):
if end == None: end = len(arr) - 1
if start > end: return None
if start == end and arr[start] != key: return None
mid = (start+end)/2
if arr[mid] == key:
return mid
if arr[mid] > key:
return bsearch(arr,key,start,mid-1)
if arr[mid] < key:
return bsearch(arr,key,mid+1,end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment