I understand that we are constructing a max-heap using the same array (which we have to sort) so there is no extra memory required there (from here).
But my question is what about heapify function (which is recursive when I follow Introduction to Algorithms, CLRS) which we use while building the heap (and also during swapping the first element of heap - that is the biggest and the last element of the heap and then again re-heapifying the array).
The call to this recursive function can, in worst case take O(log(n))
because of storing the stack pointer on each recursive call.
So, my question is that when this wiki article says that heapsort is an inplace sorting algorithm, does it implicitly mean that the heapify function that it is assuming is non-recursive one (which will not take any (non-constant) extra space). Or is there something that I'm missing?
Will the space complexity of heapsort, which uses a recursive heapify function, be O(log(n))
?