Created
April 19, 2010 20:38
-
-
Save joshourisman/371562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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