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
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(n²) | O(n²) | O(n²) |
| Space | O(1) | ||
Visualization
64
34
25
12
22
11
90
Implementation
Output
Click "Run Code" to see output...