Limited access

Recall that in selection sort, the $k$th smallest element is selected and swapped with the element in the $k$th position for each iteration $k$ over the list. A stable sort is one in which two elements with equal keys appear in the same order in the sorted list as they appear in the unsorted list.

Although selection sort is NOT a stable sort, it might not change the order of like elements of a particular list.

Consider the following unsorted list:

$1 \;\;\; 3 \;\;\; 3 \;\;\; 7 \;\;\; 1 \;\;\; 2$

If elements are equal, we will use the convention to select the left-most element as the minimum.

Note: In the case that two values have the same smallest value, the left-most is chosen.

Will the order of the 1s and 3s be preserved in the sorted output of the selection sort?

A

Yes.

B

No; the 1s will be out of order.

C

No; the 3s will be out of order.

D

No; both the 1s and 3s will be out of order.

Select an assignment template