Foundations · Beginner
Selection Sort
Find the smallest remaining value and place it at the next open position.
- Best
- O(n²)
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stability
- Not stable
- Memory model
- In-place
How it builds order
- Treat the first unsorted item as the current minimum.
- Scan the rest for a smaller candidate.
- Swap the minimum into the boundary.
- Advance the sorted prefix.
Why it works
The minimum of the unsorted region belongs immediately after the sorted prefix, so each placement is final.
Watch for: The left prefix is final; the scan only searches the remaining suffix.
The interactive version of this page adds the full trace, synchronized pseudocode, practice decisions, input experiments, and mastery review.