Skip to main contentSkip to solution

Given the following list of elements:

2357101112

Item to be searched = 2

Which of the following can be the middle of elements calculated by the binary search algorithm?

(A) 7

(B) 3

(C) 2

(D) 5

Solution

✅ Correct Option: 2

Binary search takes mid=⌊(low+high)/2⌋mid = \lfloor (low + high)/2 \rfloor (indices start at 0) and discards the half that cannot contain 2.

PasslowhighmidElement at midDecision
106372<72 < 7, so high becomes 2
202132<32 < 3, so high becomes 0
30002found

The middle elements calculated are 7, 3 and 2, which are (A), (B) and (C).


(D) 5: it is at index 2, which is never the middle of any range used. The search moves left of index 3 and then left of index 1, so 5 is skipped.

Keyboard Shortcuts

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