Data Structures & AlgorithmsHard

When sorting records by key with counting sort, why must the placement pass proceed in a specific direction for stability?

  1. A. Stability is irrelevant to counting sort.
  2. B. The direction only affects the speed, not the order.
  3. C. Placing elements from the end of the input backwards into their slots keeps equal keys in their original order.
  4. D. The keys must be placed from largest to smallest.

Correct answer: C. Placing elements from the end of the input backwards into their slots keeps equal keys in their original order.

Equal keys stay in input order when the output positions are filled from the last input element backwards, so stable placement is a deliberate direction choice.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic