Playground

Selection Sort

Watch the algorithm scan for the minimum element and swap it into the sorted region each pass.

Selection Sort

Scan the unsorted region for the minimum element, then swap it into the next sorted position.

Time O(n²)  |  Space O(1)  |  Not Stable  |  In-place
Data
Size15
Speed800ms
380271432339482510655734876912106111501218139014
default
comparing
minimum
swapping
sorted

SELECTION SORT

for i = 0 to n-2:
minIdx = i
for j = i+1 to n-1:
if arr[j] < arr[minIdx]:
minIdx = j
swap(arr[i], arr[minIdx])
// array is sorted

Console Output

n = 15
>Press SORT to begin…