Below is the Pseudo Code of HEAPSORT on an array
HEAPSORT(A)
BUILD-MAX-HEAP(A)
for i = A.length downto 2
exchange A[1] with A[i]
A.heapsize = A.heapsize - 1
MAX-HEAPIFY(A,1)
It is clear to me that BUILD-MAX-HEAP has a complexity of O(n) and MAX-HEAPIFY has a complexity of O(h) where h is the height of the heap which has a max value of logn.
What I don't understand completely is why does HeapSort have a complexity of nlogn. I understand we have n iterations with each a MAX-HEAPIFY. But he MAX-HEAPIFY call gets a HEAP of diminishing size in each iteration. How can then each iteration have a complexity of O(lgn)? Is it tightly bound? Any where I can see the mathematical proof of the same?