Shellsort

Shellsort is a sorting algorithm that improves upon insertion sort. Shellsort uses a number of passes of h-sorting which has the property that, for some value of h, every element on the h-interval is in sorted order, no matter where you start counting. The choice for values of h is an ongoing research problem; Knuth recommends the sequence $$(3^n-1)/2$$ (whose first few terms are 1 4 13 40...). It can be generated by $$a_{n+1}=3a_n+1$$. Donald Shell, the inventor of the algorithm, originally used the powers of two (1 2 4 8 16 32..) but this was found to be quite slow because (among other reasons) no even-indexed item will be swapped with an odd-indexed item until the final pass where h = 1.