A min-max heap is a data structure that supports both deleteMin and deleteMax in
ID: 3863513 • Letter: A
Question
A min-max heap is a data structure that supports both deleteMin and deleteMax in O (logN) per operation The structure is identical to a binary heap, but the heap-order property is that for any node, X, at even depth, the element stored at X is smaller than the parent but larger than the grandparent (where this makes sense), and for any node X at odd depth, the element stored at X is larger than the parent but smaller than the grandparent. See Figure below, which is a Min-Max Heap. A) How do we find the minimum and maximum elements? B) Give an algorithm in pseudocode to insert new node into the min-max heap.Explanation / Answer
Answer:
a) The heap has two properties:
Min heap is a heap which is having root element as the minimum element among its childrens.Wile on thr other hand max heap is the heap which is having largest elements among its children.
The given heap is a min heap. So finiding the minimum element takes O(1) time, means at only one step we will be able to find the min element.
To find the max element in the min heap , we start from level zero of the treat with zero element and start from left to right the searching of new element.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.