ProgrammingHard

A binary search over n = 10^6 sorted records, in the worst case, takes how many loop iterations?

  1. A. 10
  2. B. 19
  3. C. 20
  4. D. 1000000

Correct answer: C. 20

The range halves each step, and 2^20 = 1048576 is the first power of two above 10^6, so 20 iterations are enough.

More C Programming questions

Exams that ask this topic