Algorithms and Data Structures · Middle · Question 8 of 75

When can counting sort beat O(n log n)?

Explanation

Counting sort doesn't compare elements: it counts how many times each key occurs and writes them back in order. It's great for ages or grades, but a huge range of keys makes the count array too large.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 8

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz