Sorting of h
parts in distance of the elements of h
. Merging the parts for descending order of h
values with insertion sort. This means the elements gets moved over a greater distance. Typical:
int h = 1;
while (h <= array.count()) {
h = 3*h+1;
}
while (h > 0) {
h = h / 3;
for (int i = (h-1); i < array.count(); ++i) {
int j = i;
while ((j > h-1) && (array[j] < array[j-h-1])) {
array.swap( j-h-1, j );
j = j - h - 1;
}
}
}
Asymptotic complexity depends on h
:
For :
For :
For :
For :