ProgrammingHard

Binary search with lo = 0, hi = n - 1 on n = 1000 sorted records, looking for a key not in the array, performs how many probes at most?

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

Correct answer: B. 10

Each probe halves the range, and 2^10 = 1024 >= 1000, so at most 10 probes are needed. Nine probes cover only 512 positions.

More C Programming questions

Exams that ask this topic