Skip to interview prep
Apexed

205. What is a min-max heap and what does it support?

HardPriority queues & heaps

Technical
Show model answer

A min-max heap is a complete binary tree in an array where levels alternate: nodes on even levels (starting with the root) are smaller than all their descendants, and nodes on odd levels are larger than all their descendants. The root is the minimum and the larger of the root's children is the maximum.

Find-min and find-max are O(1); insert, delete-min and delete-max are O(log n) because sifting compares against grandparents or grandchildren, so each step jumps two levels. It is a compact double-ended priority queue; two heaps with cross-links or a balanced BST are alternatives.

What is a min-max heap and what does it support — Data structures & algorithms interview question — Apexed