import numpy as np
def binary_search(sequence, item_to_search):
The code for binary search has been provided. Please modify the code so that
it will return the number of steps it took to find the minimum index of the
number using binary search, given that the number is in the sequence.
In other words, the program should not stop the first time it finds the
number in the sequence, but continue binary search until it finds the minimum
index the number appears at.
>>>print(binary_search([1,1,1,2,3,4], 1))
2
>>>print(binary_search([1,1,1,2,2,2,3,3,4], 3))
2
low = 0
high = len(sequence) - 1
while low <= high:
middle = (low + high) // 2
if sequence[middle] < item_to_search:
low = middle + 1
elif sequence[middle] > item_to_search:
high = middle - 1
else:
return middle
return None