Linear search is one of the easiest search algorithms to understand. It does exactly what the name suggests: it looks at items one by one until it finds what it’s looking for or reaches the end of the list.
There’s no trick to it. If you have an array, linear search starts at the first element, compares it with the value you want, and keeps going until it either finds a match or runs out of elements.
How it works:
1. Start from the first item in the array
2. Compare it with the target value
3. If it matches, stop
4. If not, move to the next item
5. Repeat until the array ends
When should you use it?
Linear search is fine when:
The array is small
The data is not sorted
You want something quick and easy to write
It’s not the fastest option for large datasets, since it may have to check every item. But for simple tasks, it gets the job done without extra complexity.
A bit of history
Linear search is basically as old as computing itself. Early computers didn’t have fancy data structures or fast memory access, so checking data one piece at a time was the normal approach. Even before computers, people used the same idea—think of flipping through a phone book page by page or checking names on a handwritten list.
Because of that, linear search is often the first algorithm taught in computer science. It’s not impressive or clever, but it mirrors how humans naturally search, which is why it has stuck around for so long.
Simple, clear, and still useful today.