KS3 · Computer Science
Linear search
Looking for your mate in a jumbled queue? Start at the front, check each face, stop when you spot them. Only at the back can you say they're not there.
Computer Science · Algorithms
Trace table — dry run the code
One list, two searches. First we look for Mo, then for Sam. Step through one comparison at a time and watch how differently the two searches end.
Ready when you are — step through one line at a time.
Predict, then check
Think about the exact moment the search stops.
A linear search looks for 5 in the list 8, 5, 12, 5, 3. There are two 5s in it. Which position does the search report?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Check one item at a time until you find it, or run out of list.
What you need to know
- A searching algorithm finds out whether a target item is in a list and, if it is, where it is (its position). In this lesson we count positions from 1.
- Linear search starts at the first item and compares each item with the target, one at a time.
- If the item matches, the search stops and reports the position. If not, it moves on to the next item.
- Only when the end of the list is reached with no match does it report that the target is not in the list.
- Linear search works on any list, sorted or not, because it never relies on the order of the items.
- It is simple but can be slow on long lists: in the worst case (the target is last or missing) every item is checked. On a sorted list, binary search is usually much faster.
The big picture
Linear search looks for a target in a list by checking each item in turn, starting from the first. If an item matches, it stops and reports that position. If it reaches the end with no match, it reports that the target is not in the list. It works on any list, sorted or not, but in the worst case it needs a comparison for every item, so on a long sorted list binary search is usually much faster.
Key points
Worked example
Problem
A shop's stock list holds the codes 42, 17, 88, 5, 63, in no particular order. Use a linear search to look for 5. Record each comparison and say what the search reports.
⚠ Watch out
Saying 'not in the list' too early. A linear search can only decide the target is missing after it has checked the very last item. A bigger item, a long run of misses or reaching the middle proves nothing, because the list may not be in any order.
Memory hook
Look, compare, move on. Stop the moment you find it, and never say 'not here' until you've checked the last one.
Check yourself
Trace a linear search for 30 in 10, 40, 20, 50. How many comparisons does it make, and what does it report? (4 comparisons, none match, so: 'not in the list'.)
Flashcards
(12)What does a searching algorithm find out?
Where does a linear search start?
In linear search, what happens at each step?
When can a linear search report 'not in the list'?
The target appears twice in a list. Which position does linear search report?
Does a list have to be sorted before a linear search?
What is the worst case for linear search?
A target is missing from a list of 200 items. How many comparisons does linear search make?
Why can linear search be slow on a long list?
What does binary search need that linear search doesn't?
Long sorted list: which search is usually much faster?
What does each row of a linear search trace record?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore KS3 Computer Science topics
- Abstraction in computational thinking
- Adding binary numbers
- Binary to denary conversion
- Boolean logic: AND, OR, NOT
- Bubble sort
- Building truth tables
- Client-server vs peer-to-peer
- Collecting and recording data
- Comparing sorting algorithms
- Compressing data
- Creating a 3D animation
- Decomposition: splitting problems up
How this lesson was checked. This KS3 Computer Sciencelesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.