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.
| Input | 34 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
| Pass | Digit | Buckets (non-empty) | Result |
|---|---|---|---|
| 1 | units | 1: 21,121 | 2: 342 | 3: 3 | 4: 34,44 | 5: 65 | 21, 121, 342, 3, 34, 44, 65 |
| 2 | tens | 0: 3 | 2: 21,121 | 3: 34 | 4: 342,44 | 6: 65 | 3, 21, 121, 34, 342, 44, 65 |
| 3 | hundreds | 0: 3,21,34,44,65 | 1: 121 | 3: 342 | 3, 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