- Related Questions & Answers
- Min-Max Heaps
- Removing the Min Element from Interval Heaps
- Merge two binary Max Heaps using C++.
- max() and min() in Python
- Perform min/max with MongoDB aggregation
- Use of min() and max() in Python
- Sorting max to min value in MySQL
- Average of array excluding min max JavaScript
- Convert min Heap to max Heap in C++
- Find Min-Max in heterogeneous list in Python
- How to use min and max attributes in HTML?
- Min and max values of an array in MongoDB?
- Program to fill Min-max game tree in Python
- Pairing Heaps
- Soft Heaps

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A symmetric min-max heap (SMMH) is defined as a complete binary tree in which each node except the root has exactly one element. The root of an SMMH be empty and the total number of nodes in the SMMH is m + 1, where m is the number of elements.

Let y be any node of the SMMH. Let elements(y) be the elements in the sub tree rooted at y but excluding the element (if any) in y. Assume that elements(y) j= ∅. y satisﬁes the following properties:

- The left child of y has the minimum element in elements(y).
- The right child of y (if any) has the maximum element in elements(y).

Figure 1 shows an example SMMH that has 12 elements.

When y denotes the node with 81, elements(y) = {7, 15, 31, 41}; the left child of y has the minimum element 6 in elements(y); and the right child of y has the maximum element 41 in elements(y). We may verify that every node y of this SMMH satisﬁes the stated properties.

Since an SMMH is denoted as a complete binary tree, it is stored as an implicit data structure implementing the standard mapping of a complete binary tree into an array. When m = 1, the minimum and maximum elements are the same and are contained in the left child of the root of the SMMH.

When m > 1, the minimum element is in the left child of the root and the maximum is in the right child of the root. So the getMin and getMax operations consume O(1) time.

It is easy to see that an m + 1-node complete binary tree with an empty root and one element in every other node is an SMMH iff the following are true −

A1 − For every node y that has a right sibling, the element in y is less than or equal to that in the right sibling of y.

A2 − For every node y that has a grandparent, the element in the left child of the grandparent is less than or equal to that in y.

A3 − For every node y that has a grandparent, the element in the right child of the grandparent is greater than or equal to that in y.

Notice that if property A1 is satisﬁed at node y, then at most one of A2 and A3 may be violated at y. Implementing properties A1 through A3 we reach at simple Algorithms to insert and remove elements. These Algorithms are simple adaptations of the corresponding Algorithms for min and max heaps. Their complexity is O(log m).

Here, we specify the insert operation. Suppose we wish to insert 3 into the SMMH of Figure 1. Since an SMMH is a complete binary tree, we must add a new node to the SMMH in the position shown in Figure 2; the new node is labelled as B.

In our example, B will denote an empty node. Now 3 is inserted at node B.

Advertisements