Step through linear, binary, jump and interpolation search, including what happens when the array is not sorted the way they assume.
Found at index 5
3 comparisons over 10 values.
Binary search halves or skips the range, so it only works on sorted input.
16 is below 23; discard the left half.
Halves the range each step. Famously easy to write wrongly: a midpoint written `(low + high) / 2` overflows on large indices in fixed-width integer languages, a bug that sat in Java's library for nine years.
The bound is theoretical and describes how work grows with the array size. The comparison count above is what happened to this input, not a benchmark.
Searching Algorithm Visualizer runs entirely on your device — the search happens in the page and nothing is uploaded.
You’re on the Free plan. Compare plans
Four algorithms, and the interesting case is deliberately not hidden: three of them assume the array is sorted, and given unsorted input they do not fail — they return a wrong answer, quietly. So unsorted input is accepted, the trace shows what really happens, and the warning says that the silent wrong answer is the lesson. Refusing the input would remove the one thing most worth demonstrating.
Binary search is written the overflow-free way, with the midpoint as `low + (high - low) / 2` rather than `(low + high) / 2`. JavaScript numbers do not overflow, so this costs nothing here — but the naive form overflows on large indices in fixed-width integer languages, and that bug sat in Java's own library for nine years.
Interpolation search is included because it is the one that shows the trade clearly. It guesses where the target should be assuming values are spread evenly, which beats binary search on uniform data and degrades to linear on clustered data. The guard against an all-equal window is also there, because that window has a span of zero and an unguarded division by it never terminates.
Jump search is the one that looks worse and sometimes is not: more comparisons than binary search, but it only ever moves forward in large strides, which suits storage where seeking backward is expensive.
The algorithms run in a pure engine and are checked against the array independently of this page — every value found at the right index, every miss reported as a miss, over hundreds of generated arrays.
Because the array is not sorted. Binary search discards half the range at each step based on one comparison, and if the order is not what it assumes, the half it throws away can contain your value. It returns not-found rather than erroring, which is exactly why unsorted input is worth seeing here.
`low + (high - low) / 2` cannot overflow; `(low + high) / 2` can, in any language with fixed-width integers. That bug was in Java's binary search for nine years, and writing the safe form is worth the habit even where it costs nothing.
For a short array, linear — there is no sorting to pay for and no branching to mispredict. For a long sorted one, binary. Interpolation beats binary on evenly-spread data and degrades to linear on clustered data, so it is a bet on your distribution.
Every probe is listed as text below, and clicking a line jumps to that step. If your system asks for reduced motion, playback does not start on its own and the colour transitions are switched off.