[Algorithm-Sort 4] Hill sort

Source: Internet
Author: User

Algorithm-sort by hill
HillThe name of sorting is its designer, Donald Shell. The design embodies the idea of "division and control" in the computer field. Among the many sorting algorithms, Hill sorting is the only algorithm that can rank quickly and efficiently ([algorithm-Sort 2] FAST, at present, only these two sorting algorithms break through the time complexity of O (n2 ). It is worth mentioning that both Hill sorting and quick sorting are based on the "Division control method". Here, we may be able to explain that these two sorting algorithms are superior in efficiency. 1. ShellSort () Core: first, the ShellSort () sequence is divided into multiple sub-sequences for sorting, and then into fewer sub-sequences for sorting, until the last is a sequence for sorting.Image Description: for example, the system first sorts eight sub-orders, then four sub-orders, then two sub-orders, and the last one (one is all sequences ).Implementation Method of hill sorting:1.1 how to draw a molecular sequence: Hill sorting selects a number at a fixed distance to draw the molecular sequence. The interval distance is called increment.Through the illustration, the concept of increment is easy to understand. Increment means that the number of distances is the same suborder. In this way, if the incremental value is N, it can be divided into N suborders. After each sub-order is sorted, the increment is halved. The increment reduction means that the sub-order number is reduced. Knowing that the increment is 1, it is the full number order, and the hill sorting is completed.1.2 How to sort sub-orders:In the process of describing 1, the suborder is sorted separately after the molecular order, so what sort method is adopted? The suborder sorting method of hill sort is insert sort ([algorithm-Sort 3] Insert sort ).Algorithm Implementation:
The code of the hill sort is not complex, and the end of the entire sort is controlled by whether the increment is 1. When the increment is d, traverse the sub-orders of d at this time, from k = 0 to k = D-1. Then insert and sort each sub-order.
2. algorithm complexity:The complexity analysis of the hill sort algorithm can be compared with that of the fast sort ([algorithm-Sort 2] Quick Sort). Generally, the complexity of the hill sort time is considered as: O (nlogn ).3. space complexity:The spatial complexity of hill sorting is obviously O (1), and only one switching variable is required. Compared with the huge stack consumption produced by fast sorting and recursive calling, the space consumption of hill sorting O (1) is very surprising.

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.