question 1
Selection sort works on 5, 9, 3, 8, 1, 6. Its first pass swaps the 1 into place 1. What is the row after its third pass?
the answer, and why
the answer is B
Pass 1 swaps the 1 and the 5, giving 1, 9, 3, 8, 5, 6. Pass 2 swaps the 3 and the 9, giving 1, 3, 9, 8, 5, 6. Pass 3 swaps the 5 and the 9, giving 1, 3, 5, 8, 9, 6.
if you chose another
- That is the row after pass 2.
- That is the row sorted, two passes later.
- That shifts the 9 and the 8 along to make room for the 5, as insertion sort would. Selection sort swaps the 5 with the 9.