"Introduction to Algorithms" chapter sixth, heap sequencing

Source: Internet
Author: User

Basic process:

1, to maintain the nature of the maximum heap: Assuming that two sub-heap are satisfied, only the root node in turn, the complexity of O (LG N)

2, initialize the heap: The second half of the leaves, in the first half from the back forward, in turn, perform the above-mentioned maximum heap properties of operations, the nominal complexity is O (n lg N), but there is more accurate calculation,

A node with a height of H is O (h), so N\sigma (H/2^h), whose complexity is O (n). (Thought is high-level complexity, exponential attenuation, and complexity growth is the LG level, so it was dominate off)

Heap sorting algorithm: first build the largest heap, each time the top position and the appropriate position interchange, and then execute the process 1, a total of n times, the complexity of O (n lg N)

Priority queue: One way to manage collections

Action: Insert (x, s), Max (s), Extract_max (s), increase (x, K, s)-Increase the value of X to K,

1. Max is obviously ... You can take the first element

2, Extract_max the same as before, O (LG N),

3. Insert operation: Add at last, then move up 1.1 points.

Heap sort code: not yet adjourned

"Introduction to Algorithms" chapter sixth, heap sequencing

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.