SortLab

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

  1. Treat the first unsorted item as the current minimum.
  2. Scan the rest for a smaller candidate.
  3. Swap the minimum into the boundary.
  4. 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.

Compare related strategies