## Order Property

The ordering can be one of two types:

The

**min-heap**property: the value of each node is less than or equal to the value of its children, with the minimum-value element at the root. (Here “best” means “smallest”.)The

**max-heap**property: the value of each node is greater than or equal to the value of its children, with the maximum-value element at the root. (Here “best” means “largest”.)

The order property of a heap is a *weaker* ordering requirement compared to that of a binary search tree. In a max-heap for instance, the value in each node is $\ge$ to the value stored in its children but not necessarily $\ge$ to all its descendants.

Exercise Which of the following are a valid binary (max) heap?

## Solution

The two on the top are valid binary (max) heap but the bottom two are not.