Practice question · Put in order
Order the steps of one round of selection sort.
- Repeat until the unsorted part is empty
- Swap it into the first unsorted position
- Shrink the unsorted part by one
- Scan the unsorted part to find the smallest remaining element
Hints
- Selection sort repeatedly finds the smallest remaining element and places it.
- You must find the minimum before you can place it.
Show the answer
- Scan the unsorted part to find the smallest remaining element
- Swap it into the first unsorted position
- Shrink the unsorted part by one
- Repeat until the unsorted part is empty
Why
Find the smallest remaining element, put it next, shrink the unsorted region, and repeat. Placing before finding would be impossible, the minimum must be located first.
Practise Sorting Strategies
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Sorting Strategies
- Stability in a sort, preserving the order of equal elements, sounds like a technicality. When does it become…
- Sorting stability only matters when the records carry information beyond the key being sorted on.
- Sort each sorting algorithm by its typical asymptotic cost.
- Comparison-based sorting cannot beat O(n log n), and counting sort runs in O(n). Why is that not a…
- Match each sort to its distinguishing property.