Complete the code to start binary search with the correct initial left index.
int left = [1];The left index in binary search starts at 0, the first element's position in the array.
Complete the code to calculate the middle index correctly in binary search.
int mid = left + ([1] - left) / 2;
The middle index is calculated between left and right to avoid overflow.
Fix the error in the condition to move the left pointer when target is greater than mid value.
if (target > arr[[1]]) { left = mid + 1; }
We compare target with the middle element arr[mid] to decide which half to search next.
Fill both blanks to correctly update pointers when target is less or greater than mid value.
if (target < arr[[1]]) { [2] = mid - 1; }
If target is less than arr[mid], we move the right pointer to mid - 1 to search left half.
Fill all three blanks to complete the binary search loop condition and return statement.
while ([1] <= [2]) { int mid = [1] + ([2] - [1]) / 2; if (arr[mid] == target) { return mid; } // update pointers } return -1;
The loop runs while left is less or equal to right. Mid is calculated from left and right.
