"Dahua Data Structure" 9th Chapter 9.6 Hill Sort (ON) _ Dahua data structure

Source: Internet
Author: User
9.6.1 change impossible for possible

Give us an intellectual problem. What is "VII", please?
Well, well, it's 7 of the Roman numerals. Now we're going to add a pen to it and make it 8 (VIII), it should be very simple, just add a vertical line to the right.
Now I ask you to try to add a sum to the Roman numeral 9, or "IX", and turn it into 6.
(after a few minutes)
I've heard a lot of voices say, "How could this be." "But why do we have to use conventional methods?"
I have three different ways to achieve it.
Method One: observed that "X" can actually be seen as an inverted two "V". So we add a horizontal line to the middle of "IX", upside down, and then cover the lower part, that is to say, we add a pen to cover part, so we get "VI".

Method Two: Add an "S" in front of "IX", at this time constitute an English word "SIX", this is equal to get a 6. Haha, I heard the following uproar, I just did not say that must be "VI" ah, I just said to turn it into 6 just, as for Roman numerals or English words, I can have no restrictions. Obviously, your mind has been affected by the transition from "VII" to "VIII", as the example above.

Method Three: After "IX" Add a "6", get "1X6", the result of course is the number 6. Everyone smiled, because the idea was too much, the letter "I" as a number 1, the letter "X" as a multiplication. But who rules that this is not possible? As long as you do not violate the rules, get 6.

The answer to the puzzle is finished. You will find that seemingly not solve the problem, there is really not necessarily no way, perhaps just temporarily did not think of it.
We all understand that the first condition of a good sorting algorithm is speed (there are other requirements, the speed is the first). So people think a lot of ways, the purpose is to improve the speed of sorting. For a long time, they found that despite the variety of sorting algorithms (such as the three different sorting algorithms we mentioned earlier), the time complexity was all O (N2), and it seemed impossible to go beyond it (sort in here). At this point, the computer academia is flooded with "sorting algorithm can not break through O (n2)" sound. Just like the feeling of people doing puzzles, "impossible" has become the mainstream.
Finally, one day, when a scientist released a new sort algorithm beyond O (N2), there were several sort algorithms that could go beyond O (N2), and the time complexity of the internal sorting algorithm was raised to O (nlog2n). "Impossible Beyond O (N2)" has become a complete history.
Tell us from here, too. To do anything, you can not solve, think of "Nothing is impossible!", although a bit idealistic, but this way of thinking will allow you to think more deeply about the solution, rather than hastily give up.


9.6.2 Hill Sorting principle
Now, I'm going to explain the algorithm called Hill sort (Shell sort). Hill sort is a sort algorithm D.l.shell in 1959, in which the time complexity of the sorting algorithm is basically O (N2), and the Hill sorting algorithm is one of the first algorithms to break through this time complexity.
The direct insertion sort in the previous section, it should be said, its efficiency at some times is very high, for example, our record itself is basically orderly, we only need a small amount of insert operation, we can complete the entire recordset sorting work, at this time the direct insertion is very efficient. There is a relatively few records, the advantages of direct insertion is also more obvious. The problem is that the two conditions themselves are too harsh, and the fact that fewer records are in reality or that basic order is a special case.
But don't worry, there are conditions of course is good, conditions do not exist, we create conditions, is also able to do. So scientist Hill has developed a sort of method for increasing efficiency after the direct insertion of a sort.
How to make the number of records to be sorted less. It's easy to think of grouping records that have a large number of records. Split into several subcategories, where each subsequence has fewer records to sort. Then in these subsequence direct insertion of the sequence, when the whole sequence is basically orderly, the attention is only basic order, then the whole record for a direct insertion of the order.
At this point some students must begin to wonder. This is wrong, for example, we now have a sequence is {9,1,5,8,3,7,4,6,2}, now divided it into three groups, {9,1,5},{8,3,7},{4,6,2}, even if they are sorted out, into {1,5,9},{3,7,8},{2,4,6}, And then merge them into {1,5,9,3,7,8,2,4,6}, at this time, this sequence or disorderly, not basic order, to sort or start again directly inserted in order, so useful. Need to emphasize that the so-called basic order, is the small keyword basic in the front, large basic in the back, a little bit of the basic in the middle, like {2,1,3,6,4,7,5,8,9} This can be called the basic order. But like {1,5,9,3,7,8,2,4,6} such 9 in third place, 2 in the last third place is far from the basic order.
The problem is actually here, we split the record to be sorted to reduce the number of records to be sorted, and the entire sequence to the basic orderly development. And such as the above after the group, on their own sorting methods can not achieve our requirements. Therefore, we need to take a jump-split strategy: A sequence of "increments" is formed to make sure that the result of the direct insertion sequence within the subsequence is basically orderly rather than local order.

Source: http://www.cnblogs.com/cj723/archive/2011/04/19/2021613.html

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.