A binary search looks for 36 in the sorted array [4, 9, 13, 18, 22, 27, 31, 36, 40, 45, 51], indexed from 1 to 11. How many items are compared with 36?
- Low = 1, High = 11, Mid = 12 DIV 2 = 6. Item 6 is 27, too small, so Low = 7.
- Mid = (7 + 11) DIV 2 = 9. Item 9 is 40, too large, so High = 8.
- Mid = (7 + 8) DIV 2 = 7. Item 7 is 31, too small, so Low = 8.
- Mid = (8 + 8) DIV 2 = 8. Item 8 is 36: found.
Answer: 4 comparisons (items 27, 40, 31, 36). A linear search would need 8.