logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Heap Sort
    Radix 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 - 1):
        if arr[j] < arr[min]:
            min = j
    if min != i: swap(i, min)
Select number of elements:  

Curious to Learn More?

Hand-picked resources to deepen your understanding

Beginner Friendly
Grokking Algorithms

A friendly, fully illustrated guide. The best starting point for visual learners.

Practical Guide
A Common-Sense Guide to Data Structures and Algorithms

A practical guide with clear explanations and real-world examples.

Deep Dive
Introduction to Algorithms

The definitive guide (CLRS). Comprehensive and rigorous, perfect for deep diving into theory.

As an Amazon Associate, I earn from qualifying purchases. This helps support the site at no extra cost to you.

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