logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Radix Sort
    Heap Sort
    Merge Sort
    Quick Sort

Selection Sort

Selection Sort is like a choosy person picking the best apples. It scans the unsorted section, selects the smallest item, and places it at the correct position. This process repeats until the entire list is sorted. Selection sort 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.

Things to Observe

  • Finding the Minimum: In each pass, watch how the algorithm scans the entire unsorted portion of the array to find the single smallest element.
  • One Swap Per Pass: Notice that there is only one swap at the very end of each pass. This is a key difference from Bubble Sort and is the reason why Selection Sort is preferred when write operations are expensive.
for i = 0 to (n - 1):
    min = i
    for j = i + 1 to (n):
        if arr[j] < arr[min]:
            min = j
    if min != i: swap(i, min)
Select number of elements:  

© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.