Binary Heap in Data Structure

Heap or Binary Heap is a special case of balanced binary tree data structure. This is complete binary tree structure. So up to l-1 levels it is full, and at l level, all nodes are from left. Here the root-node key is compared with its children and arranged accordingly. If a has child node b then −

key(a) ≥ key(b)

As the value of parent is greater than that of child, this property generates Max Heap. Based on this criteria, a heap can be of two types the Max Heap and the Min Heap.

These are examples of Max and Min Heap respectively −