Loading algorithms…
Loading visualizer…
Check every element until a match is found. Works on unsorted data; baseline for search algorithm comparisons.
Amber = current index · Emerald = found · dimmed = already checked
Begin linear scan for target = 56 in an array of 12 elements. Walk left-to-right; stop at the first match. Worst case: 12 comparisons.
Same values, same target — binary search first sorts the data, then eliminates half the remaining range per comparison.
Works on any array. Scans left-to-right and can stop early.
Requires sorted data. Halves the search range after every comparison.
Compare the first element with the target. If it matches, return immediately.
When the values differ, advance i by one and inspect the next element.
Return the first matching index, or −1 after every element has been checked.
Linear search needs no preprocessing and works on unsorted data. For repeated lookups, sorting once and using binary search can reduce each search from O(n) to O(log n).
Check every element until a match is found. Works on unsorted data; baseline for search algorithm comparisons.