Q9. Binary Min-Heap
A complete binary min-heap is made by including all the integers from 1 to 1023 exactly once. The depth of the 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
how is the answer -> 8
please explain???
Not able to figure out the answer
hello @Usha24
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.
in general case the total no of level will be 10 right??
as total there are 1023 nodes , so height = total levels = logN = 10
1+2+2^2+2^3…2^l<=1023
2^(l+1)-1 <=1023
2^(l+1)<=1024
2^(l+1)<=2^10
l+1=10
l=9
2^0 to 2^9 = 10 terms , so that means 10 levels right??