Skip to content
BENIBIX Learn

Selection Sort

Development🧮 Algorithms & Data StructuresSorting Algorithms

Also known as Selection Sorting, Select Sort

Find the smallest item left. Move it to the front. Do it again and again.

Think of it like

It is like picking teams by height. You find the shortest child, put them first, then find the next shortest.

Example

Jack sorts five cards: he finds the 1 and swaps it first, then finds the 2, and so on to the end.

Why it matters

It is one of the easiest sorts to understand, so it is often taught first. It also shows why some sorts are slow.

Definition

Selection sort finds the smallest item left and swaps it to the front. Then it does the same for the rest of the list, one place at a time. It always takes about n squared steps, even if the list is already sorted. It makes very few swaps, at most one per place. That only helps when moving items costs a lot.
Selection sort, on the right: the smallest card left is swapped to the front.

Common mistake

Thinking it speeds up on sorted data. It still checks every item left on every pass.

Key takeaways

  1. 1
    Find the smallest. Scan what is left each pass.
  2. 2
    Few swaps. At most one per place.
  3. 3
    Always slow. About n squared, even when sorted.

Compare