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

Selection Sort

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.

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.

Pseudocode

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
Coding Interview Bootcamp: Algorithms + Data Structures

Learn essential data structures and algorithms step-by-step with practical JavaScript examples.

Practical Guide
JavaScript Algorithms & Data Structures Masterclass

Master DSA fundamentals, problem-solving techniques, and advanced structures using JavaScript.

Deep Dive
Master the Coding Interview: Data Structures + Algorithms

Prepare for top tech interviews with advanced DSA concepts and real-world coding challenges.

Learn DSA on Udemy
Learn DSA on Udemy
As an Udemy Associate, I earn from qualifying purchases.

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