Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft

Binary search with mid = (lo + hi) // 2 (lo = 0, hi = n − 1, loop while lo ≤ hi) looks for 16 in [18, 39, 40, 44, 45, 56, 60, 62, 70, 84, 97]. Which elements are compared with the key, in order?

  1. A. 56, 40
  2. B. 56, 40, 18
  3. C. 56, 40, 39, 18
  4. D. 56, 40, 18, 39

Correct answer: B. 56, 40, 18

Each probe halves the range: 56 → 40 → 18. The range becomes empty, so the search fails after 3 probes.

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

Exams that ask this topic