Selection Sort Simulation
Selection Sort scans the unsorted portion of the array for the minimum element on each pass and swaps it into the next sorted position at the front.
Interactive simulation
- Pass
- 1
- Current min
- -
- Swaps
- 0
- Sorted front
- 0 / 10
- Speed
- 1x
Ready: press Select Next or Resume to start
Legend
- Unsorted element
- Scanning candidate
- Minimum found so far
- Sorted in final position
Event log
How to use this simulation
- Press Select Next once to step through one scan/swap event, or press Resume to animate continuously.
- Watch how the current minimum candidate is tracked and swapped into index
iat the end of each scan. - Use Step, Slower (down to 0.25x), Faster (up to 4x), and Reset to run with new values.
1. Scanning for the minimum
Starting at position i, Selection Sort sets minIdx = i and scans remaining indices j = i + 1 .. n - 1 to find the smallest value.
2. Swapping into position
Once the scan finishes, it swaps arr[i] with arr[minIdx] and advances i, locking another sorted element at the front.
3. Time & space complexity
Selection Sort always performs O(n²) comparisons regardless of input order, uses O(1) extra memory, and performs at most n - 1 swaps.