6.4-5 the time complexity of Heapsort is Ω (NLGN) in the case that all elements are different
Proof: It is not difficult to prove this, just intuitively understand-although the heap sequence is not "complete", but also to some extent to determine the size of the relationship, such as the smaller elements are mostly very low (near the bottom).
Start with a rough calculation (the elements are different):
The number of nodes in the heap with a height of 0 (that is, the lowest) is half N/2 of the total. What is the size position of these elements in the entire element set:
First put this N/2 node in order, get the increment sequence (consider the maximum heap here), and then consider the size position in the whole element set.
One of the largest in the entire heap can only be ranked LGN large, because it has lgn ancestors, the smallest in the entire heap is necessarily the smallest, because the minimum height can only be 0.
The above sentence is not really important, it is important that the N/2 elements in the entire element set the approximate distribution.
The above 2k + 1 elements in the entire element set of the largest can only be ranked LGN + 2k + 1 large, because the element separated by 2 must have a different ancestor, and this ancestor must exist in front of the smaller element.
So a distribution is constructed by greed:
Because the internal node also has N/2, so the unassigned ancestors have N/4, so the lowest element size position in the N/2 after the large element has N/6, consider the N/2 after the big because, after the N/2 times the minimum value, these rows will remain in the heap.
The sum of all the nodes ' depths (the path from the lowest to the bottom of the N/6) is N/6LG (N/6), which is a two-fork heap of these elements.
So for the whole heap, the depth of these nodes must not be less than N/6LG (N/6), because the result of the latter is the geometric reduction, add out is similar, not forget.
You might think that if a node falls to the bottom, then some of the lowest-level nodes do not fall from the root node, which makes the proofs not tenable.
It's not, because if that happens, just think of the depth of the node that's not being pulled into LGN (which is bigger than the estimate), because this is the case where the other element is the equivalent of "replace" it down.
So the time complexity of Heapsort is Ω (NLGN).
6th Chapter Heap Sorting