Algorithm Learning/Selection Sort

Selection Sort

Selection sort sorts an array by repeatedly finding the minimum element from unsorted part and putting it at the beginning.

EasySortingBasicsIn-place SortO(n²)

Definition

Selection sort is a sorting algorithm that repeatedly finds the smallest value in the array and swaps it with the value at the beginning.

Key Characteristics

  • Each round "selects" the minimum value from remaining array - origin of the name
  • Few swaps - maximum n-1 swaps (beneficial when memory writes are expensive)
  • Unstable sort - relative order of equal elements may change
  • Always O(n²) regardless of input - performs all comparisons even for sorted arrays

Use Cases

Used in these scenarios:

💾

Memory Write-Expensive Environments

Minimize swaps in storage devices with limited write cycles like flash memory

📚

Educational Algorithm

Simple structure that makes it easy to understand basic sorting principles

🔢

Small Datasets

For small data sizes, simple and easy-to-implement selection sort is efficient

Operations

Main operations:

Find Minimum

O(n)

Find the position of the smallest value in the unsorted portion.

Swap

O(1)

Swap the found minimum value with the value at the current sort position.

Complexity

Time Complexity

Best
O(n²)
Average
O(n²)
Worst
O(n²)

Space Complexity

O(1)

Understand Deeper with Visualization

See how the algorithm works through step-by-step animations and code execution.

Start Visualization