Complete the code to calculate the middle index in binary search.
let mid = (low + [1]) / 2;
The middle index is calculated by adding low and high, then dividing by 2.
Complete the code to check if the middle element is equal to the target.
if arr[mid] == [1] {
We compare the middle element with the target value we are searching for.
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 the 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 signature and return statement.
fn [1](arr: &[i32], target: i32) -> [2] { let mut low = 0; let mut high = arr.len() as i32 - 1; while low <= high { let mid = (low + high) / 2; if arr[mid as usize] == target { return [3]; } // rest of code omitted } -1 }
The function is named binary_search, returns i32 index, and returns mid as i32 when found.
