Selection Sort Visualizer

See Selection Sort scan for each minimum and place it into position with animated comparisons, swaps, controls, and metrics.

Current status: Comparing the highlighted values to decide the next move.

Comma-separated numbers, up to 20 values.

Balanced

Live operation

compare

Step 1 / 18
5
[0]
3
[1]
8
[2]
4
[3]
2
[4]
Compare candidatesPlace minimumSorted prefix

Comparisons

1

Moves / writes

0

Confirmed sorted

0 / 5

Algorithm notes

What to watch for

Selection Sort grows a sorted prefix from left to right. It spends comparisons finding the smallest remaining value, then performs at most one swap for each position.

Concept guide

Review the mental model, tradeoffs, and practical use cases after you experiment.

Selection Sort Complete Info Card

Comparison SortMinimum Swaps

Selection Sort works by repeatedly selecting the smallest element from the unsorted portion and swapping it with the first unsorted element. It maintains two subarrays: sorted and unsorted.

Algorithm Characteristics

Time Complexity (Best)

Same as average case

O(n²)

Time Complexity (Average)

Regardless of input order

O(n²)

Time Complexity (Worst)

Same as average case

O(n²)

Space Complexity

In-place sorting algorithm

O(1)

Stable

May change order of equal elements

No

Adaptive

Performance doesn't improve with nearly-sorted inputs

No

Sorting Process Steps

1

Find minimum element in unsorted portion

2

Swap with first unsorted position

3

Expand sorted portion by one element

4

Repeat until entire array is sorted

5

Performs exactly n-1 swaps total

Key Feature: Minimum Swaps

Selection Sort

Selection Sort makes exactly n-1 swaps always

Always n-1 swaps

Bubble Sort

Bubble Sort makes O(n²) swaps in worst case

Up to n² swaps

Insertion Sort

Insertion Sort adapts to nearly-sorted data

O(n²) worst case

When to Use

  • When swap operations are expensive
  • Small datasets or educational purposes
  • Memory-constrained environments

When to Avoid

  • Large datasets (use QuickSort/MergeSort)
  • When stability is required
  • Nearly-sorted data (use Insertion Sort)
Did You Know? Selection Sort performs the same number of comparisons in all cases, but always makes exactly n-1 swaps.
Fixed swapsSimple to implementQuadratic time