Data Structures & AlgorithmsModerateCognizant · Capgemini pattern

Binary search (one three-way comparison per probe) is done on a sorted array of 1000 elements. What is the maximum number of probes needed?

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

Correct answer: C. 10

The worst case is ⌊log₂ n⌋ + 1 = ⌊9.97⌋ + 1 = 10 probes, because 2¹⁰ − 1 = 1023 ≥ 1000 while 2⁹ − 1 = 511 is too small. Taking ⌊log₂ 1000⌋ = 9 forgets the final probe.

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

Exams that ask this topic