Algorithms

Counting sort

A sorting algorithm that doesn't compare: it counts how many times each value appears and writes them in order. It works for integers in a small range.

Example

With 1 million grades from 1 to 10, it counts how many 1s, how many 2s... and writes them out: about 1 million steps.

Test yourself: Counting sort

Counting sort

To sort [3, 1, 3, 0], the counters array becomes [1, 1, 0, ___].

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.