MaxHeap

 

Question :
There is an unsorted array of integers representing a binary tree.Convert it to maxHeap.

arr = { 3, 5, 1, 2, 7, 9, 6, 8, 10, 4 };

ai1tutorial_heap

 

Algorithm :
Step 1 : From 1st element till the last element,each element data is compared with its child data.

Step 2 : Parent and child’s data are swapped if parent data is greater than child’s data.

Program :

 
 


Leave a comment

Your email address will not be published. Required fields are marked *

10 + 8 =