Searching and sorting

Finding and ordering data quickly matters for every app you use. You need to know two searches and two sorts.

Practise this lesson free (6 questions)

More tools

Linear and binary search

Linear search: check each item in turn from the start. Works on any list, but slow for big lists.
Binary search: the list must be sorted. Check the middle item; if it is not the target, throw away the half that cannot contain it. Repeat. Much faster on big lists.

Bubble sort

Compare each pair of neighbouring items and swap them if they are in the wrong order.
One full pass moves the largest item to the end. Repeat passes until no swaps are needed.
[5, 1, 4, 2, 8] after one pass becomes [1, 4, 2, 5, 8].

Merge sort

Divide the list in half again and again until each list has one item.
Then merge pairs of lists back together in order.
Merge sort is usually much faster than bubble sort on large lists, but uses more memory.
Worked example

Use binary search to find 23 in [3, 8, 12, 15, 23, 31, 40].

  1. Middle item is 15. 23 > 15, so discard the left half.
  2. Remaining: [23, 31, 40]. Middle item is 31. 23 < 31, so discard the right.
  3. Remaining: [23]. Found.

Answer: Found in 3 comparisons.

Key idea

Linear search checks every item; binary search halves a sorted list each time. Bubble sort swaps neighbours in passes; merge sort splits then merges and is faster on big lists.

Key words
Linear search
Checks each item in turn from the start of a list until the target is found or the list ends.
Binary
Base 2: the number system that uses only the digits 0 and 1.
Binary search
Repeatedly checks the middle item of a sorted list and discards half the list.
Bubble sort
Sorts by comparing neighbouring items and swapping them, in passes, until a pass makes no swaps.
Merge sort
Splits a list into single items, then merges pairs of lists back together in order.

All GCSE and International GCSE Computer Science key terms and definitions →

Common mistakes
Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. The list [9, 2, 7, 4, 1] needs searching. Why can binary search not be used on it?

    1. It has an odd number of items
    2. It contains numbers
    3. It is too short
    4. It is not sorted
    Show the answer

    Answer: It is not sorted

    Binary search needs sorted data.

  2. Show [5, 1, 4, 2] after ONE pass of bubble sort. Type it like 1, 2, 3, 4.

    Show the answer

    Answer: 1, 4, 2, 5

    5,1: swap; 5,4: swap; 5,2: swap. Result: 1, 4, 2, 5.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Facts checked against the sources below, 17 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

What do exam command words like explain and evaluate mean? →

Related lessons