Skip to content

Shell sort

ordering

Level 2 of 3

Also called Diminishing increment sort.

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 shell sort's own run on the numbers shown.

choose one

question 1

Shell sort works on 4, 5, 7, 6, 1, 3, 2. What is the row after its first move?

4576132
the answer, and why

the answer is D

7 numbers take the gaps 4, 1. The gap 4 pass trades first where a number has a bigger one 4 places to its left, the 1 and the 4: 1, 5, 7, 6, 4, 3, 2.

if you chose another

  • That is insertion sort's first move, trading neighbours.
  • That trades numbers 3 places apart, the 5 and the 1.
  • That is the row after the whole gap 4 pass, not its first move.

new numbersthe test page's numbers

question 2

How many moves does Shell sort make, from start to finish, on 7, 3, 2, 8, 5, 9, 4, 1?

73285941
the answer, and why

the answer is B

Gap by gap (4, 1), its passes make 2 + 10 moves, 12 in all.

if you chose another

  • That is insertion sort's count, one move per wrong pair.
  • That counts the comparisons.
  • That counts the numbers that change place. Each move trades two.

new numbersthe test page's numbers

question 3

Shell sort works on each of these orders of 1 to 7. On which does it make the most comparisons?

the answer, and why

the answer is D

Shell sort makes 16 comparisons on 3, 1, 5, 7, 4, 2, 6, the most of the four.

if you chose another

  • Shell sort makes 15 comparisons on this row, fewer than 16.
  • Shell sort makes 14 comparisons on this row, fewer than 16.
  • Shell sort makes 15 comparisons on this row, fewer than 16.

new numbersthe test page's numbers