Skip to content
VirtusAcademy

Bubble Sort

FoundationHigherAQA

Revise Bubble Sort for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers for AQA GCSE Computer Science (8525). A bubble sort repeatedly compares adjacent items and swaps them until the list is in order.

Free downloads

These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.

Topic overview

A bubble sort repeatedly passes through a list, comparing each adjacent pair and swapping them if they are in the wrong order.

After the first pass, the largest item has moved to the end of the list — this is why it is called a bubble sort, as large values bubble upwards. Each subsequent pass places the next largest item, so the sorted section at the end grows by one each time.

The algorithm stops when a complete pass makes no swaps, which means the list is sorted. It is simple to understand and to write, but inefficient: for n items it may need n − 1 passes, making it much slower than a merge sort on large lists.

Revision notes

How it works

Compare the first two items and swap them if they are in the wrong order.

Move to the next pair and repeat, all the way to the end. That is one pass. After the first pass the largest item is in its final position at the end.

When it stops

Repeat passes until a complete pass makes no swaps.

No swaps means every adjacent pair is in order, so the whole list is sorted. Each pass can ignore the items already placed at the end.

Efficiency

Simple to understand and implement, and needs little extra memory.

But inefficient: for n items it may need n − 1 passes, each with up to n − 1 comparisons. This makes it far slower than a merge sort on large lists.

Key points

  • A bubble sort compares adjacent pairs.
  • Pairs in the wrong order are swapped.
  • One pass moves the largest item to the end.
  • The sorted section grows by one each pass.
  • It stops when a pass makes no swaps.
  • It is simple but inefficient on large lists.

Worked examples

Example 1

Perform one pass of a bubble sort on 5, 3, 8, 1. [3 marks]

Working

Compare 5 and 3: swap, giving 3, 5, 8, 1compare and swap the first pair
Compare 5 and 8: no swap, list stays 3, 5, 8, 1compare the second pair
Compare 8 and 1: swap, giving 3, 5, 1, 8compare and swap the third pair

Example 2

Explain how a bubble sort knows the list is sorted. [2 marks]

Working

A complete pass is made without any swaps being neededstate the condition
which means every adjacent pair is already in the correct order, so the whole list is sortedexplain why that means sorted

Example 3

Give one advantage and one disadvantage of a bubble sort. [2 marks]

Working

Advantage: it is simple to understand and to program, and uses little extra memorygive the advantage
Disadvantage: it is inefficient on large lists, needing up to n − 1 passesgive the disadvantage

Common mistakes

  • Swapping non-adjacent items.

    Only adjacent pairs are compared and swapped.

  • Stopping after one pass.

    Passes repeat until one makes no swaps.

  • Forgetting the largest item is placed first.

    After pass one the largest is at the end, not the smallest at the start.

  • Saying it is efficient because it is simple.

    Simplicity and efficiency are different things.

Exam tips

  • Show each comparison separately in a trace.
  • State that it stops when a pass makes no swaps.
  • Remember the largest item settles first.
  • Give both an advantage and a disadvantage.

Key terms

Bubble sort
Sorting by repeatedly swapping adjacent items.
Pass
One complete run through the list.
Swap
Exchanging two items that are in the wrong order.
Adjacent
Next to each other in the list.

Written and reviewed against the current AQA specification. Spotted an error? Let us know.