Shellsort

Shellsort
Shellsort with gaps 23, 10, 4, 1 in action
ClassSorting algorithm
Data structureArray
Worst-case performanceO(n2) (worst known worst case gap sequence)
O(n log2n) (best known worst case gap sequence)
Best-case performanceO(n log n) (most gap sequences)
O(n log2n) (best known worst-case gap sequence)
Average performancedepends on gap sequence
Worst-case space complexityО(n) total, O(1) auxiliary
OptimalNo

Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort. It can be understood as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. By starting with far-apart elements, it can move some out-of-place elements into the position faster than a simple nearest-neighbor exchange. The running time of Shellsort is heavily dependent on the gap sequence it uses. For many practical variants, determining their time complexity remains an open problem.

The algorithm was first published by Donald Shell in 1959, and has nothing to do with shells.