Rotated & Mountain
The array is sorted in pieces: two ascending runs, or up then down. Comparing mid with the target tells you nothing, so compare it with a reference point, find the break, then search a sorted piece.
Sorted in pieces
A rotated array is two ascending runs; the minimum (the pivot) starts the second. A mountain rises to a peak and falls. In both, one comparison per probe says which side of the break mid is on.
Compare with a[hi]
a[mid] > a[hi] means mid is still in the first run, so the pivot is to the right: lo = mid + 1. Otherwise hi = mid.
Compare with a[mid + 1]
a[mid] < a[mid + 1] means mid is on the way up, so the peak is to the right: lo = mid + 1. Otherwise hi = mid.
Duplicates break the test
When a[mid] == a[hi] the side is unknown. Drop one copy with hi -= 1; the worst case becomes O(n) (154, 81).
Find the pivot
Find the Pivot (Minimum)
Find the Pivot (Minimum)
153. Find Minimum in Rotated Sorted Array
153. Find Minimum in Rotated Sorted Array
Find the Pivot, then Read It
154. Find Minimum in Rotated Sorted Array II
154. Find Minimum in Rotated Sorted Array II
Find the Pivot, then Read It
Pivot, then search
Find the pivot, then bisect whichever sorted run can hold the target.
33. Search in Rotated Sorted Array
33. Search in Rotated Sorted Array
Find the Pivot, then Split
Climb to the peak
162. Find Peak Element
162. Find Peak Element
Climb Toward the Slope
852. Peak Index in a Mountain Array
852. Peak Index in a Mountain Array
Climb Toward the Slope
Peak, then search both slopes
Find the peak, bisect the rising slope, then the falling slope with the comparison flipped.