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 = 0
for position = 1 to length(list)
comparisons = comparisons + 1
if list[position] == target then
print("Found at position " + position)
stop
endif
next position
print("Not found")

Variables

target=27comparisons=0

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.

Step 1 of 5Called right: 0 of 3

Try all four searches. Watch how the tally ends up for each one.

Computer Science · Performance

How much work is "not there"?

A list holds 500 items, and the search item is not in it. How many comparisons does a linear search make before it can say "not found"?

Your estimate

500 comparisons

0 comparisons1000 comparisons

Exam line: To say an item is missing, a linear search has to compare every item. Missing costs as many comparisons as there are items.

Computer Science · Checking a trace

Where does this dry run go wrong?

A student dry-runs a linear search for 9 in the list 14, 3, 27, 9, 21. Their working has one wrong line. Which one?

A student's working — which line goes wrong?

Exam line: Found: the moment you meet the item. Not found: only after the last item.

Computer Science · What can it search?

What kind of list does it need?

Hari has a list of 100 names, typed in a random jumble. Hari needs to find out whether "Priya" is in it.

Which is closest to what you think Hari should do?
How sure are you?

Exam line: Linear search works on a list in any order, sorted or unsorted, and on strings as well as numbers.

Computer Science · Write it, then mark it

Write it, then mark it

Describe how a linear search looks for an item in a list. Then explain when the search has to do the most work. [6 marks]

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

Exam line: Steps first (first item, compare, move on, stop on a match), then the cost: the worst case checks every item.

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

1A linear search checks each item in a list one at a time, starting with the first.
2It compares the item at the current position with the search item. Equal means stop and report found.
3Not equal means go to the next item. A mismatch is never a reason to stop.
4Only after the whole list has been checked with no match can it say the item is not in the list.
5It works on any list: sorted or unsorted, numbers or strings.
6Best case: the item is first, 1 comparison. Worst case: the item is last or missing, as many comparisons as there are items.

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?
It checks each item in a list one at a time, until it finds the search item or runs out of items.
What two things does a linear search start with?
A list of data, and the search item it is looking for.
At each position, what gets compared with the search item?
Whichever item the search has reached in the list.
The item at the current position is not equal to the search item. What happens?
The search goes to the next item in the list and compares again.
How does a linear search know it has found the item?
The item at the current position is equal to the search item, so it stops searching.
A linear search has just compared the final item and found no match. What can it conclude?
The search item is not in the list.
Does a list have to be sorted before a linear search can be used?
No. It finds items in any order, sorted or unsorted. For a list that is not in order, it is the only reasonable way to search it.
What types of data can a linear search be used on?
Lots of different types, including strings.
What does the performance of an algorithm relate to?
The number of steps it takes to complete.
What is the best case for a linear search?
The very first item is the search item, so the search ends after one comparison.
What is the worst case for a linear search?
The item is last, or missing altogether. Every item gets compared, so the number of comparisons equals the number of items.

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 Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

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.