Search code examples
heapminmax-heap

in binary max heap, isn't a parent node bigger than its children?


I got wrong on this question because the question says in Binary Max Heap, "If y is a node in the right subtree of node x, then y.key >= x.key." I attached the screenshot of the question below.

Binary Max Heap Question

if y is a node in the subtree of node x, I think x.key is bigger than y.key since according to max heap property a parent node is bigger than its children. I would like to know whether I am missing something. Thanks in advance.


Solution

  • A Binary-Max Heap is one in which -

    • The root node has the maximum value.

    • The value of each node is equal to or less than the value of its parent node.

    • is a complete binary tree.

    In Binary Max-Heap, a parent node is always bigger than any of its children nodes

    So you are right ! x.key is bigger than y.key since according to max heap property a parent node is bigger than its children is correct.