Complete the code to find the middle index in binary search.
int mid = low + (high - low) / [1];In binary search, we find the middle by dividing the range by 2.
Complete the code to check if the middle element is the target.
if (arr[mid] == [1]) { return mid; }
We compare the middle element with the target value we want to find.
Fix the error in updating the search range when target is less than middle element.
if (target < arr[mid]) { high = [1]; }
If the target is less than the middle element, we move the high pointer just before mid.
Fill both blanks to update the search range correctly when target is greater than middle element.
if (target > arr[mid]) { low = [1]; high = [2]; }
When target is greater, we move low just after mid and keep high unchanged.
Fill all three blanks to complete the binary search method.
public int BinarySearch(int[] arr, int target) {
int low = 0, high = arr.Length - 1;
while (low <= high) {
int mid = low + (high - low) / [1];
if (arr[mid] == [2]) return mid;
else if (target < arr[mid]) high = mid [3] 1;
else low = mid + 1;
}
return -1;
}This completes the binary search: middle index calculation, comparison with target, and updating high pointer.
