# 153. Find Minimum in Rotated Sorted Array

Reference: LeetCode
Difficulty: Medium

## Problem

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

Find the minimum element.

You may assume no duplicate exists in the array.

Example:

## Analysis

### Sorting

Time: $O(N\log{N})$
Space: $O(1)$

### Brute-Force

Time: $O(N)$
Space: $O(1)$

### Divide & Conquer

Reference: Huahua

In the mid3 case, the result could be calculated in $O(1)$.

Time: $O(\log{N})$

• False: $T(N) = 2T(N/2) = O(N)$ ❌
• At each level, at least one side could be done in $O(1)$.
• True: $T(N) = O(1) + T(N/2) = O(\log{N})$

Space: $O(\log{N})$

The basic idea is that if nums[mid] >= nums[lo] we assure that the inflection point is on the right part.

Recursion:

Iteration:

Time: $O(\log{N})$
Space: $O(\log{N})$ or $O(1)$

Comment
Junhao Wang
a software engineering cat