- A heap is a special kind of tree-based data structure.
- A heap is a complete binary tree in which every node satisfies the Heap property which states that: “The node_value(A) ≥ node_value(B) where B is a Child of A”
- This means that at elements at every node will be having a value greater than or equal to its parent element. That means, the root node will be having the highest value in the tree.
- Such kind of tree is popularly called as max-heap.
- A tree which works in exactly the opposite fashion of the above mentioned property is called as min-heap.
- The root element of a min-heap will be having the lowest value.
- Consider the array " 67, 12, 89, 26, 38, 45, 22, 79, 53"
Step 1: Build a heap using elements of array
Step 2:Repeatedly delete the Root element of the heap created