Data Structures & AlgorithmsVery hardGATE CS · competitive programming

What is the worst-case time complexity of finding the minimum in a rotated sorted array that may contain duplicates, using a binary search that compares a[mid] with a[hi]?

  1. A. O(log n)
  2. B. O(n log n)
  3. C. O(1)
  4. D. O(n)

Correct answer: D. O(n)

When a[lo] = a[mid] = a[hi], the minimum could lie on either side, so the search can only shrink the range by one index. With all values equal this takes n steps.

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

Exams that ask this topic