0% found this document useful (0 votes)
46 views7 pages

Understanding Heap Data Structures

The document provides an overview of Heap Data Structures, which are balanced binary trees where the parent node's key is compared to its children. It describes two types of heaps: Min-Heap and Max-Heap, along with algorithms for constructing and deleting from a Max-Heap. The construction algorithm involves adding a new node and ensuring the heap property is maintained, while the deletion algorithm involves removing the root and adjusting the heap accordingly.

Uploaded by

Zeeshan Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views7 pages

Understanding Heap Data Structures

The document provides an overview of Heap Data Structures, which are balanced binary trees where the parent node's key is compared to its children. It describes two types of heaps: Min-Heap and Max-Heap, along with algorithms for constructing and deleting from a Max-Heap. The construction algorithm involves adding a new node and ensuring the heap property is maintained, while the deletion algorithm involves removing the root and adjusting the heap accordingly.

Uploaded by

Zeeshan Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Data Structures and Algorithms

Heap Data Structure


Heap Data Structures
Heap is a special case of balanced binary tree data
structure where the root-node key is compared with its
children and arranged accordingly.

If α has child node β then −


key(α) ≥ key(β)

As the value of parent is greater than that of child, this


property generates Max Heap.
Types of Heaps
Min-Heap − Where the value of the root node is less
than or equal to either of its children.

Max-Heap − Where the value of the root node is


greater than or equal to either of its children.
Max Heap Construction Algorithm

Step 1 − Create a new node at the end of heap.

Step 2 − Assign new value to the node.

Step 3 − Compare the value of this child node with its


parent.

Step 4 − If value of parent is less than child, then swap them.

 Step 5 − Repeat step 3 & 4 until Heap property holds.


Max Heap Construction
Max Heap Deletion Algorithm

Step 1 − Remove root node.

 Step 2 − Move the last element of last level to root.

Step 3 − Compare the value of this child node with its


parent.

Step 4 − If value of parent is less than child, then swap them.

 Step 5 − Repeat step 3 & 4 until Heap property holds.


Max Heap Deletion

You might also like