I am studying the heap sort algorithm from the book Introduction to Algorithms by Thomas H. Corman. It differentiates between the length of the array, A.length, as
"the number of elements in the array"
, and A.heapsize, as
"represents how many elements in the heap are stored within array
A"
I am trying to visualize a case when A.heapsize will not be equal to A.length.
- When does an element of a heap not reside in the array?
- Is there a practical scenario where
A.heapsize < A.length?
A.heapsizejust tells you, at any point during the execution, where the heap-containing part ends (and where the sorted array starts). You need this because the split is not physical (it's not actually two arrays) - you just maintain a "marker" to tell you where each part starts/ends. 2/2