+1 vote
in Data Structures & Algorithms I by (88.2k points)
If we implement heap as min-heap, deleting root node (value 1)from the heap. What would be the value of root node after second iteration if leaf node (value 100)  is chosen to replace the root at start.

(a) 2

(b) 100

(c) 17

(d) 3

Query is from Heap in section Heap of Data Structures & Algorithms I

This question was addressed to me in examination.

1 Answer

+1 vote
by (672k points)
selected by
Best answer
The correct choice is (a) 2

The explanation is: As the root is deleted and node with value 100 is used as replaced one. There is a violation of property that root node must have value less than its children. So there will be shuffling of node with value 100 with node of value 2. And thus 2 becomes root. And it will remain to be at root after all the possible operations. So the value at root will be 2.

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.