Selection Sort
An in-place comparison sort that divides the list into a sorted and an unsorted part, repeatedly picking the smallest element from the unsorted part.
Parameters
Visualization
Step: 0Algorithm Insight
Selection Sort builds the sorted array by repeatedly finding the minimum element from the unsorted part.
- 1. Set the first unsorted position as the current Minimum.
- 2. Scan the rest of the unsorted part for a smaller value.
- 3. If found, update the Minimum index.
- 4. Swap the found minimum with the first unsorted element.
Complexity
Overview
Divide the array into a sorted prefix and an unsorted suffix. Scan the suffix for its minimum, swap that value with the first suffix position, and extend the prefix by one. After each pass, the prefix contains the smallest values in sorted order.