Shell Sort
Run insertion sort over shrinking gaps so distant inversions disappear before the final adjacent pass.
Core idea
Apply insertion sort to elements separated by a large gap, then shrink the gap. Early passes move badly misplaced values long distances before the final gap-one cleanup.
Read the visualization
Dimmed bars are outside the current gap group. Within the active group, the key, comparisons, shifts, and insertion follow ordinary Insertion Sort at gap-sized distances.
Reduce the gap and form a new set of interleaved subsequences.
Complexity and tradeoffs
Time: Gap-dependent; common worst O(n^2). Space: O(1). In-place and often faster than insertion sort on medium arrays, but not stable.
Where it fits
Shell Sort is compact, in-place, and practical for moderate arrays when a library sort is unavailable. Its performance depends strongly on the gap sequence and it is not stable.