Data Structures & AlgorithmsModerateGATE CS · TCS NQT

A sorted array of distinct values was rotated some number of times. Which technique finds the minimum element in O(log n) time, and why does it work?

  1. A. Linear scan with two pointers, since the sorted order allows skipping half the array each time
  2. B. Hashing every value, since a hash table gives the minimum in constant time
  3. C. Binary search: compare the middle element with the last element to decide which half contains the rotation point
  4. D. Sorting the array again, since sorting is cheaper after a rotation

Correct answer: C. Binary search: compare the middle element with the last element to decide which half contains the rotation point

If a[mid] > a[hi], the rotation point (the minimum) lies right of mid; otherwise it lies at or left of mid. Each comparison discards half the range, so the search is O(log n).

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

Exams that ask this topic