The Gateway to Computer Science Excellence

+1 vote

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 ______.

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

+1

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.

+2 votes

Best answer

@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.

52,315 questions

60,427 answers

201,753 comments

95,231 users