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
1question 1
Shell sort works on 6, 9, 1, 8, 3, 5, 2. What is the row after its first move?
the answer, and why
the answer is C
7 numbers take the gaps 4 and 1. The gap 4 pass first picks up the 3 at place 5. The 6, 4 places left, is bigger, so they trade.
if you chose another
AThat is insertion sort's first move, trading neighbours.
BThat trades numbers 3 places apart, the 9 and the 3.
DThat is after the whole gap 4 pass, which also trades the 9 and the 5.
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 B
Its gap 4 pass makes 3 comparisons and leaves 12 of its 14 wrong pairs. So the gap 1 pass makes 12 moves, and 16 comparisons, one per move and one for each of 4 numbers stopping short of the front. 19 in all.
6, 4, 1, 7, 5, 3, 2 pass by pass, 3 comparisons and then 16.
if you chose another
A13 comparisons. The gap 4 pass leaves 6 of its 21 wrong pairs.
C11 comparisons. The gap 4 pass leaves 3 of its 12 wrong pairs.
D11 comparisons. The gap 4 pass moves nothing, but only 3 pairs are wrong.