Hill sort and merge sorted by __ Merge sort

Source: Internet
Author: User

This is a sort of gap algorithm that needs to be counted
Hill sort of gap is getting smaller
And the merged sort of gap is getting bigger

Example: If there are 11 numbers
The order of Hill sort is
Gap=11/2=5 (0, 5, 10) (1, 6) (2, 7) (3, 8) (4, 9)
gap=5/2=2 (0, 2, 4, 6, 8, 10) (1, 3, 5, 7, 9)
Gap=2/2=1 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

The order of the merge sort is
gap=2 (0, 1) (2, 3) (4, 5) (6, 7) (8, 9) (10)
gap=2*2 = 4 (0, 1, 2, 3) (4, 5, 6, 7) (8, 9, 10)
Gap=4*2=8 (0, 1, 2, 3, 4, 5, 6, 7) (8, 9, 10)
Gap=8*2=16>n (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

Hill sort is a kind of insert sort method, the time complexity is the most quickly o (n), the slowest is O (n^2), each small interval is inserted sort of way, do not need to request additional auxiliary space O (1).

Merge sort is the merge sort, the time complexity is O (NLOGN) level, each time to apply for a gap length of the auxiliary space used to merge 2, so the space complexity of O (n).

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.