Skip to content
Menu

Year 9 (ages 13–14, Grade 8 in the US) · Computing · Algorithms · Lesson 1

Linear search

How a linear search works, tracing it, counting comparisons, best and worst cases, and writing it in Python.

Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

Whiteboard video lesson: Linear search

20-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Describe a linear search
  • Trace a linear search
  • Count comparisons
  • Read linear search code

The method

  1. Start at position 0.
  2. Compare with the target.
  3. Match? Stop. No? Next item.
  4. Count the comparisons.

Key words: algorithm, linear search, comparison, index, worst case.

Worked examples

Worked examples from the lesson, with every step.

Question 1

Use a linear search to find 9 in the list [7, 3, 9, 2, 5, 8]. How many comparisons are needed?

  1. Step 1: Start at position 0
  2. Step 2: Check each item in turn

Answer: found at position 2 after 3 comparisons

Question 2

Use a linear search to find 7 in the list [7, 3, 9, 2, 5, 8]. How many comparisons are needed?

  1. Step 1: Start at position 0
  2. Step 2: Check each item in turn

Answer: found at position 0 after 1 comparison

Question 3

Use a linear search to find 8 in the list [7, 3, 9, 2, 5, 8]. How many comparisons are needed?

  1. Step 1: Start at position 0
  2. Step 2: Check each item in turn

Answer: found at position 5 after 6 comparisons