GCSE · Computer Science · Eduqas · Spec C500QS
Linear search
You're the computer. You can look at one item at a time. So when are you allowed to say the target isn't there?
Computer Science · Searching
Be the computer: run the search
The list is 14, 3, 27, 9, 21. Pick a search, then call each step before the table shows it.
The list is 14, 3, 27, 9, 21, and position 1 is the first item. comparisons is a tally of how many items have been compared with the search item. Nothing is run: every value is set out for you.
comparisons = 0for position = 1 to length(list)comparisons = comparisons + 1if list[position] == target thenprint("Found at position " + position)stopendifnext positionprint("Not found")
Variables
Step 1. The search item is 27. Nothing has been compared yet, so the tally starts at 0. This first step is worked for you.
Try all four searches. Watch how the tally ends up for each one.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Check the list one item at a time, and learn why "not there" costs the most.
What you need to know
- Computers can quickly search through large amounts of data to find what is needed.
- Linear search is one way to do it: check each item in a list, one at a time.
- It takes two things in: the list, and the search item you are looking for.
- It starts at the first item and compares the item at the current position with the search item.
- Not equal? Move to the next item. Equal? Stop: you have found it.
Have a goSam says: "I checked the first item, it wasn't a match, so the item isn't in the list." Is Sam right?
No. Not equal means move on to the next item.
A mismatch only rules out that one item. The search carries on to the next item rather than giving up.
- If the whole list is checked and nothing matched, the item is not in the list.
- It works on lists in any order, sorted or not, and on strings as well as numbers.
Have a goMia's list of seven names is in a total jumble. "Better sort it first," she says. Does a linear search need that?
No. It works on a list in any order.
A linear search checks each item in turn, so sorted or unsorted makes no difference and Mia can start straight away.
- An algorithm's performance relates to how many steps it takes, so we count comparisons.
- Best case: the item is the very first one, so it takes one comparison.
- Worst case: the item is last or not in the list, so as many comparisons as there are items.
Have a goA list has 12 items and the search item turns out to be the 12th. How many comparisons does the search make?
12
Each of the first 11 items fails the comparison, then the 12th matches. The last item costs one comparison per item.
The big picture
A linear search checks each item in a list, one at a time, comparing it with the search item. It stops the moment an item matches, and it can only say the item is not in the list after checking every item. It works on any list, in any order, so the best case is one comparison and the worst case is as many comparisons as there are items.
Key points
Worked example
Problem
A list holds four fruit names in this order: pear, plum, fig, kiwi. Use a linear search to look for "fig", and then look for "grape". How many comparisons does each search make, and what does each one report?
⚠ Watch out
Reporting "not found" as soon as one comparison fails. A mismatch only means "try the next item". "Not found" can only be reported once the last item has been compared.
Memory hook
Found: the moment you meet it. Not found: only after you've met everything.
Check yourself
A linear search looks for 40 in 8 unsorted numbers, and 40 is not there. How many comparisons before it can say so, and why not sooner?
Flashcards
(11)What does a linear search do?
What two things does a linear search start with?
At each position, what gets compared with the search item?
The item at the current position is not equal to the search item. What happens?
How does a linear search know it has found the item?
A linear search has just compared the final item and found no match. What can it conclude?
Does a list have to be sorted before a linear search can be used?
What types of data can a linear search be used on?
What does the performance of an algorithm relate to?
What is the best case for a linear search?
What is the worst case for a linear search?
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 Eduqas GCSE Computer Science topics
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)lesson 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 23 November 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.