SortingAnimated
Shell Sort
Insertion sort over shrinking gaps.
Time
About O(n^1.3) in practice
Extra space
O(1)
Use it for
Medium arrays, simple code, no recursion.
How it works
- Insertion sort is slow because it moves items one step at a time. Shell sort first sorts items that are far apart.
- Pick a gap (start at n/2). Do an insertion sort on every gap-th element.
- Halve the gap and repeat.
- When the gap is 1 it is a normal insertion sort, but the list is already nearly sorted, so it finishes fast.
Watch it run
Loading animation…