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 bubble sort's own run on the numbers shown.
choose one
1question 1
Bubble sort makes its first walk along 6, 2, 9, 4, 7. What is the row when that walk ends?
the answer, and why
the answer is A
The 6 and the 2 swap, the 6 and the 9 stay, then the 9 swaps with the 4 and with the 7, ending last.
if you chose another
BThat is the row sorted. One walk promises only that the biggest number reaches the end.
CThat stops after the first swap. A walk goes on to the end of its part.
DThat misses the last pair, 9 and 7, which the walk also swaps.
Each row holds 1 to 6 with little out of place. On which does bubble sort make the most comparisons?
the answer, and why
the answer is B
A small number near the end moves left one place a walk. The 1 needs five walks, each with a swap, so 5 + 4 + 3 + 2 + 1 = 15, the most 6 numbers can cost.
if you chose another
AThe 6 reaches the end in walk 1, and walk 2 swaps nothing, so 9.
CThe 6 reaches its place in walk 1, and walk 2 swaps nothing, so 9.
DThe 5 and the 6 reach the end in two walks, and a third swaps nothing, so 12.