Data Structures & AlgorithmsModerateTCS Digital · Infosys SP

What is the worst-case number of comparisons made by binary search (three-way comparison per probe) on a sorted array of 1,000 elements, for a key that may be absent?

  1. A. 10
  2. B. 9
  3. C. 11
  4. D. 500

Correct answer: A. 10

Each probe at least halves the remaining range; ⌊log₂ 1000⌋ + 1 = 10 probes suffice and are needed in the worst case.

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

Exams that ask this topic