Skip to content
Azhimathi Mayam logoDSA Study HubPCCST303 · KTU · S3
B.Tech S3 (R) (FT/WP) Examination November 2025 (2024 Scheme)QP 06PCCST303112503Part A · Q73 marksCO4Module 4asked in 2 papers

Question 7

Perform radix sort to sort the numbers 34, 21, 3, 121, 342, 65 and 44

Topics: Radix sort

Watch this exact question run

Loading visualizer…

Solution

Assumptions:
  • LSD radix sort, base 10, buckets 0–9 used as FIFO queues (the standard KTU/Horowitz presentation).

The largest key is 342, which has 3 digits, so we need 3 passes: units, tens, hundreds. In each pass, keys are dropped into buckets in their current order and collected from bucket 0 to 9.

Array after each pass (generated by the radix-sort engine)checked by code
Input34 21 3 121 342 65 44
After pass 1 (units)21 121 342 3 34 44 65
After pass 2 (tens)3 21 121 34 342 44 65
After pass 3 (hundreds)3 21 34 44 65 121 342

Totals: passes = 3

Pro tipWhy order inside a bucket matters

In pass 2, bucket 2 holds 21 then 121 — the order from pass 1. Keeping that order (stability) is what makes the final pass correct.

How to write it in the exam

PassDigitBuckets (non-empty)Result
1units1: 21,121 | 2: 342 | 3: 3 | 4: 34,44 | 5: 6521, 121, 342, 3, 34, 44, 65
2tens0: 3 | 2: 21,121 | 3: 34 | 4: 342,44 | 6: 653, 21, 121, 34, 342, 44, 65
3hundreds0: 3,21,34,44,65 | 1: 121 | 3: 3423, 21, 34, 44, 65, 121, 342

Sorted list: 3, 21, 34, 44, 65, 121, 342.

How this answer was verified
  • Hand trace
  • tests/pyq-sorting.test.ts (engine checkpoints)
  • content/c/radix_sort.c output compared by scripts/verify-c.ts

Similar questions