The Minimum Anchor
EasyAcc. 96.2%
+15 XP 5
The Minimum Anchor (Selection)
Selection Sort works by scanning the unsorted part of the array to find the absolute minimum value. Once found, it swaps that value with the first unsorted position, "anchoring" it in place.
The Assignment
Your mission is to anchor the smallest values first. Your function receives data.
- Iterate through the array with index
i. - For each
i, find the index of the minimum element in the range fromito the end of the array. - Swap the element at
iwith the element atminIndex. - Print the final sorted array (space-separated).
01EXAMPLE 1
Input
[64, 25, 12, 22, 11]Output
11 12 22 25 64Explanation: Smallest element moved to front each step.
Constraints
- In-place sorting.
AlgorithmsSorting
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
data[64,25,12,22,11]
Expected Output
11 12 22 25 64
Click RUN to test your solution