Shellsort is one of the more unusual sorting
algorithms. The basic idea is to insert new elements into a sorted
sequence, much like with Insertion Sort.
The reason for the high complexity of Insertion Sort is
that elements are only moved by one position. Shellsort tries
to sort the elements quicker by moving the elements in larger
steps. To do this the elements are h-sorted, i.e. the input
sequence is sorted in h partial sequences consistent of all
elements which have the distance of h to each other, e.g. for
h=4 the sequences are 0, 4, 8; 1, 5, 9; 2, 6, 10 and
3,7,11.
These sequences are now sorted separately using Insertion
Sort.
If the index sequence of h is chosen correctly (i.e. especially at
the end the elements need to be h=1 sorted) the complete
sequence will be sorted.
The calculation of the complexity of Shellsort is very
complicated and is dependent on the index sequence of h.
The "pre-sorting" into h-sorted sequences only
brings a benefit if there are at least 18 elements, so that is not
seen in the animation.