Data Structures & AlgorithmsModerate

Standard binary search (lo = 0, hi = n−1, mid = (lo+hi)//2) runs on 3 7 11 15 19 23 27 31 35 to look for the absent key 20. How many probes does it make before concluding the key is absent?

  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 9

Correct answer: B. 3

An unsuccessful search keeps halving until the live range is empty, so it still makes a number of probes about log₂ n. Counting the array length or stopping one probe early gives different values.

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

Exams that ask this topic