Consider a list [-4, 0, 2, 7, 8, 17, 19].
Apply binary search to find element -4. Determine the number of key comparisons required.
Consider a list [-4, 0, 2, 7, 8, 17, 19].
Apply binary search to find element -4. Determine the number of key comparisons required.
Solution
✅ Correct Option: 3
Binary search compares the key with the middle element and discards half the list each time. Here the list has 7 elements at indices 0 to 6, and .
| Comparison | low | high | mid | Element at mid | Outcome |
|---|---|---|---|---|---|
| 1 | 0 | 6 | 3 | 7 | , search left half |
| 2 | 0 | 2 | 1 | 0 | , search left half |
| 3 | 0 | 0 | 0 | -4 | Found |
Key comparisons
Related questions:
2026: 26 May Shift 1
2026: 29 May Shift 1
2025: 22 May Shift 1