Hi I have studied min heap and max heap and I have these questions that
- a sorted array is a min heap?
- where is the minimum value of a max heap?
please help me thanks {if you put some link I will be so glad}
Hi I have studied min heap and max heap and I have these questions that
- a sorted array is a min heap?
- where is the minimum value of a max heap?
please help me thanks {if you put some link I will be so glad}
A array sorted from lowest to highest is a min-heap when using the array-based heap implementation. The heap property that the parent node is greater than 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.
- a sorted array is 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 leafs. Which exactly is undefined.