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

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

  1. A. 10
  2. B. 5
  3. C. 15
  4. D. 4

Correct answer: B. 5

Simulate: lo=0, hi=24; each probe halves the range; 35 sits at index 11 and is found on probe 5.

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

Exams that ask this topic