Linear Search
Check each item in turn until you find the target.
About this topic
Linear search, also called sequential search, finds a target value in a list by checking each item one at a time from the start until the target is found or the list ends. It is simple and works on any list, sorted or not.
For example, to find 42 in [7, 15, 42, 8], the algorithm checks 7, then 15, then 42 and stops at index 2. If the value is absent, every item is checked and the search reports not found. In the best case the target is first, taking one comparison. In the worst case it is last or missing, taking n comparisons for n items, so it has O(n) time, meaning the work grows in direct proportion to the list size.
Linear search is fine for short lists or data that is unsorted, such as looking for a name in a small class register. For very large sorted lists, binary search is much faster. A common mistake is returning not found too early, before the whole list has been checked, or forgetting to stop once the target is found. Always handle the case where the value does not exist.
Key ideas
- Works on any list
- Slow for large lists
- O(n)
Quick check
Use cases: where Linear Search helps
- Homework: review the key idea behind Linear Search before you start a problem set.
- Exam revision: use the quick check to test whether you can recall Linear Search without notes.
- Visual learning: play with the interactive lab to see how Linear Search changes when you adjust its inputs.
- Teaching a friend: explain Linear Search in your own words, then compare your version with the key ideas.
Computing ideas run phones, search engines, games and the wider internet.
Frequently asked questions
What is Linear Search?
Check each item in turn until you find the target.
What will I learn in Linear Search?
Works on any list. Slow for large lists. O(n).
Is Linear Search part of Computer Science?
Yes. It is one of 80 Computer Science topics on LearnViz HighSchoolEdu, with 3 key ideas, a live animation and a quick check.
Does the Linear Search lab work on a phone or tablet?
Yes. The animation resizes to fit your screen and supports touch, so you can drag, tap and slide with your finger.
How should I study Linear Search?
Read the summary and key ideas first, play with the interactive lab to see the idea in motion, then answer the quick check. If you get a question wrong, go back to the key idea it tests.
Do I need an account, and is my progress saved?
No account is needed. Marking a topic as learned is saved in your own browser, so it stays on that device and is not sent to a server.