Merge pull request #159 from shutstart/master

binary search in python
This commit is contained in:
Luke Oliff 2018-10-06 09:31:11 -07:00 committed by GitHub
commit a4d8e59bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

19
code/shutstart.py Normal file
View File

@ -0,0 +1,19 @@
def binary(a, tv):
minimum = 0
maximum = len(a) - 1
while minimum < maximum:
guess = round((minimum + maximum)/2)
if a[guess] == tv:
return guess
elif a[guess] < tv:
minimum = guess + 1
else:
maximum = guess - 1
return -1
arr = []
ind = binary(arr, 4)
print("index:")
print(ind)