GATE Computer ScienceHardGATE CSE · NIELIT

A binary search (loop while low ≤ high, mid = ⌊(low+high)/2⌋) runs on a sorted array of 1000 elements. The maximum number of loop iterations over all searches, successful or not, is

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

Correct answer: C. 10

The range roughly halves each time until empty: ⌊log2 1000⌋ + 1 = 10.

More Algorithms questions

Exams that ask this topic