GATE Computer ScienceHardGATE CS (PYQ pattern)

LSD radix sort (decimal digits, stable counting sort on each digit, least significant first) is applied to [329, 457, 657, 839, 436, 720, 355, 102, 893]. What does the array look like after the second pass (tens digit)?

  1. A. [720, 102, 893, 355, 436, 457, 657, 329, 839]
  2. B. [102, 720, 329, 436, 839, 355, 457, 657, 893]
  3. C. [102, 329, 355, 436, 457, 657, 720, 839, 893]
  4. D. [102, 720, 329, 839, 436, 355, 457, 657, 893]

Correct answer: B. [102, 720, 329, 436, 839, 355, 457, 657, 893]

Pass 1 (units) gives 720, 102, 893, 355, 436, 457, 657, 329, 839; pass 2 sorts by the tens digit, keeping the order of equal digits: 102 | 720, 329 | 436, 839 | 355, 457, 657 | 893. The third pass would give the fully sorted array.

More Algorithms questions

Exams that ask this topic