Selection Sort
A simple comparison-based sorting algorithm. It divides the list into sorted and unsorted regions, repeatedly selecting the minimum element from the unsorted region.
Selection Sort Algorithm
Selection Sort: Pass 0 (finding min)
Starting Selection Sort with 7 elements
Current array: [64, 34, 25, 12, 22, 11, 90] (length: 7)
One pass of selection sort
Order what happens in a single pass.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
Test your knowledge
How many swaps does Selection Sort perform in the worst case?
The short version
Imagine picking the smallest candy from a jar one at a time. Each time you pick, you scan ALL remaining candies to find the smallest, then swap it to the front.
In more depth
How It Works
Selection Sort maintains two regions: sorted (left) and unsorted (right).
Algorithm:
Key Properties
When to reach for this
- When swap cost is significantly higher than comparison cost
- When memory writes are expensive (flash memory)
- When simplicity is prioritized over efficiency
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required