GATE | GATE-CS-2016 (Set 2) | Question 44
A complete binary min-heap is made by including each integer in [1, 1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth 0. The maximum depth at which integer 9 can appear is _____________
[This question was originally asked as Fill-in-the-Blanks question]
Explanation: here node with integer 1 has to be at root only. Now for maximum depth of the tree the following arrangement can be taken. Take root as level 1.
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.
make node 2 at level 2 as a child node of node 1.
make node 3 at level 3 as the child node of node 2.
.. and so on for nodes 4,5,6,7
make node 8 at level 8 as the child node of node 7.
make node 9 at level 9 as the child node of node 8.
Putting other nodes properly, this arrangement of the complete binary tree will follow the property of min heap.
So total levels are 9. node 9 is at level 9 and depth of node 9 is 8 from the root.
Quiz of this Question