Sorted
Current Min
Scanner
i
29
MIN
0
10
1
14
2
37
3
13
4

The Treasure Hunt

Selection Sort works by repeatedly finding the minimum element (the 'treasure') from the unsorted part and putting it at the beginning.

Finding the Smallest

We assume the first element (29) is the minimum. Now we scan the rest to see if we're wrong.

Found a Smaller One!

10 is smaller than 29. Update our Minimum pointer.

Keep Looking

Is 14 < 10? No. Is 37 < 10? No. Is 13 < 10? No. We scanned the whole list.

Swap!

The smallest item is 10. We drag it to the front (swap with 29). The first position is now sorted.

Next Round

Now we look at the remaining unsorted part starting at index 1. 29 is our current candidate.

Better Candidate

14 is smaller than 29. Update Minimum.

Even Better

Continue scanning... 37 is huge. But 13? 13 is smaller than 14! Update Min again.

Swap Again

13 is the winner of this round. Swap 13 with the current front (29).

Halfway There

Start at index 2 (14). Scan... 37 > 14. 29 > 14. 14 is already the smallest!

No Swap Needed

If the minimum is already in place, we just lock it in.

Final Swap

Compare 37 and 29. 29 is smaller. Swap them.

Sorted!

We are left with one element (37). A single element is always sorted. We are done.

Simplicity vs Speed

Selection Sort is easy to understand but slow (O(n²)). However, it creates the minimum number of swaps (O(n)), which can be useful if *writing* to memory is expensive.

Selectively Slow.

A great starting point, but rarely used in production due to O(n²).

AlgoAnimator: Interactive Data Structures