AI engineering glossary · Data structures algorithms

What is counting sort?

Counting sort: A non-comparison sorting method for integers in a small known range that counts how many times each value occurs and then writes the values out in order. It runs in O(n + k) time, where k is the range size.

Level: intermediateTopic: Data structures algorithms

Counting sort: an example

Sorting 1 lakh exam marks between 0 and 100 needs only 101 counters and one pass, far faster than comparison sorting.

Related terms

More Data structures algorithms terms

Where you learn it

Counting sort is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.