Tracing a selection sort
A table of the array after each selection sort pass: the minimum of the unsorted part is swapped to the left, so the sorted part grows by one each pass.
Understanding Tracing a selection sort in WA Computer Science ATAR Unit 1
What it does: Swapping 1 with the 5 at the left gives [1, 2, 8, 5], and the sorted part has grown to one item. The minimum is 1 at index 4. It is swapped with the first item (5), giving [1, 3, 8, 5]. Only one swap happens. In pass 2 the minimum of [2, 7, 4] is 2, already in place, so the array stays the same. The 4 and 7 are only fixed in pass 3. Each pass begins by treating position i, the left end of the unsorted part, as the index of the minimum until a smaller value is found.
Common mistakes: Selection sort makes one swap per pass. The minimum (1) swaps places with the first item (5), giving [1, 3, 8, 5]. The other items do not shift along. Pass 1 makes one swap: the minimum (1) swaps with the first item (4). That gives [1, 2, 7, 4]. The 2 stays where it is.
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 100–314) 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
trace tableFill in the Blanks
Spot the Error
Student with a class code? Join your class →