1 · Learn and predict
Read this worked example. Predict its output, run it in Python 3, and explain how variables change.
def binary_search(values, target):
low, high = 0, len(values)-1
while low <= high:
mid = (low + high) // 2
if values[mid] == target:
return mid
if values[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
print(binary_search([2, 4, 6, 8, 10], 8))