What will you explore?

Back to Home

Search Algorithms

Follow a target through an ordered list. Linear Search checks each value; Binary Search repeatedly halves the remaining range.

1–80 ordered, distinct values.

1–100 steps per second.

Ready

Target value: 162

Elapsed visualization time: 0.00 s

This is playback time including the selected animation delay, not a CPU benchmark.

?: inspected value · M: Binary Search midpoint · Stripes: checked or eliminated · ✓: target found

Comparisons
0
Values inspected
0
Result
—
Target index
—
Current ordered values

10, 20, 32, 40, 52, 61, 74, 86, 94, 107, 118, 128, 131, 141, 158, 162, 176, 183, 197, 202, 214, 228, 233, 248, 253, 265, 277, 280, 296, 303

Linear Search

Check values from left to right until the target is found or the list ends. It also works on unsorted data, though it may inspect every value.

Time: O(n) · Space: O(1)

Works on unsorted data; time O(n), space O(1).

Algorithm tradeoffs
AlgorithmTimeSpaceRequirements
Linear SearchO(n)O(1)Works on unsorted data; time O(n), space O(1).
Binary SearchO(log n)O(1)Requires sorted data. The time and space shown describe the underlying search, excluding animation event generation.