Complete the code to find the middle index in binary search.
mid = (low + [1]) // 2
The middle index is found by adding low and high, then dividing by 2.
Complete the code to check if the middle element is the target.
if arr[mid] [1] target:
We check if the middle element equals the target to find it.
Fix the error in updating the low index when target is greater than middle element.
if arr[mid] < target: low = [1]
When target is greater, we move low to mid + 1 to search the right half.
Fill both blanks to update high index when target is less than middle element.
if arr[mid] > target: high = [1] - [2]
We set high to mid - 1 to search the left half excluding mid.
Fill all three blanks to complete the binary search function.
def binary_search(arr, target): low, high = 0, len(arr) - 1 while low <= high: mid = (low + [1]) // 2 if arr[mid] == target: return [2] elif arr[mid] < target: low = mid + [3] else: high = mid - 1 return -1
The function finds the middle index, returns mid if found, and moves low or high accordingly.
