0

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

vt-0307
  • 63
  • 1
  • 7
  • Although the image of the heap is fine, the text is not. Instead of sharing text as an image, type the text in the question. Secondly, you ask about not understanding the question and explaining the answer. Those are two different things. Also, can you explain exactly *what* you don't understand? Maybe read [Wikipedia](https://en.wikipedia.org/wiki/Heap_(data_structure))? Is there then still a question? – trincot Apr 10 '23 at 19:57

1 Answers1

0

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
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351