Data Structures & AlgorithmsModerateGATE CS · DSA

Binary search with mid = (lo + hi) // 2 (lo = 0, hi = n − 1, loop while lo ≤ hi) looks for 81 in [22, 26, 29, 31, 36, 38, 46, 51, 70, 81, 93, 94, 99]. Which elements are compared with the key, in order?

  1. A. 46
  2. B. 46, 81, 93
  3. C. 46, 81
  4. D. 46, 93, 70, 81

Correct answer: C. 46, 81

Each probe halves the range: 46 → 81. The key is found at index 9.

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

Exams that ask this topic