Visualize full Shell Sort passes
Here is the COMPLETE VISUALIZATION OF ENTIRE SHELL SORT
COMPLETE VISUALIZATION OF ENTIRE SHELL SORT
Here is the COMPLETE VISUALIZATION OF ENTIRE SHELL SORT
with your array:
45, 12, 78, 23, 56, 9, 67, 34, 89, 41
We use gap sequence: 5 → 2 → 1
FULL STEP-BY-STEP GRAPHICAL REPRESENTATION
Original Array
Index: 0 1 2 3 4 5 6 7 8 9
Value: 45 12 78 23 56 9 67 34 89 41
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│45 │12 │78 │23 │56 │ 9 │67 │34 │89 │41 │
└─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┘
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
Gap=5 groups → 0-5, 1-6, 2-7, 3-8, 4-9
PASS 1: GAP = 5
Groups being sorted (like mini insertion sort):
[45 ↔ 9] → 9 < 45 → swap
[12 ↔ 67] → already good
[78 ↔ 34] → 34 < 78 → swap
[23 ↔ 89] → already good
[56 ↔ 41] → 41 < 56 → swap
After Gap=5:
9 12 34 23 41 45 67 78 89 56
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ 9 │12 │34 │23 │41 │45 │67 │78 │89 │56 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
PASS 2: GAP = 2
Now two long chains:
Chain 1 (even indices): 9, 34, 41, 67, 89 → already sorted ✓
Chain 2 (odd indices): 12, 23, 45, 78, 56
Focus on Chain 2:
12 → 23 → 45 → 78 → 56 ← 56 is out of order!
Insert 56 into correct position:
56 goes between 45 and 78 → shift 78 right
After Gap=2:
9 12 34 23 41 45 67 56 89 78
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ 9 │12 │34 │23 │41 │45 │67 │56 │89 │78 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
PASS 3: GAP = 1 (Final Insertion Sort)
Now normal insertion sort on nearly-sorted array:
9 12 34 23 41 45 67 56 89 78
↑ ↑ ↑ ↑───────────────────────────→ sorted prefix grows
Step-by-step insertions:
1. Insert 23 → shifts 34 → becomes: 9 12 23 34 41 45 67 56 89 78
2. 41, 45, 67 → already in place
3. Insert 56 → shifts 67 → becomes: 9 12 23 34 41 45 56 67 89 78
4. 89 → already good
5. Insert 78 → shifts 89 → becomes: 9 12 23 34 41 45 56 67 78 89
FINAL SORTED ARRAY
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ 9 │12 │23 │34 │41 │45 │56 │67 │78 │89 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
COMPLETE VISUAL SUMMARY (All Passes)
Pass Gap Array After Pass
────────────────────────────────────────────────────
0 Start 45 12 78 23 56 9 67 34 89 41
1 5 9 12 34 23 41 45 67 78 89 56
2 2 9 12 34 23 41 45 67 56 89 78
3 1 9 12 23 34 41 45 56 67 78 89 ← FINAL
Bar Graph Evolution (Draw this in exam!)
Initial: After Gap 5: After Gap 2: Final (Gap 1):
89 89 89
78 78 78 78 78
67 67 67 67 67
56 56 56 56 56
45 45 45 45 45
41 41 41 41
34 34 34 34
23 23 23 23
12 12 12
9 9 9
──────────────────────────────────────────────────────────────→
Original Nearly grouped Almost sorted Fully sorted
Key Point: Only 3 major shifts happened in final pass because earlier gaps already moved elements close to their correct positions!
You can now draw this entire visualization on your answer sheet and impress your professor!
Want this as a printable image/PDF? Just say the word!
Visualize full Shell Sort passes
Here is the COMPLETE VISUALIZATION OF ENTIRE SHELL SORT
COMPLETE VISUALIZATION OF ENTIRE SHELL SORT
Here is the COMPLETE VISUALIZATION OF ENTIRE SHELL SORT
with your array:
45, 12, 78, 23, 56, 9, 67, 34, 89, 41
We use gap sequence: 5 → 2 → 1
FULL STEP-BY-STEP GRAPHICAL REPRESENTATION
Original Array
Index: 0 1 2 3 4 5 6 7 8 9
Value: 45 12 78 23 56 9 67 34 89 41
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│45 │12 │78 │23 │56 │ 9 │67 │34 │89 │41 │
└─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┘
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
Gap=5 groups → 0-5, 1-6, 2-7, 3-8, 4-9
PASS 1: GAP = 5
Groups being sorted (like mini insertion sort):
[45 ↔ 9] → 9 < 45 → swap
[12 ↔ 67] → already good
[78 ↔ 34] → 34 < 78 → swap
[23 ↔ 89] → already good
[56 ↔ 41] → 41 < 56 → swap
After Gap=5:
9 12 34 23 41 45 67 78 89 56
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ 9 │12 │34 │23 │41 │45 │67 │78 │89 │56 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
PASS 2: GAP = 2
Now two long chains:
Chain 1 (even indices): 9, 34, 41, 67, 89 → already sorted ✓
Chain 2 (odd indices): 12, 23, 45, 78, 56
Focus on Chain 2:
12 → 23 → 45 → 78 → 56 ← 56 is out of order!
Insert 56 into correct position:
56 goes between 45 and 78 → shift 78 right
After Gap=2:
9 12 34 23 41 45 67 56 89 78
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ 9 │12 │34 │23 │41 │45 │67 │56 │89 │78 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
PASS 3: GAP = 1 (Final Insertion Sort)
Now normal insertion sort on nearly-sorted array:
9 12 34 23 41 45 67 56 89 78
↑ ↑ ↑ ↑───────────────────────────→ sorted prefix grows
Step-by-step insertions:
1. Insert 23 → shifts 34 → becomes: 9 12 23 34 41 45 67 56 89 78
2. 41, 45, 67 → already in place
3. Insert 56 → shifts 67 → becomes: 9 12 23 34 41 45 56 67 89 78
4. 89 → already good
5. Insert 78 → shifts 89 → becomes: 9 12 23 34 41 45 56 67 78 89
FINAL SORTED ARRAY
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ 9 │12 │23 │34 │41 │45 │56 │67 │78 │89 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
COMPLETE VISUAL SUMMARY (All Passes)
Pass Gap Array After Pass
────────────────────────────────────────────────────
0 Start 45 12 78 23 56 9 67 34 89 41
1 5 9 12 34 23 41 45 67 78 89 56
2 2 9 12 34 23 41 45 67 56 89 78
3 1 9 12 23 34 41 45 56 67 78 89 ← FINAL
Bar Graph Evolution (Draw this in exam!)
Initial: After Gap 5: After Gap 2: Final (Gap 1):
89 89 89
78 78 78 78 78
67 67 67 67 67
56 56 56 56 56
45 45 45 45 45
41 41 41 41
34 34 34 34
23 23 23 23
12 12 12
9 9 9
──────────────────────────────────────────────────────────────→
Original Nearly grouped Almost sorted Fully sorted
Key Point: Only 3 major shifts happened in final pass because earlier gaps already moved elements close to their correct positions!
You can now draw this entire visualization on your answer sheet and impress your professor!
Want this as a printable image/PDF? Just say the word!