Data Structures & AlgorithmsHardTCS Digital · Infosys SP

A sorted array was rotated to give [29, 47, 50, 57, 60, 61, 75, 4, 5, 8, 13]. Binary search finds the index of the minimum: while lo < hi, mid = (lo + hi) // 2; if a[mid] > a[hi] then lo = mid + 1 else hi = mid. What index is returned and how many iterations run?

  1. A. index 7, 4 iterations
  2. B. index 6, 4 iterations
  3. C. index 7, 5 iterations
  4. D. index 8, 4 iterations

Correct answer: A. index 7, 4 iterations

Comparing with a[hi] tells which half is sorted; the minimum 4 is at index 7 (the rotation point), reached after 4 iterations.

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

Exams that ask this topic