Hill sort (shell) theory---does not contain source code

Source: Internet
Author: User

Copyright Notice: This article for Bo Master original article, without Bo Master permission not reproduced.

Hill sort, is a narrowing incremental sort. It is sorted according to the step size, different steps may produce different sequences, but their final result is the same, the official theory of hill sort is difficult to understand, this is explained by unofficial explanation.

Principle:

>1. Adding a sequence of n nodes, assuming the step I of the hill sort, then our first step is to set the N nodes, every I-seat, as a group, as shown below (step I to take good):

[N1, N1+i]

[N2, Ni+2]

[...........]

[NX, NN]

>2. Then each group of 22 comparisons, such as N1 and N1+i comparisons, select the appropriate (appropriate refers to the sort of ascending and descending relationship) data in front. If N1+i < N1, and in ascending order, then the first set of sorted sequence is [N1+i, N1], and so on, and so on, make up the order of the X group. Suppose the following is a well-ordered sequence.

[N1+i, N1]

[N2, Ni+2]

[N3, Ni+3]

[Ni+4, N4]

[...........]

[NX, NN]

>3. Finally, the vertical sequence will be followed by all the nodes, which is the result of the first trip of the hill sort, according to >2. The result is: N1+i, N2, N3, Ni+4, ...., NX, N1, ni+2, ni+3, N4, .... Nn

>4. Then the step I minus 1, repeat the above operation until i=0, end.

Example: Take the (5,6,1,8,4,9) sequence as an example to demonstrate the results of the first trip sort

Hill sort (shell) theory---does not contain source code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.