Computer Science, asked by ambccbjcgh12, 8 months ago

How many edges of this binary tree violate the min-heap property? In other words, for how many edges of the tree, the parent value is greater than the value of the child?

Attachments:

Answers

Answered by mad210219
2

Binary tree

Explanation:

Min heap:

The min heap is a complete binary tree so that the value in each node is less than its child nodes

So the above figure  

We have to chech where the property of min heap is vioalated that us we have to chech in which edges the value of parent node is greater than the child nodes

Calculating from the root node  

We compare root node with its child so  

1.5>4 so here we find the edge which violates min heap condition

5<11 so it satisfying min heap condition

Like wise we have to compare all the nodes with its child nodes

14>11 in the left subtree observe so it is violating the min heap property

In the right sub tree  

At last

18>12 and 18>7 so it is violating min heap property

So

We have to calculate where the number of times the property is broken

So on counting we got 4

So the answer is 4

Similar questions