📁 Paper 1 · Topic 1: Computational Thinking
1.2c Sorting: Bubble Sort
Edexcel 1CP2 · GCSE Computer Science · ~12 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

What is Bubble Sort?

Bubble sort is a simple sorting algorithm that works by repeatedly comparing adjacent pairs of elements and swapping them if they are in the wrong order. After each pass through the list, the largest unsorted element "bubbles up" to its correct position at the end.

How Bubble Sort Works — Step by Step

  1. Start at the first element of the list
  2. Compare the first and second elements; if the first is larger, swap them
  3. Move to the next pair (second and third) and repeat
  4. Continue until the end of the list — this completes one pass
  5. Repeat the whole process for the remaining unsorted portion
  6. Stop when a complete pass makes no swaps — the list is sorted

Worked Example

Sort [5, 3, 8, 1, 2] using bubble sort:

PassList stateSwaps made
Pass 1[3, 5, 1, 2, 8]3: (5,3), (5,8 no), (8,1), (8,2) → 8 in place
Pass 2[3, 1, 2, 5, 8]2: (3,5 no), (5,1), (5,2) → 5 in place
Pass 3[1, 2, 3, 5, 8]2: (3,1), (3,2) → 3 in place
Pass 4[1, 2, 3, 5, 8]0 swaps → STOP (list sorted)

Efficiency

Best case: The list is already sorted. One pass with 0 swaps is needed → n-1 comparisons total.

Worst case: The list is in reverse order. n passes each comparing n elements → roughly n² comparisons total.

Bubble sort is considered inefficient for large lists because its worst-case performance is quadratic. For small lists, it is easy to understand and implement.

Exam tip: In an Edexcel exam, you may be asked to trace through one or two passes of bubble sort on a given list. Make sure to show the state of the list after each comparison where a swap occurs, and state how many swaps were made in each pass.

Optimisation

Bubble sort can be optimised by keeping track of whether any swap occurred in a pass. If no swaps happened, the list is already sorted and the algorithm can stop early. This is the optimised/early exit bubble sort.

⚠️ Common Mistakes
  • Stopping after a fixed number of passes rather than checking for zero swaps
  • Forgetting that after each pass, the last n items are already in place and don't need to be compared again
  • Showing the wrong state after a swap — always update the list immediately
  • Confusing bubble sort with selection or insertion sort in an exam
Video coming soon
In production

Key points covered

  • Bubble sort step-by-step trace on a worked example
  • What a pass is and what happens at the end of each pass
  • Optimised bubble sort with early exit
  • Best case and worst case scenarios
  • Exam technique: showing passes in a trace table
Click slide or press arrow keys to navigate
✍️

Worksheet — 1.2c Bubble Sort

8 Edexcel-style questions · instantly marked

Q1State what happens when two adjacent elements are compared and found to be in the wrong order in bubble sort.[1]
✅ Mark scheme
They are swapped. [1]
Q2Describe what a "pass" means in the context of bubble sort.[1]
✅ Mark scheme
One complete iteration through the list, comparing each adjacent pair. [1]
Q3Show the state of the list [4, 1, 6, 3, 2] after the first complete pass of bubble sort. Clearly show each swap.[3]
✅ Mark scheme
Compare 4,1 → swap → [1,4,6,3,2] [1]
Compare 4,6 → no swap
Compare 6,3 → swap → [1,4,3,6,2] [1]
Compare 6,2 → swap → [1,4,3,2,6] [1]
End of pass 1: [1,4,3,2,6] — 6 is now in its final position
Q4State the condition that causes bubble sort to stop early (optimised version).[1]
✅ Mark scheme
When a complete pass is made with zero swaps / no swaps occur during a pass. [1]
Q5After each pass of bubble sort, what is guaranteed about the end of the list?[1]
✅ Mark scheme
The largest unsorted element has moved to its correct final position at the end. [1]
Q6A list already sorted in ascending order is given to bubble sort. How many passes will the optimised version need? Explain your answer.[2]
✅ Mark scheme
One pass [1] — the algorithm makes a single pass, finds no swaps, and stops immediately as the list is already sorted [1].
Q7Explain why bubble sort is considered inefficient for large lists.[2]
✅ Mark scheme
In the worst case, bubble sort requires approximately n² comparisons for n items [1]; as the list grows, the number of comparisons grows quadratically, making it very slow for large datasets [1].
Q8Trace all passes of bubble sort on the list [9, 3, 7, 1]. Show the list after each pass and count the number of swaps per pass.[4]
✅ Mark scheme
Pass 1: compare(9,3)→swap, compare(9,7)→swap, compare(9,1)→swap → [3,7,1,9], 3 swaps [1]
Pass 2: compare(3,7)→no, compare(7,1)→swap → [3,1,7,9], 1 swap [1]
Pass 3: compare(3,1)→swap → [1,3,7,9], 1 swap [1]
Pass 4: no swaps → stop [1] — sorted: [1,3,7,9]
Topic Quiz
Question 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — 1.2c Bubble Sort

Timed exam-style test. No hints until submission.

  • 10 questions · 10 marks · 10 minutes
  • 5 MCQ + 5 short answer
← 1.2b Searching AlgorithmsTopic 1: Computational ThinkingNext: 1.2d Merge Sort →
🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year