Comparing the number of comparisons in bubble and selection sort
Bubble and selection sort both make about n squared comparisons, so doubling n quadruples the work, but selection sort makes far fewer swaps.
Understanding Comparing the number of comparisons in bubble and selection sort in WA Computer Science ATAR Unit 1
What it does: If a full pass makes no swaps, swapped stays FALSE and the loop ends early, so a sorted list needs only one pass. Selection sort swaps once, after finding the minimum. Bubble sort can swap on every comparison, so it makes far more swaps. Work grows with n squared. Doubling n gives 2 x 2 = 4 times as many comparisons. n is 10 times bigger, so n squared is 10 x 10 = 100 times bigger. Their comparison counts are of the same order, n squared. The big difference is the number of swaps. For n = 20, n(n-1)/2 = 190, which is about 4 times 45. Doubling only applies to a linear algorithm.
Common mistakes: Selection sort compares a[min] with the elements after position i, so the inner loop must start at i + 1. Starting at i adds a pointless comparison of an item with itself on every pass and gives the wrong comparison count. Each time bubble sort compares a[j] with a[j+1], the counter must go up by 1, so it should be comps ← comps + 1. Subtracting would make the total shrink instead of reaching about n squared.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 315–470) and word search (Modules 100–470).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
O(n^2)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →