- 2075 Baisakh · 4 marks
Shell sort on 92, 83, 22, 49, ...
Short answer
With gaps 5,2,1. Gap 5 sorts pairs at distance 5, producing 92 12 9 49 36 98 83 22 70 51. Gap 2 sorts even-indexed and odd-indexed sub-lists, giving 9 12 36 22 70 49 83 51 92 98. Gap 1 insertion sort completes sort: 9, 12, 22, 36, 49, 51, 70, 83, 92, 98.
Sort the numbers 92, 83, 22, 49, 36, 98, 12, 9, 70 and 51 using shell sort.
Use Shell's gap sequence n/2, n/4, ..., 1. With n = 10 the gaps are 5, 2, 1.
Original list: 92 83 22 49 36 98 12 9 70 51 (positions 0 to 9)
Pass 1: gap = 5 (compare a[i] and a[i+5])
| Pair (positions) | Values | Action |
|---|---|---|
| 0, 5 | 92, 98 | in order |
| 1, 6 | 83, 12 | swap |
| 2, 7 | 22, 9 | swap |
| 3, 8 | 49, 70 | in order |
| 4, 9 | 36, 51 | in order |
Result: 92 12 9 49 36 98 83 22 70 51
Pass 2: gap = 2 (two sub-lists)
- Even positions: 92, 9, 36, 83, 70 → sorted: 9, 36, 70, 83, 92
- Odd positions: 12, 49, 98, 22, 51 → sorted: 12, 22, 49, 51, 98
Putting them back in position order: 9 12 36 22 70 49 83 51 92 98
Pass 3: gap = 1 (insertion sort)
| Insert | List after |
|---|---|
| 12 | 9 12 36 22 70 49 83 51 92 98 |
| 36 | 9 12 36 22 70 49 83 51 92 98 |
| 22 | 9 12 22 36 70 49 83 51 92 98 |
| 70 | 9 12 22 36 70 49 83 51 92 98 |
| 49 | 9 12 22 36 49 70 83 51 92 98 |
| 83 | 9 12 22 36 49 70 83 51 92 98 |
| 51 | 9 12 22 36 49 51 70 83 92 98 |
| 92 | 9 12 22 36 49 51 70 83 92 98 (no change) |
| 98 | 9 12 22 36 49 51 70 83 92 98 (no change) |
Sorted list: 9, 12, 22, 36, 49, 51, 70, 83, 92, 98
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Heap sort on 37, 33, 26, 92, ... · Data Structure and Algorithm, chapter 7
- Radix sort on 32, 45, 60, 83, ... · Data Structure and Algorithm, chapter 7
- Merge sort on 85, 76, 46, 92, ... · Data Structure and Algorithm, chapter 7
- Explain shell sort · Data Structure and Algorithm, chapter 7
- B-tree of order 5 for 82, 12, 22, ... · Data Structure and Algorithm, chapter 6 · asked 2×
- Radix sort on 25, 57, 48, 37, ... · Data Structure and Algorithm, chapter 7
- Conductor selection, 100 MW 70 km 132 kV · Transmission and Distribution System Design, chapter 4
- Chi-square test on 100 random numbers · Simulation and Modeling, chapter 6
- Chi-square uniformity test, 40 numbers · Simulation and Modeling, chapter 6
- Line spectra of 12 + 6sin(140πt+30°) - 9cos(80πt-70°) · Data Communication, chapter 3