Codacoda
Back to Academy

sorting

Selection Sort

Selection Sort divides the array into a sorted and unsorted region, repeatedly finding the minimum element from the unsorted region and moving it to the end of the sorted region. It performs the minimum number of swaps (O(n)) among comparison-based sorts, making it useful when write operations are expensive.

Use Cases

  • When the number of swaps must be minimized
  • Small datasets where simplicity is valued
  • Memory-constrained environments requiring in-place sorting

Complexity Analysis

MetricBestAverageWorst
TimeO(n²)O(n²)O(n²)
SpaceO(1)

Visualization

64
34
25
12
22
11
90
Speed:1x
Initial arrayStep 1 / 39

Implementation

Output

Click "Run Code" to see output...