How to identify vertices that violates Max Heap property?

98 Views Asked by At

I am learning binary heap now and I do not really understand this question about Build Heap that violates the property of Max Heap. Could someone explain the answer below for me please?

Build Heap

1

There are 1 best solutions below

0
Jim Mischel On

In a max heap, a node must be greater than or equal to both of its children. You correctly identified most of the nodes that violate that condition, but you missed a few of them.

Here are those that you identified:

  • 10 is out of order because it is smaller than both of its children
  • 44 is out of order because it is smaller than both of its children
  • 29 is out of order because it is smaller than 33, its right child
  • 46 is out of order because it is smaller than 80, its right child
  • 75 is out of order because it is smaller than 96, its right child
  • 85 is out of order because it is smaller than 86, its left child
  • 54 is out of order because it is smaller than 57, its left child

The two that you missed are:

  • 61 is out of order because it is smaller than 78, its right child
  • 76 (the root) is out of order because it is smaller than 99, its left child