Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE-CS-2016 (Set 2) | Question 44

  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021

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]
(A) 6
(B) 7
(C) 8
(D) 9

Answer: (C)

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.

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!