Skip to main content

Selection Sort

Definition​

Selection Sort is a simple comparison-based sorting algorithm that divides the input list into two parts: a sorted sublist and an unsorted sublist. It repeatedly selects the smallest (or largest) element from the unsorted sublist and swaps it with the leftmost unsorted element, moving the sublist boundaries one element to the right

Practice​

selectionSort(array A)
n = length of A
for i from 0 to n-1
minIndex = i
for j from i+1 to n-1
if A[j] < A[minIndex]
minIndex = j
swap A[i] with A[minIndex] // Swap the minimum element with the first unsorted element