Search a list with linear search
Check items in order until a target is found or the list ends.
Section 7 · Algorithm design and problem-solving
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0984, 2026–2028 syllabus Version 4. It covers subject content Topic 7 only. The separately published 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding. Cambridge states that 0984 has the same 2026–2028 subject content as 0478, with 9–1 grading. In June and November, Cambridge lists 0984 in Administrative zone 3 and for centres in Oman and the UAE. Confirm availability for your centre and exam series with Cambridge International. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes.
Before you begin
- No programming language is required. Be comfortable with place value and multiplication; each lesson introduces the computer-science notation it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Which item does a linear search normally compare first?
What you will learn
- Describe linear search
- Report found and not-found outcomes
- Trace comparisons in sequence
Linear search checks each item in turn
A linear search starts at the first item and compares it with the target. If it matches, the search can report the position; otherwise it moves to the next item.
Apply and check the rule
If every item has been checked without a match, report NotFound. The list does not need to be sorted, but each preceding item may need to be checked before the target is found.
Pause and explain
In [4, 11, 7], how many comparisons are needed to find 7?
Worked example
Search [12, 5, 19, 8] for 19. How many comparisons are made?
Show the worked solution
- Compare 12 with 19: no match.
- Compare 5 with 19: no match.
- Compare 19 with 19: match on comparison three.
Answer The target is at position 3 in one-based counting; three comparisons are made.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Search [21, 17, 32, 9] for 17. State the comparison sequence and result.
Give me a hint
Stop at the first matching item.
Compare my reasoning
- Compare with 21: no.
- Compare with 17: match.
- Report the second item using one-based positions.
Comparisons: 21, 17; found at position 2.
Look for these in your work
- Order
- Stop at match
- Position
Search [3, 8, 2] for 5. How many comparisons occur and what should be reported?
Give me a hint
Check every item because no match appears early.
Compare my reasoning
- Compare 3, 8 and 2 with 5.
- No comparison matches.
- The list ends, so report not found.
Three comparisons; NotFound.
Look for these in your work
- All items checked
- Comparison count
- Outcome
A programmer returns the position of the last checked item even when the target is absent. Explain the error and a safer design.
Give me a hint
The final position is not evidence of a match.
Compare my reasoning
- Track whether a comparison actually equals the target.
- Only return a position after a successful match.
- If the list ends with no match, return NotFound or a defined sentinel.
The algorithm confuses the last inspected position with a successful result. Set a found flag or use a defined NotFound value and report a position only after equality is confirmed.
Look for these in your work
- Error identified
- Match condition
- Absent outcome
Common mistakes
- Claiming a linear search must sort the list first
- Returning a position after reaching the end without a match
What can you explain now?
What happens if a linear search reaches the end without a match?
Compare with the explanation
It reports that the target was not found
Every item has been checked, so there is no matching position.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How does linear search handle a found target and an absent target?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.