Learn in your language
Skip to content
IGCSE · Cambridge (CIE) · 0478

Sort a list with bubble sort

Compare adjacent values and swap out-of-order pairs over repeated passes.

Cambridge IGCSE Computer Science 0478 · Algorithm design and problem-solving · 2026–2028 Version 6 · 7

This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. 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.

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

In ascending bubble sort, what happens when left value is greater than right value?

What you will learn

  • Describe a bubble-sort pass
  • Trace adjacent comparisons and swaps
  • Explain when repeated passes can stop

Bubble sort moves values by adjacent swaps

Bubble sort compares neighbouring items in a list. If a pair is in the wrong order, it swaps them; after a pass, a large value has moved toward the end of an ascending list.

Apply and check the rule

Repeat passes until the list is sorted. A program may stop after a pass with no swaps or after a known number of passes. Use a temporary variable or safe swap method so neither value is lost.

Pause and explain

After one ascending pass on [7, 3, 5], what is the list?

Put the idea to work

Worked example

Perform one left-to-right ascending bubble-sort pass on [5, 2, 4].

Show the worked solution
  1. Compare 5 and 2; swap to get [2, 5, 4].
  2. Compare 5 and 4; swap to get [2, 4, 5].
  3. The list after one pass is [2, 4, 5].

Answer [2, 4, 5].

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.

1 · Guided

Make one ascending bubble-sort pass over [6, 1, 4, 2].

Give me a hint

Compare each neighbouring pair from left to right.

Compare my reasoning
  1. Swap 6 and 1: [1, 6, 4, 2].
  2. Swap 6 and 4: [1, 4, 6, 2].
  3. Swap 6 and 2: [1, 4, 2, 6].

After one pass: [1, 4, 2, 6].

Look for these in your work

  • Adjacent comparisons
  • Swaps
  • Final pass state
2 · Independent

A bubble-sort routine swaps when Left < Right but claims to sort ascending. What order will it tend to produce?

Give me a hint

For ascending order, larger values should move right.

Compare my reasoning
  1. If left is smaller, the pair is already in ascending order.
  2. Swapping such a pair moves smaller values rightward.
  3. The condition is reversed for an ascending sort.

It tends to move smaller values to the right, producing descending order; swap when Left > Right instead.

Look for these in your work

  • Condition interpreted
  • Direction
  • Correction
3 · Transfer

A sort stops after one pass even though a swap occurred. Explain how an early-stop optimisation should work.

Give me a hint

A pass with swaps means the list may still be unsorted.

Compare my reasoning
  1. Track whether any pair was swapped during the pass.
  2. If a swap occurred, another pass may be needed.
  3. Stop early only after a complete pass with no swaps.

Use a Swapped flag: reset it before a pass, set it on any swap, and stop only when an entire pass has no swaps.

Look for these in your work

  • Flag reset
  • Flag set
  • Stop condition

Common mistakes

  • Comparing non-adjacent items as if they were a bubble-sort pair
  • Swapping values without preserving one of them
Recall without your notes

What can you explain now?

Which values does bubble sort compare at each step?

Compare with the explanation

Adjacent values

It compares neighbours and swaps a pair if they are out of order.

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

What happens during a bubble-sort pass, and when can the algorithm stop early?

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.

Keep learning Computer Science

Course scope and assessment

165 original lessons map the listed objectives across all 10 main topics in the 2026–2028 Version 6 syllabus, with worked explanations and guided, independent and transfer practice. This is mapped teaching coverage, not proof of full exam readiness. Three earlier starter lessons remain available but are not counted as syllabus-mapped teaching. Practical programming experience in an executable browser workspace, full timed-paper practice, human subject-teacher review and the separate 2029–2031 syllabus remain outstanding. Practice is self-checked and does not award an official Cambridge grade.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.