Option 1 is right. As we begin to add children from the leftmost node, and if the parent is lower than the one just added, we will replace it. And so it will continue until the child receives a parent who has a value greater than that.
Your source tree
77 / \ / \ 50 60 / \ / \ 22 30 44 55
Now add 55 in accordance with the rule on most leftists.
77 / \ / \ 50 60 / \ / \ 22 30 44 55 / 55
But you see that 22 is less than 55, therefore replaced it.
77 / \ / \ 50 60 / \ / \ 55 30 44 55 / 22
Now 55 is a descendant of 50, which is still below 55, so replace them too.
77 / \ / \ 55 60 / \ / \ 50 30 44 55 / 22
Now it cannot be sorted anymore, because 77 is more than 55 ... So, your option 1 is right.
here you can see an example of sorting the heap in detail .. This link indicates the heap - this is a specialized tree-like data structure that satisfies the heap property: if B is a child node of A, then (A) ≥ (B). This means that the element with the largest key is always in the root of the node, and therefore this heap is sometimes called max-heap. (Alternatively, if the comparison is canceled, the smallest element is always in the root directory of the node, which leads to a mini-heap.) There are no restrictions on the number of children, each of which node is on the heap, although in practice each node has at most two.
Luck
Syeda
source share