Skip to content

Instantly share code, notes, and snippets.

@Javex
Created May 7, 2014 17:21
Show Gist options
  • Save Javex/66fc60d0a84d016e3b2c to your computer and use it in GitHub Desktop.
Save Javex/66fc60d0a84d016e3b2c to your computer and use it in GitHub Desktop.
def bsearch(items, x, L=None, R=None):
if L is None:
L = 1
if R is None:
R = len(items)
if L > R:
return None
mitte = (L + R) // 2
assert mitte == int(mitte)
if x < items[mitte-1][1]:
return bsearch(items, x, L, mitte-1)
elif x > items[mitte-1][1]:
return bsearch(items, x, mitte+1, R)
else:
return mitte - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment