+1 vote
144 views
The height of a binary tree is defined as the number of nodes in the longest path form the root node to the leaf node. Let X be the height of complete binary tree with 256 nodes. The value of X will be ______.
in DS | 144 views
0
7 )
0
I got 8 , answer given is 9
0
starts counting height of root with 1, then you will get 9
0

@Shaik Masthan but height of root node should be 0?

0
$2^{h+1} - 1 = n ???$
0

The height of a binary tree is defined as the number of nodes in the longest path form the root node to the leaf node.

take 2 nodes, and apply the definition !

but height of root node should be 0?

it is a convention but not rule

0
Here height defined in the question is in terms of "nodes" and not "edges".
0

Yes @MiNiPanda

is right

0

can you please explain, I'm not getting what you say in an above comment?

+1

@Lakshman Patel RJIT

generally we take height as the no. of edges involved in the longest path from root to leaf right?

Here height has to be taken as the no. of nodes involved and not the edges because of the definition in the question.

0
So the height of the root, if the number of nodes is $3$ in the complete binary tree$?$
+1

Is this one correct$?$

The height of a binary tree is defined as the number of nodes in the longest path from the root node to the leaf node.

I have the problem with the above line?

+1
Height is 2 acc to the problem here..

O

/      \

O         O

As two nodes are there in the longest path.
0

thank you so much, now I understand.

@Shaik Masthan Sir, Can we do like this

number of nodes will be 1,2,4,8,... at each level

now count them it will be 2^n-1

now check for what value of n it will result in >=256

for n=8 it is 255

for n=9 it is >=256

so the height of the tree will be 9.

selected by
+1
Yes, this is the correct way to analysis this question...

Moreover no need to call me sir :)

–1 vote