Skip to main contentSkip to solution

Consider a list [-10, -4 ,3 ,5, 6, 8, 9]. How many comparisons will be required if binary search is applied to find the element '9'?

Solution

✅ Correct Option: 2

Binary search compares the target with the middle element and discards the half that cannot contain it. The list has 7 elements at positions 0 to 6.

ComparisonlowhighmidElement at midResult
106355<95 < 9, search right half
246588<98 < 9, search right half
36669found

Total comparisons =3= \boxed{3}


Option 3: 7 is the count for linear search, which checks 9 as the last element.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question