Skip to content
BENIBIX Learn

Insertion Sort vs Selection Sort

Insertion sort slides each item back into place. It is quick when the list is nearly in order. Selection sort looks for the smallest item on each pass. It is always slow.

Development🧮 Algorithms & Data Structures

Insertion Sort

Take each item in turn. Slide it back to its right place.

Insertion sort builds a sorted part one item at a time. It takes the next item and slides it back until it sits in the right spot. On a list that is already nearly sorted, it is very fast. On a big jumbled list it is slow, about n squared steps. Fast sorts often switch to it for very small pieces.

Example
A list of 20 scores is in order except for one new score at the end. Insertion sort fixes it in a few steps.
Why it matters
It is simple and quick on small or nearly sorted lists. Real sorting code uses it for that job.
Full entry
Development🧮 Algorithms & Data Structures

Selection Sort

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

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.

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.
Full entry

In one line

Insertion Sort
Take each item in turn. Slide it back to its right place.
Selection Sort
Find the smallest item left. Move it to the front. Do it again and again.