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 = 126
2 start at cup 1
3 compare the number in this cup with the search item
4 if they are equal → stop: found it
5 if not → move to the next cup, then back to line 3
6 if there are no cups left → stop: it is not in the list

Variables

cups=▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢comparisons=0search item=126

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.

1 / 9

Press Next to open the next cup. ▢ is a cup nobody has opened yet.

Step 1 of 9: Nine closed cups in a random order. We're hunting for 126, and we can't see inside a cup until we open it..

Watch out: The search never peeks ahead. It only ever knows what's in the cups it has already opened.

Your turn

Now search a list of words

The list is Moscow, Sydney, Beijing, Athens, Mumbai, Tokyo, Prague, and the search item is Mumbai. The search has started. You choose each missing step.

  1. The search item is Mumbai. Start at the first item in the list, Moscow.
  2. Compare Moscow with Mumbai. They're not equal, so move to the next item, Sydney. (1 comparison)
  3. missing step
Which line is step 3?

Exam line: Count every comparison, including the one that finds the match.

What do you think?

Will a linear search work here?

Sam's music app keeps 200 song titles in the order they were added, not in alphabetical order. Sam wants to use a linear search to find a song called 'Neon Rain'.

Which is closest to what you think right now?
How sure are you?

How long does it take?

Best case and worst case

The list is Dublin, Cairo, La Paz, Seoul, New York, London, Paris. Drag each search item to the number of comparisons a linear search makes before it stops. (Berlin isn't in the list.)

Put it in writing

Explain it like an expert

A club stores the names of its 30 members in a list, in the order they joined — not in alphabetical order. (a) Describe how a linear search would find one member's name in this list. (b) Explain why a linear search is a suitable choice for this list. (c) State the best case and the worst case for this search. [5 marks]

0 words · your answer stays on this page and is not sent anywhere.

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

1A linear search looks for a search item by examining each item in a list, one after another, starting from the first.
2At each position, compare the current item with the search item: if they're equal, stop; if not, move to the next item.
3The search can only report that the item is not in the list after every item has been checked.
4It works on lists in any order, sorted or unsorted, and on any type of data, including strings. For an unordered list, it's the only reasonable way to search.
5The performance of an algorithm relates to the number of steps it takes to complete. For a linear search, count the comparisons.
6Best case: the search item is the first item, so 1 comparison. Worst case: it's the last item or isn't in the list, so every item is compared.

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?
An algorithm that searches for an item in a list by examining each item, one after another, to see if it's the item being searched for.
What is the 'search item'?
The item the search is looking for — each item in the list is compared with it.
Where does a linear search start?
At the first item in the list.
What happens at each position in a linear search?
The item at the current position is compared with the search item. If they're not equal, the search moves to the next item.
When does a linear search stop if the item is in the list?
As soon as the item at the current position is equal to the search item. Nothing after it is checked.
A search item is missing from the list. How does the search find that out?
It compares every item right to the end. Only when none of them matched can it report 'not in the list'.
Does a linear search need a sorted list?
No. It works on a list in any order, sorted or unsorted.
Why is linear search used on an unordered list?
If a list isn't in order, a linear search is the only reasonable way to search through it.
Can a linear search look for words (strings)?
Yes. It works on lists containing any type of data, not just numbers.
What does the performance of an algorithm relate to?
The number of steps it takes to complete. For a linear search, count the comparisons.
Linear search: best case?
The search item is the very first item in the list, so only 1 comparison is needed.
Linear search: worst case?
The search item is the last item, or isn't in the list at all, so the whole list is checked.
Worst case for a list of 50 items: how many comparisons?
50 — every item is compared.
Give two everyday jobs where a computer searches data.
Finding a file with a particular name, and finding websites that match some keywords.

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 posted

More Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.