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.

  1. Iterate through the array with index i.
  2. For each i, find the index of the minimum element in the range from i to the end of the array.
  3. Swap the element at i with the element at minIndex.
  4. Print the final sorted array (space-separated).

01EXAMPLE 1

Input[64, 25, 12, 22, 11]
Output11 12 22 25 64

Explanation: Smallest element moved to front each step.

Constraints

  • In-place sorting.
AlgorithmsSorting
JavaScript
Loading...
1 Hidden

Input Arguments

data[64,25,12,22,11]

Expected Output

11 12 22 25 64

Click RUN to test your solution