The hill sort was proposed by D.l.shell in 1959, and the relative direct ranking has been greatly improved. Hill sort is also called narrowing the incremental sort
Basic idea:
First, the entire sequence of records to be sorted into a number of sub-sequences of the direct insertion of the order, the entire series of records in the "Basic order", then the whole record is inserted in order.
Operation Method:
- Select an incremental sequence T1,T2,...,TK, where ti>tj,tk=1;
- According to the number of increment series K, the sequence is sorted by K-trip;
- Each order, according to the corresponding increment ti, the backlog sequence is divided into several sub-sequences of length m, respectively, the sub-table is directly inserted sort. Only the increment factor is 1 o'clock, the entire sequence is treated as a table, and the length of the table is the length of the entire sequence.
Algorithm implementation:
We simply handle the increment sequence: Delta sequence d = {N/2, N/4, N/8 ..... 1} n is the number of digits to be sorted
That is: A set of records to be sorted by an increment D(the number of n/2,n to be sorted) into several sets of sub-sequences, each group of recorded subscript difference D. direct insertion of all elements in each group, It is then grouped with a smaller increment (d/2), followed by a direct insert sort in each group. Continue to shrink the increment until it is 1, and finally use the direct insert sort to complete the sorting.
Eight sorting algorithms of the two-hill sort (Shell's sort)