DevTools Hub

Search tools

Search for a developer tool

Algorithms

Search Algorithm Visualizer

Watch Linear Search and Binary Search run step by step, with real comparison counts.

Part of the Algorithms Toolkit
15 elements
6/10

Start scanning from index 0 for 1.

1
0
3
1
5
2
7
3
9
4
11
5
13
6
15
7
17
8
19
9
21
10
23
11
25
12
27
13
29
14
Unvisited Comparing Eliminated Found
Comparisons
0
Status
Searching…
Worst case
O(n)
Requires sorted
No

What this shows

Linear Search and Binary Search running step by step against the same sorted array, with real comparison counts and every intermediate pointer visible — not just the final answer. Pick a target that's in the array to see the best case play out, or one that isn't to watch each algorithm exhaust its search space and report "not found." Play through it, step manually, or drag the scrubber to any point.

Why Binary Search needs a sorted array and Linear Search doesn't

Linear Search just checks every element in order — it has no assumptions about the data, so it works on any array, sorted or not, and its comparison count is always exactly index of the target + 1 (or the full length, if the target is absent).

Binary Search only works because a sorted array lets it discard half the remaining search space with a single comparison: check the middle element, and everything on the wrong side of it can't possibly contain the target, so it's eliminated without ever being checked. That's the entire mechanism behind O(log n) — each comparison halves the problem, so an array of 1,000,000 elements takes at most 20 comparisons, not 1,000,000.

What the colors and markers mean

FAQ

Why does the array always look evenly spaced out?

It's generated as a random increasing sequence of unique values rather than sorting arbitrary random numbers — this keeps every value visually distinct and readable as a bar label at any array size this tool allows, without changing anything about how either algorithm behaves.

Does Binary Search always beat Linear Search?

Not for a target near the start of the array — Linear Search finds index 0 in a single comparison, while Binary Search still starts at the middle. Binary Search's advantage is in the worst case and, on average, across all possible targets — try a target near the end of the array, or one that's absent, to see the gap open up.

Where do these complexity classes come from?

See Algorithm Complexity Explained for the formal definitions, Big O Calculator for exact O(n) vs O(log n) operation counts at a given size, and Algorithm Runtime Estimator for what that gap looks like in actual wall-clock time.

Is anything I enter sent anywhere?

No — every search runs entirely in your browser. Nothing here is ever sent to a server.

Related tools