Skip to content
DSA Visualizerpreview

Binary search

Halve the range still in play at every step until the target is found or ruled out.

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

Values2, 5, 8, 12, 16, 23, 38, 56, 72, 91target 23

Search 2, 5, 8, 12, 16, 23, 38, 56, 72, 91 for 23. lo starts at index 0 and hi at index 9.

Array of 10 values: 2, 5, 8, 12, 16, 23, 38, 56, 72, 91. Active index 0 (2) and index 9 (91). Pointers lo at index 0 and hi at index 9.
  • compare
  • swap or write
  • settled

1 / 7

Speed

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