Shell Sort Visualizer (Step-by-Step)
Animate Shell sort with shrinking gaps and see each gapped insertion move.
Start with gap n/2 (Shell’s original sequence).
Step-by-step working
- Start with gap = ⌊n/2⌋ and gapped insertion sort.
- Halve the gap until it is 1 (final pass is plain insertion sort).
- Press Play or Step to watch every move.
Mathematical Formula
Overview & Explanation
Shell sort generalises insertion sort by first moving elements far apart, so the final pass has little work.
How It Works
- Pick a gap.
- Insertion-sort each gap-separated subsequence.
- Halve the gap until 1.
Practical Applications
- Understanding gap sequences.
- Embedded systems with small arrays.
Example 1: 23, 12, 1, 8, 34, 54, 2, 3
Eight elements.
Inputs
Array to sort (comma separated, max 40): 23, 12, 1, 8, 34, 54, 2, 3
Step 1
Start with gap = ⌊n/2⌋ and gapped insertion sort.
Step 2
Halve the gap until it is 1 (final pass is plain insertion sort).
Step 3
Press Play or Step to watch every move.
Sorted
Result
Example 2: reverse order
Worst-ish input.
Inputs
Array to sort (comma separated, max 40): 9, 8, 7, 6, 5, 4, 3, 2, 1
Step 1
Start with gap = ⌊n/2⌋ and gapped insertion sort.
Step 2
Halve the gap until it is 1 (final pass is plain insertion sort).
Step 3
Press Play or Step to watch every move.
Sorted
Result
How it's calculated & sources
Gaps n/2, n/4, …, 1 (Shell, 1959). For each gap, perform insertion sort on elements gap apart. Worst case O(n²) for this sequence.
Frequently Asked Questions
Which gap sequence is best?
Is it stable?
Why faster than insertion sort?
Related Calculators
Insertion Sort Visualizer & Step Generator
Interactive Insertion Sort step generator showing array shifts and key element insertion.
Heap Sort Visualizer (Step-by-Step)
Watch heap sort build a max-heap and extract elements, with animated bars and every swap explained.
Merge Sort Visualizer
Interactive divide and conquer Merge Sort step generator showing array splitting and merging.
Bubble Sort Visualizer & Step Calculator
Interactive step-by-step Bubble Sort execution visualizer with comparisons, swaps, and time complexity breakdown.