Selection sort works by maintaining a boundary between a sorted prefix and an unsorted suffix. On each pass, the algorithm finds the smallest value in the unsorted portion and places it into the first position of that unsorted portion (which is also the next position in the sorted prefix). This is usually done by swapping the element at the minimum’s index with the element at the boundary index (the “first unsorted element”). That description matches option D.
If the first element of the unsorted portion is already the smallest, then the minimum’s index equals the boundary index. In textbook implementations, the algorithm may still execute a swap operation, but it becomes a swap of an element with itself (a no-op), leaving the array unchanged. Many implementations include a small optimization: perform the swap only if the minimum index differs from the boundary index. Either way, conceptually the “action taken” by selection sort is still “swap the selected minimum into the first unsorted position,” which is exactly what option D states.
Options A and B are unrelated to sorting; selection sort never increases or duplicates values. Option C is incorrect because selection sort swaps the minimum with thefirstunsorted element, not the last. After the swap (or no-op), the sorted region grows by one element, and the algorithm repeats from the next boundary position.
This logic is fundamental for understanding how selection sort ensures correctness: after pass i, the smallest i+1 elements are fixed in their final positions.
Submit