Selection Sort is another comparison-based algorithm that sorts an array by repeatedly finding the minimum element from the unsorted part and moving it to its correct position. It minimizes the number of swaps needed compared to Bubble Sort, which makes it useful when the cost of moving items is high, but finding the smallest item is easy.
for i = 0 to (n - 1):
min = i
for j = i + 1 to (n - 1):
if arr[j] < arr[min]:
min = j
if min != i: swap(i, min)
Hand-picked resources to deepen your understanding
© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.