Community resourceWorksheet
1CP2-CT-8.3 Bubble sort passes swaps and comparisons
Part 3 of 5 · 1CP2-CT-8 · Tracing, debugging, sorting and searching
Bubble sort repeatedly compares neighbouring items. If a pair is in the wrong order, it swaps them. One complete pass moves the largest remaining item towards the end. Passes repeat until a pass makes no swaps. You must apply, trace, recognise and amend this method; the specification does not require a full blank-editor implementation.
Students will:
- apply bubble sort one complete pass at a time
- record comparisons, swaps and resulting list states
- recognise bubble sort in Python
- amend a faulty comparison and explain its effect
Inside: 6 explanation cells, 1 fill-in-the-blanks cell, 3 multiple-choice questions and 5 written answers. 17 marks, about 45 minutes.
Series: 1CP2-CT-8 · Tracing, debugging, sorting and searching, part 3 of 5.
Shared by Coding PathwayVerified teacher
- 15 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Bubble sort: passes, swaps and comparisons
Bubble sort repeatedly compares neighbouring items. If a pair is in the wrong order, it swaps them. One complete pass moves the largest remaining item towards the end. Passes repeat until a pass makes no swaps. You must apply, trace, recognise and amend this method; the specification does not require a full blank-editor implementation.
1. Follow one pass
Only adjacent items are compared. In ascending order, swap when the left item is greater than the right item. Values already in order remain where they are for that comparison.
- adjacent
- pass
- swap
- random
After one pass through [6, 2, 4, 1] in ascending order, which statement must be true?
- AThe whole list is sorted
- BThe largest value has reached the final position
- CEvery possible pair was compared
- DThe smallest value must be first
2. Apply the algorithm by hand
For [5, 2, 4, 1], pass 1 produces [2, 4, 1, 5]: compare 5/2 and swap, 5/4 and swap, 5/1 and swap. Pass 2 produces [2, 1, 4, 5]. Pass 3 produces [1, 2, 4, 5]. A further check pass has no swaps, so the algorithm can stop.
Show the list after one complete ascending bubble-sort pass through [7, 3, 6, 2], and state the number of comparisons made.
Work from left to right through adjacent pairs.
Students type their answer here.
Starting from [3, 6, 2, 7], show the list after the next pass through the unsorted part.
The final 7 is already in its sorted position.
Students type their answer here.
3. Recognise bubble sort in code
Read without running.
values = [4, 1, 3]
for position in range(0, len(values) - 1):
if values[position] > values[position + 1]:
temporary = values[position]
values[position] = values[position + 1]
values[position + 1] = temporary
print(values)
This performs one pass, not the complete sort. The boundary stops at the second-last position because the code also reads position + 1.
What exact list is printed after this one pass?
- A[1, 3, 4]
- B[1, 4, 3]
- C[4, 1, 3]
- D[3, 1, 4]
Explain why the final position contains 4 after the pass.
Link adjacent comparisons, swaps and movement.
Students type their answer here.
4. Amend a faulty comparison
For ascending order, left > right triggers a swap. Replacing it with left < right sorts towards descending order. Removing position + 1 would compare an item with itself and make no useful progress.
A bubble-sort pass uses if values[position] < values[position + 1]: but the requirement is ascending order. State the correction and explain its effect.
Give the corrected operator and resulting swap rule.
Students type their answer here.
Why may bubble sort stop after a complete pass with no swaps?
- ANo adjacent pair was out of order, so the list is sorted
- BThe list has become unsorted
- CA pass deletes duplicate values
- DThe first item is always the largest
Two lists require 3 passes and 8 passes respectively with the same implementation. Explain what this evidence suggests about execution work.
Use passes and repeated comparisons, not the vague word faster alone.
Students type their answer here.
Route forward
You can apply, recognise and amend bubble sort. Next you will study binary search, where a sorted-data precondition allows half of the remaining items to be discarded after each comparison.