Question.1
A developer searches for value 8 in a sensor lookup table using binary search:
8
int arr[] = {20, 5, 15, 8, 30}; int idx = binary_search(arr, 5, 15);
The function returns -1 (not found), even though 8 is at index 3. What went wrong?
-1
Select Answer
Binary search has a bug — it should always find existing elements
The array is not sorted — binary search requires a sorted array to work correctly
The key 15 is at an odd index, which binary search skips
Binary search only works for arrays with power-of-two sizes