- 2071 Magh · 8 marks
Merge and radix sort on 142, 523, ...
Short answer
Merge sort: recursive division, then merge steps produce 123,142,144,198,228,249,375,462,523. Radix sort: 3 passes: after units: 142,462,523,123,144,375,228,198,249; after tens: 523,123,228,142,144,249,462,375,198; after hundreds (leading zeros for 2-digit numbers): 123,142,144,198,228,249,375,462,523.
Trace the sorting steps in merge sort and radix sort for sorting the data 142, 523, 228, 375, 462, 198, 249, 144, 123 in ascending order.
Merge sort on 142, 523, 228, 375, 462, 198, 249, 144, 123
Split (left half gets the extra element):
142 523 228 375 462 | 198 249 144 123
142 523 228 | 375 462 | 198 249 | 144 123
142 523 | 228 | 375 | 462 | 198 | 249 | 144 | 123
142 | 523
Merge:
| Step | Merge | Result |
|---|---|---|
| 1 | [142] + [523] | [142, 523] |
| 2 | [142, 523] + [228] | [142, 228, 523] |
| 3 | [375] + [462] | [375, 462] |
| 4 | [142, 228, 523] + [375, 462] | [142, 228, 375, 462, 523] |
| 5 | [198] + [249] | [198, 249] |
| 6 | [144] + [123] | [123, 144] |
| 7 | [198, 249] + [123, 144] | [123, 144, 198, 249] |
| 8 | [142, 228, 375, 462, 523] + [123, 144, 198, 249] | [123, 142, 144, 198, 228, 249, 375, 462, 523] |
Radix sort on the same data (3 digits, so 3 passes)
Pass 1 (units digit)
| Queue | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| Keys | 142, 462 | 523, 123 | 144 | 375 | 228, 198 | 249 |
List: 142, 462, 523, 123, 144, 375, 228, 198, 249
Pass 2 (tens digit)
| Queue | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| Keys | 523, 123, 228 | 142, 144, 249 | 462 | 375 | 198 |
List: 523, 123, 228, 142, 144, 249, 462, 375, 198
Pass 3 (hundreds digit)
| Queue | 0 | 1 | 2 | 3 | 4 | 5 | 6-9 |
|---|---|---|---|---|---|---|---|
| Keys | 123, 142, 144, 198 | 228, 249 | 375 | 462 | 523 |
Answer: 123, 142, 144, 198, 228, 249, 375, 462, 523
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Merge sort algorithm and trace · Data Structure and Algorithm, chapter 7
- Merge sort on 47, 27, 56, 23, ... · Data Structure and Algorithm, chapter 7
- Radix sort on 25, 57, 48, 37, ... · Data Structure and Algorithm, chapter 7
- Merge sort on 85, 76, 46, 92, ... · Data Structure and Algorithm, chapter 7
- Radix sort on 345, 654, 924, ... · Data Structure and Algorithm, chapter 7
- Radix sort definition and algorithm · Data Structure and Algorithm, chapter 7
- Sort array ascending in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Sort employee structures by salary · Computer Programming, chapter 8 · asked 2×
- Employee text file; sort into binary file · Computer Programming, chapter 10
- Conductor selection, 100 MW 70 km 132 kV · Transmission and Distribution System Design, chapter 4