Skip to content

Instantly share code, notes, and snippets.

@johnsyweb
Created April 25, 2010 05:30
Show Gist options
  • Save johnsyweb/378185 to your computer and use it in GitHub Desktop.
Save johnsyweb/378185 to your computer and use it in GitHub Desktop.
def binary_search(elements, required):
if 1 == len(elements):
if required == elements[0]:
return required
else:
return None
else:
midpoint = int(len(elements) / 2)
if elements[midpoint] > required:
return binary_search(elements[:midpoint], required)
else:
return binary_search(elements[midpoint:], required)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment