5

Configure inputs and press Visualize to begin.

64
34
25
12
22
11
90
45
Default
Comparing
Swap
Pivot
Sorted
Found
Pseudocode & Implementations
1 approach

Find min in unsorted portion, place at front. Makes exactly n-1 swaps regardless of input.

SELECTION-SORT(A):
  n = length(A)
  FOR i = 0 TO n-2:
    minIdx = i
    FOR j = i+1 TO n-1:
      IF A[j] < A[minIdx]:
        minIdx = j
    SWAP(A[i], A[minIdx])
  RETURN A
Complexity Analysis

Time Complexity

Best Case
QuadraticO(n²)
Average
QuadraticO(n²)
Worst Case
QuadraticO(n²)
Space (aux)
ConstantO(1)
UnstableIn-placecomparisonsimplein-place
About

Finds the minimum element from the unsorted portion and places it at the beginning. Makes exactly n-1 swaps.

Key Insight

Minimizes the number of swaps, making it useful when write operations are expensive.

Use Cases

Memory-constrained environmentsWhen swaps are costly