StringMash.com

Linear search visualizer

Watch it check each item in turn until it finds the one you want.

20 characters
Updates as you type
The animation is below

Show the steps
  1. Position 1: 4. Not 23, so move on.
  2. Position 2: 8. Not 23, so move on.
  3. Position 3: 15. Not 23, so move on.
  4. Position 4: 16. Not 23, so move on.
  5. Position 5: 23. That's 23. Found.
  6. Found 23 at position 5, after 5 checks.

Watch it sort

  • Being compared
  • Just moved
  • In its final place
  • Not being worked on

Type a list above to see it sorted step by step.

Using the visualizer

Type a list in the box and what to look for in Look for. The result says where it was found, or that it isn't there, and the animation below checks the list one item at a time. Show the steps lists every check.

How linear search works

Start at the first item. If it's the one you want, stop. If not, move to the next, and keep going until you find it or run out of list. That's all there is to it.

It works on any list, in any order. The cost is time: on a list of n items it can take n checks, and on average about half that when the item is there. Binary search is far faster, but only on a list that's sorted.

Questions

When is linear search the right choice?

When the list is short, unsorted, or searched only once. Sorting it first just to use binary search costs more than one straight look through.

Is it the same as sequential search?

Yes, they're two names for the same thing.

Why does the animation only go up to 3 steps a second?

Each step recolours a bar or two, and three changes a second is the limit the web's accessibility guidelines set for anything that flashes. Step forward goes as fast as you can click.