Draw the heap represented by the list [0, 2, 28, 16, 29, 33, 17, 20, 56, 76, 60] as a tree:
min heap
Firstly, we set all the values of the list in a tree. [0, 2, 28, 16, 29, 33, 17, 20, 56, 76, 60]
As we know in min heap parent node always should be less than or equals to their child.
there are total no of node(n) = 11
we starting traversing the node from = n/2
=11/2=5.5
And , we start from 5th node, which is 29.
29 is already less than its child, then no need to traverse.
After 29 there are 4th node which is 16
16 is also less than its child, then no need to traverse.
After that 28 which is 3rd node.
there are 20 which is more then its parent so we replace the position of 17 and 28.
After that we check the 2nd node which is 2
2 is also less than its child.
in last we chaeck the 1st node which is 0
0 is also less than its child.
So, min heap tree is:
Answer.
Get Answers For Free
Most questions answered within 1 hours.