Zum Inhalt springen
Brainlag

Design

Farbe

Searching algorithms: linear and binary search

Informatik GCSE Updated Wed 7 Oct 2026

A search algorithm finds a target value in a list, or reports that it is not there. You need to describe, trace and compare the two standard ones, and say when each is the better choice.

Part 1 of 3: Learn it

In short

  1. Linear search checks each item in turn and works on any list.
  2. Binary search needs the list in order first. Each check looks at the middle item and rules out half of what is left.
  3. For large sorted lists, binary search needs far fewer comparisons.

Where this is in your specification

Spec points: AQA 3.1.3, OCR 2.1.3, Edexcel Topic 1

BoardTopic: Algorithms
AQA 85253.1.1 to 3.1.4
Edexcel 1CP2Topic 1
OCR J2772.1.1 to 2.1.3
Eduqas C5008 Algorithms and constructs
Cambridge IGCSE 04787 Algorithm design and problem-solving
National 5 C816 75Software design and development: design, standard algorithms

Linear search

  • Start at the first item.
  • Compare it with the target. If they match, stop and report where it is.
  • Otherwise move to the next item and repeat.
  • If you reach the end with no match, the target is not in the list.

It is simple and the list does not need to be in order, but in the worst case it checks every item: 1000 comparisons for 1000 items.

Binary search

  • Look at the middle item of the part of the list still being searched.
  • If it is the target, stop.
  • If the target is bigger, discard the middle item and everything before it; if smaller, discard the middle item and everything after it.
  • Repeat on the half that is left until the target is found or nothing is left.

With an even number of items there are two middles; use the rule your board's pseudocode uses, usually (low + high) DIV 2.

Comparing them

Linear searchBinary search
List must be sorted?noyes
Worst case for 1000 items1000 comparisons10 comparisons
Good forshort or unsorted listslong sorted lists
Codevery simplea little harder

Each step of binary search halves the list, and 2¹⁰ = 1024, so 10 steps are enough for up to 1024 items.

Quick check

What must be true about a list before a binary search can be used?

Show the answer

It must be sorted.

Part 2 of 3: See it worked

Worked examples

Example 1

Use binary search to find 37 in the list 3, 8, 12, 19, 25, 31, 37, 44, 50 (positions 0 to 8).

  1. low = 0, high = 8, middle = 4: the value is 25. 37 is bigger, so low = 5
  2. low = 5, high = 8, middle = 6: the value is 37. Found

Answer: 37 is at position 6, found after 2 comparisons.

Example 2

A list of 500 names is not in alphabetical order. Which search should be used, and what is the most comparisons it could need?

  1. The list is unsorted, so binary search cannot be used
  2. Linear search might have to check every item

Answer: Linear search, with up to 500 comparisons.

Common mistakes

  • Running a binary search on an unsorted list.
  • Saying binary search always beats linear search. For a very short list, or a target near the start, linear can be as quick.
  • Forgetting to discard the middle item itself after checking it.
  • Describing the steps without saying what happens when the item is not found.
Quick check

What is the most comparisons a linear search could need for 80 items?

Show the answer

80.

Part 3 of 3: Test yourself

Check yourself

Answer each one in your head or on paper first, then open it to check.

What must be true about a list before a binary search can be used?

It must be sorted.

What is the most comparisons a linear search could need for 80 items?

80.

About how many comparisons does a binary search need, at most, for 1000 sorted items?

10, since 2¹⁰ = 1024.

Jobs that use this

Each link opens the job profile on the National Careers Service (England). In the rest of the UK: My World of Work (Scotland), Careers Wales, nidirect careers (Northern Ireland).

Diese Lernzettel sind auf Englisch, weil sie britischen Prüfungslehrplänen folgen.

Full lessons and marked practice for this course are coming soon to Brainlag Learn. See courses