Complete the code to find the middle index in binary search.
int mid = low + ([1] - low) / 2;
The middle index is calculated using the high and low indices to avoid overflow.
Complete the condition to check if the target is found.
if (arr[mid] [1] target) return mid;
We return the index if the middle element equals the target.
Fix the error in updating the low index when target is greater than mid 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 mid element.
if (arr[mid] > target) [1] = mid - 1; else [2] = mid - 1;
We update the high index to mid - 1 to search the left half.
Fill all three blanks to complete the binary search loop condition and return statement.
while (low [1] high) { int mid = low + (high - low) / 2; if (arr[mid] == target) return [2]; else if (arr[mid] < target) low = mid + 1; else high = mid - 1; } return [3];
The loop runs while low is less than or equal to high. Return mid if found, else -1 if not found.
