Introduction to Python algorithm: Hill sort


As a new language, Python is naturally better than Java in many functions, and it is also easy to accept. No matter you are an adult or a child, you can learn this language. Today, I’ll share the hill sorting of a python algorithm tutorial for you. Let’s take a look at it now!

Hill sorting algorithm idea: group the array to be sorted according to step gap, and then use the method of direct insertion sorting to sort the elements of each group; reduce gap by half every time, and cycle the above operations; when gap = 1, use direct insertion to complete sorting.

The same: from the above description, we can see that the overall implementation of hill sorting should be completed by three cycles:

First layer loop: divide gap into half and group the sequence until gap = 1

The second and third level loops: that is, the two loops needed to directly insert sorting. See above for details.



So how is the code implemented?