Binary Search Iterative
Binary Search Iterative
Write binary_search(values: list[int], target: int) -> int, the iterative version: the list is already sorted, so keep low and high indexes for the part that may still hold the target, and while low is at most high compute mid as (low + high) // 2; return mid when values[mid] equals the target, move low up past mid when the middle value is too small, otherwise move high down below mid. Return -1 when the range empties. Each step halves the range, so this is O(log n). Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, a space-separated sorted list of integers (possibly empty) and then the target; the tests print the index your function returns.
Expected Output:
3= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...