What condition must be true for recursive binary search to work correctly?
Explanation
Each step compares the target with the middle value and then keeps only the half that can still contain the target. That decision is only trustworthy when the values are in sorted order; without it the method can return an incorrect result.
- A is not correct: The return type is not what makes the search work; the traced method returns an
int, either the found indexmidor-1. - C is not correct: A single value is not a requirement at all; the traced array
{2, 5, 8, 10, 11, 15, 17, 20, 22}holds nine values and the halving still works. - D is not correct: Unsorted data is the case the method cannot handle, since the choice between the left half and the right half would no longer eliminate the values it assumes it eliminates.