Questions: Counting Sort Algorithm

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

What is the time complexity of counting sort when sorting n integers drawn from the range [0, k−1]?

AO(n log n) — same as comparison-based sorts like merge sort
BO(n + k) — one pass over the input plus one pass over the count array
CO(n × k) — each element is compared against all k possible values
DO(k log k) — the count array itself must be sorted
Question 2 Multiple Choice

You need to sort 1,000 integers where each value can range from 0 to 1,000,000,000. Would counting sort be the best approach?

AYes — counting sort is always faster than comparison sorts since O(n + k) beats O(n log n)
BNo — with k = 10^9 and only n = 1,000 elements, the count array would require a billion entries, making counting sort far less practical than a comparison sort
CYes — as long as the values are integers, counting sort outperforms merge sort regardless of range
DIt depends only on whether the array is nearly sorted; counting sort is best for nearly-sorted inputs
Question 3 True / False

Counting sort avoids the O(n log n) comparison-sort lower bound by making fewer comparisons than merge sort — it simply compares elements more cleverly.

TTrue
FFalse
Question 4 True / False

Counting sort is a stable sorting algorithm, meaning elements with equal keys appear in the output in the same relative order they had in the input.

TTrue
FFalse
Question 5 Short Answer

Explain why counting sort can sort n elements faster than O(n log n) in some cases, but cannot universally replace comparison-based sorting algorithms.

Think about your answer, then reveal below.