AiTechWorlds
AiTechWorlds
Visualize Selection Sort finding the minimum each pass, with synced code, stats, and complexity breakdown.
def selection_sort(a):
n = len(a)
for i in range(n - 1):
m = i
for j in range(i + 1, n):
if a[j] < a[m]:
m = j
a[i], a[m] = a[m], a[i]Selection Sort scans the unsorted region for the minimum element and swaps it into place, making at most n−1 swaps total.
| Best | O(n²) |
| Average | O(n²) |
| Worst | O(n²) |
| Space | O(1) |
| Stable | No |
| In-place | Yes |
The Selection Sort Visualizer animates how Selection Sort works: on each pass it scans the unsorted region for the smallest element and swaps it into its final position. Selection Sort always runs in O(n²) time regardless of input, uses O(1) extra space, makes at most n−1 swaps, and is not stable. Use Play, Step, and the timeline to watch the minimum being selected each pass.
Generate an array
Click New Array or adjust the size slider to create random bars.
Play the animation
Press Play to watch the current minimum (highlighted) get selected and swapped into place.
Step and scrub
Step forward/back or drag the timeline to study each comparison.
Read the synced code
The highlighted pseudocode line tracks the algorithm; switch language tabs for C++, Java, Python, or JavaScript.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.