Intermediate Data Structures & Algorithms
Q75 / 100

Why does counting sort run in linear time, and what limits its applicability?

Correct! Well done.

Incorrect.

The correct answer is B) It tallies occurrences of each key value in a count array and then reconstructs the sorted output in O(n + k), but it is only practical when the range of key values k is not much larger than n

B

Correct Answer

It tallies occurrences of each key value in a count array and then reconstructs the sorted output in O(n + k), but it is only practical when the range of key values k is not much larger than n

Explanation

Counting sort builds a frequency array indexed by key value, computes prefix sums to determine final positions, and places elements accordingly, achieving O(n + k) time. It becomes inefficient in time and space when the key range k is very large relative to n.

Progress
75/100