- Heap data structure is a specialized binary tree-based data structure. Heap is a binary tree with special characteristics. In a heap data structure, nodes are arranged based on thier value. A heap data structure, some time called as Binary Heap.
- There are two types of heap data structures and they are as follows...
- Max Heap
- Min Heap
Every heap data structure has the following properties...
Property 1 (Ordering):
- Nodes must be arranged in a order according to values based on Max heap or Min heap.
Property 2 (Structural):
- All levels in a heap must full, except last level and nodes must be filled from left to right strictly.
Max Heap
- Max heap data structure is a specialized full binary tree data structure except last leaf node can be alone. In a max heap nodes are arranged based on node value.
Max heap is defined as follows...
"Max heap is a specialized full binary tree in which every parent node contains greater or equal value than its child nodes. And last leaf node can be alone."
Example
- The above tree is satisfying both the Ordering property and Structural property according to the Max Heap data structure.
Operations on Max Heap
The following operations are performed on a Max heap data structure...
- Finding Maximum (It's easy to find the node in a max heap with the highest value. The root node in a max heap has the highest value of all the other nodes. As a result, we can display the value of the root node as the maximum value in the max heap.)
- Insertion Operation in Max Heap
- Deletion Operation in Max Heap