Data Structures & AlgorithmsHardGATE CS · Product placement

A sorted array was rotated to give [58, 67, 70, 71, 77, 3, 12, 14, 55]. 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 5, 3 iterations
  2. B. index 4, 3 iterations
  3. C. index 6, 3 iterations
  4. D. index 5, 4 iterations

Correct answer: A. index 5, 3 iterations

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

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

Exams that ask this topic