GCSE · Computer Science · Edexcel · Spec 1CP2
Linear search
Nine cups, one hidden number, and you can only lift one cup at a time. Where do you start — and how many cups might you have to lift?
Open the cups
Find 126, one cup at a time
Nine cups sit in a row, in no particular order, and each one hides a number. Step through the search and watch which cups get opened — and which ones never do.
Before each click, ask yourself: is this the cup? And how many comparisons have we made so far?
1 search item = 1262 start at cup 13 compare the number in this cup with the search item4 if they are equal → stop: found it5 if not → move to the next cup, then back to line 36 if there are no cups left → stop: it is not in the list
Variables
Output
Step 1: Nine closed cups in a random order. We're hunting for 126, and we can't see inside a cup until we open it.
Press Next to open the next cup. ▢ is a cup nobody has opened yet.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Check every item, one after another, until you find what you're looking for — or run out of list.
What you need to know
- Describe what a linear search does, step by step, and when it stops.
- Carry out a linear search on a list of numbers or strings, counting the comparisons.
- Explain why a linear search works on a list in any order, and why it suits unordered lists.
- Identify the best case and the worst case, and how many comparisons each one needs.
The big picture
A linear search checks a list one item at a time, starting from the first, comparing each item with the search item. It stops the moment they're equal, and it can only say 'not in the list' once every item has been checked. It works on any order and any type of data, so for an unordered list it's the only reasonable choice. Best case: the first item, 1 comparison. Worst case: the last item or a missing one, every item compared.
Key points
Worked example
Problem
A list holds eight playing cards in this order: four, ten, five, two, eight, seven, nine and three of spades. Use a linear search to look for the six of spades. How many comparisons are made, and what is the result?
⚠ Watch out
Giving up early. If the item hasn't turned up yet, it's tempting to say it isn't there — but the list can be in any order, so it could be the very last one. 'Not in the list' is only true once every item has been compared.
Memory hook
Lift, look, move on. Stop the moment you find it — but you can't say 'it's not here' until you've lifted the very last cup.
Check yourself
List: 15, 8, 42, 3, 27. How many comparisons to find 3? And to search for 50? (4 — 3 is the 4th item. 5 — 50 isn't there, so every item is checked.)
Flashcards
(14)What is a linear search?
What is the 'search item'?
Where does a linear search start?
What happens at each position in a linear search?
When does a linear search stop if the item is in the list?
A search item is missing from the list. How does the search find that out?
Does a linear search need a sorted list?
Why is linear search used on an unordered list?
Can a linear search look for words (strings)?
What does the performance of an algorithm relate to?
Linear search: best case?
Linear search: worst case?
Worst case for a list of 50 items: how many comparisons?
Give two everyday jobs where a computer searches data.
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 Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 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.