Complete the code to find the middle index in binary search.
int mid = low + (high [1] low) / 2;
The middle index is calculated by adding low to half the difference between high and low.
Complete the code to check if the middle element is the target.
if (arr[mid] [1] target) return mid;
We check if the middle element equals the target to return its index.
Fix the error in updating the low index when target is greater than middle element.
if (arr[mid] < target) low = [1];
If the target is greater than the middle element, 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]; else low = [2];
If target is less, high moves to mid - 1; else low moves to mid + 1.
Fill all three blanks to complete the binary search function.
int binarySearch(int arr[], int low, int high, int target) {
while (low <= high) {
int mid = low + (high [1] low) / 2;
if (arr[mid] == target) return [2];
else if (arr[mid] < target) low = mid [3] 1;
else high = mid - 1;
}
return -1;
}The middle index is calculated by adding low to half the difference (high - low). If the middle element matches target, return mid. If target is greater, move low to mid + 1.