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