Bubble sort – practice for Years 7–9
Sample questions on Bubble sort with the right answer and a worked solution, from easy to hard. In the Pickles Academy app a child gets new questions of the same kind every time, so they can't just learn the answers by heart.
- Subject
- Computing
- Year
- Years 7–9
- Curriculum area
- Information systems
Question types: Bubble sort
Rule: Bubble sort
Compare neighbouring pairs from left to right and swap them when the left one is bigger. Repeat while anything is swapped.
After each pass the biggest remaining number is in its place on the right.
Example: 3, 1, 2: swap 3 and 1 → 1, 3, 2; swap 3 and 2 → 1, 2, 3 (2 swaps)
Watch out: Count swaps, not comparisons. There are as many swaps as pairs of numbers in the wrong order.
Sample questions
-
Question 1 Easy
Bubble sort goes through the list from left to right, compares each two neighbouring numbers and swaps them when the left one is bigger. It repeats such passes while it still swaps something. How many swaps does it make to sort 13, 9, 1, 7 from smallest to largest?
Show the solution
Answer: 5How it works: Swaps in each pass: 3 + 2 + 0 = 5.
-
Question 2 Normal
Bubble sort goes through the list from left to right, compares each two neighbouring numbers and swaps them when the left one is bigger. It repeats such passes while it still swaps something. How many swaps does it make to sort 17, 2, 14, 1, 10, 18 from smallest to largest?
Show the solution
Answer: 7How it works: Swaps in each pass: 4 + 2 + 1 + 0 = 7.
-
Question 3 Hard
Bubble sort goes through the list from left to right, compares each two neighbouring numbers and swaps them when the left one is bigger. It repeats such passes while it still swaps something. What does the list 17, 2, 14, 1, 10, 18 look like after the first pass?
Show the solution
Answer: C) 2, 14, 1, 10, 17, 18How it works: After pass 1: 2, 14, 1, 10, 17, 18.
Keep practising in the app
In a minute, your child has their own avatar and a first task. Free, no ads, data in the EU.
Start for free