Search in a Rotated Sorted Array
intermediateSearches a rotated sorted array in O(log n) by determining which half is still sorted at each step.
PhaseInit
Mid—
Result—
K =3
lo
mid
hi
↻
5
[0]6
[1]7
[2]8
[3]9
[4]10
[5]1
[6]2
[7]3
[8]Current mid being tested
Found (K)
Active search space
Outside search space / eliminated
Search for K=3 in rotated array [5, 6, 7, 8, 9, 10, 1, 2, 3]. Rotation at index 6. lo=0, hi=8.
1 / 10