Created
March 9, 2017 22:26
-
-
Save SeanPlusPlus/40cdfacf794d34b0270995ac1891b15c to your computer and use it in GitHub Desktop.
binary search in python
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 | |
import time | |
from bisect import bisect_left | |
def binary_search(a, x): | |
# implement binary_search | |
return | |
def main(): | |
a1 = [12, 16, 24, 37, 102, 109] | |
a2 = [1, 4, 7, 8, 9, 16] | |
a3 = [400, 401, 402, 403, 404, 405] | |
x = 16 | |
print binary_search(a1, x) | |
print binary_search(a2, x) | |
print binary_search(a3, x) | |
if __name__ == '__main__': | |
start_time = time.time() | |
main() | |
print('--- %s seconds ---' % '%.2f' % (time.time() - start_time) ) | |
# takes about 13 seconds to run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment