= x.key." I att..." /> = x.key." I att..." /> = x.key." I att..."/>

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

1.1k Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

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.

1
On

Don't think you are missing anything. Minheap bubbles up minimum key to root, maxheap bubbles up maximum key to root.

Now, min-max heaps... those are interesting.