Is a sorted array a min-heap? What's the minimum value of a max-heap?

An array sorted from lowest to highest is a min-heap when using the array-based heap implementation. The min-heap property that the parent node value is less than or equal to it's child nodes (2i + 1 and 2i + 2, using zero-based arrays) holds for all nodes that have children.

The minimum value of a max heap is in one of the leaf nodes, but you don't know which. Since the minimum node cannot, by definition, have any child nodes, it must be a leaf. The heap property, however, does not specify how leaf nodes compare with each other, only with their parent.


Is a sorted array a min-heap?

Yes, if you're using the typical array-stored heap convention.

Where is the minimum value of a max-heap?

At one of the leaves. Which exactly is undefined.

Tags:

Heap