Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

A sorted array holds the 15 values 2, 5, 8, … (step 3). Binary search with mid = ⌊(lo+hi)/2⌋ and 0-based indices looks for 11. How many elements are compared with 11 until it is found?

  1. A. 2
  2. B. 5
  3. C. 0
  4. D. 3

Correct answer: A. 2

Simulate: lo=0, hi=14; each probe halves the range; 11 sits at index 3 and is found on probe 2.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic