Skip to content
DSA Visualizerpreview

Search a rotated sorted array

A sorted array, rotated: one half is always in order, so you can still halve the search.

O(log n) time · O(1) space

Values40, 52, 67, 81, 3, 9, 15, 22, 31target 15

40, 52, 67, 81, 3, 9, 15, 22, 31 is sorted, then rotated. Search it for 15.

Array of 9 values: 40, 52, 67, 81, 3, 9, 15, 22, 31. Active index 0 (40) and index 8 (31). Pointers lo at index 0 and hi at index 8.
  • compare
  • swap or write
  • settled

1 / 3

Speed

Space play · ← → step · Home End jump · drag the strip to scrub