Machine-translated by Google. Questions are authored in English.
Top

Discussion

For a given max-heap, which is the correct answer ?

  • A.The leaf nodes have values greater than or equal to their parents
  • B.The leaf nodes have values less than or equal to their parents
  • C.The leaf nodes and their parents have same values
  • D.The leaf nodes have values different from their parents

Answer: B

In a max-heap, the leaf nodes have values less than or equal to their parents.

The max-heap property says that every node's key is greater than or equal to the keys of its children. Applied to a leaf and its parent, the leaf's value can be no larger than its parent's. As a result the maximum is at the root.

Option A states the min-heap property instead. C and D are not required: a leaf may equal its parent or differ from it, as long as it is not larger.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.