The basic idea of Hill sorting:
Hill sorting is an improvement based on insertion sorting. Since insertion sorting is efficient when operating on arranged arrays, insertion sorting is generally inefficient because it can only be moved at a time. One person. So Hill sort sorts by grouping first until the grouping increment is 1.
Example:
arr = [49,38,04,97,76,13,27,49,55,65], when the grouping increment is 5, the red numbers are in one group, insertion sorting is performed, and the loop is traversed in sequence
arr = [13,38,04,97,76,49,27,49,55,65], after the traversal is completed, the grouping increment decreases,
arr = [13,27,04,55,65 ,49,38,49,97,76], and then continue to perform insertion sorting on the group with a grouping increment of 2 until the grouping increment is 1
Code:
Python code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|