Open In App

Minimum in a Sorted and Rotated Array

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
186 Likes
Like
Report

Given a sorted array of distinct elements arr[] of size n that is rotated at some unknown point, the task is to find the minimum element in it. 

Examples: 

Input: arr[] = [5, 6, 1, 2, 3, 4]
Output: 1
Explanation: 1 is the minimum element present in the array.

Input: arr[] = [3, 1, 2]
Output: 1
Explanation: 1 is the minimum element present in the array.

Input: arr[] = [4, 2, 3]
Output: 2
Explanation: 2 is the only minimum element in the array.

[Naive Approach] Linear Search - O(n) Time and O(1) Space

A simple solution is to use linear search to traverse the complete array and find a minimum

C++
C Java Python C# JavaScript

Output
1

[Expected Approach] Binary Search - O(log n) Time and O(1) Space

We can optimize the minimum element searching by using Binary Search where we find the mid element and then decide whether to stop or to go to left half or right half:

  • If arr[mid] > arr[high], it means arr[low ... mid] is sorted and we need to search in the right half. So we change low = mid + 1.
  • If arr[mid] <= arr[high], it means arr[mid ... high] is sorted and we need to search in the left half. So we change high = mid. (Note: Current mid might be the minimum element).

How do we terminate the search? One way could be to check if the mid is smaller than both of its adjacent, then we return mid. This would require a lot of condition checks like if adjacent indexes are valid or not and then comparing mid with both. We use an interesting fact here: If arr[low] < arr[high], then the current subarray is sorted, So we return arr[low].


C++
C Java Python C# JavaScript

Output
1



Minimum in a Sorted and Rotated Array
Visit Course explore course icon
Next Article

Similar Reads