Skip to content

Instantly share code, notes, and snippets.

@joshourisman
Created April 19, 2010 20:38
Show Gist options
  • Save joshourisman/371562 to your computer and use it in GitHub Desktop.
Save joshourisman/371562 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def search(array, term):
print "searching for %d in %s" % (term, array)
length = len(array)
if length == 1:
if array[0] == term:
print "Found %s in %s." % (term, array)
return True
else:
print "Did not find %s in %s." % (term, array)
return False
else:
mid = length/2
if array[mid] <= term:
return search(array[mid:], term)
else:
return search(array[:mid], term)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment