Skip to content

Selection sort

ordering

Level 1 of 3

Also called Straight selection.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from selection sort's own run on the numbers shown.

choose one

question 1

Selection sort works on 6, 9, 3, 8, 1, 7. Its first pass swaps the 1 into place 1. What is the row after its third pass?

693817
the answer, and why

the answer is C

Pass 1 gives 1, 9, 3, 8, 6, 7. Pass 2 gives 1, 3, 9, 8, 6, 7. Pass 3 swaps the 6 with the 9: 1, 3, 6, 8, 9, 7.

if you chose another

  • That is the row after pass 2.
  • That is the row sorted, after every pass.
  • That shifts the numbers along to make room for the 6, as insertion sort would. Selection sort swaps the 6 with the 9.

new numbersthe test page's numbers

question 2

How many comparisons does selection sort make on 6, 3, 5, 8, 9, 1, 4, from start to finish?

6358914
the answer, and why

the answer is C

The passes compare 6 + 9 + 3 + 2 + 1 numbers after their places, 21 in all.

if you chose another

  • That counts the swaps.
  • That is one comparison per pass, but each pass compares every number after its place.
  • That is insertion sort's count on this row.

new numbersthe test page's numbers

question 3

Selection sort works on each of these rows of 1 to 5. On which does it make the most swaps?

the answer, and why

the answer is D

Selection sort makes 4 swaps on 2, 5, 1, 3, 4, the most of the four.

if you chose another

  • Selection sort makes 3 swaps on this row, fewer than 4.
  • Selection sort makes 2 swaps on this row, fewer than 4.
  • Selection sort makes 3 swaps on this row, fewer than 4.

new numbersthe test page's numbers