in DS edited by
1,280 views
1 vote
1 vote
The height of a binary tree is defined as the number of nodes in the longest path from root to the leaf node. Let X be the height of a complete binary tree with 256 nodes. Then the value of X will be
Answer 9
in DS edited by
1.3k views

1 comment

https://www.geeksforgeeks.org/relationship-number-nodes-height-binary-tree/

If there are n nodes in a binary tree, the maximum height of the binary tree is n-1 and minimum height is $\left \lfloor log\ 2n \right \rfloor$ .

3
3

1 Answer

2 votes
2 votes

Read carefully what it is saying :- The height of a binary tree is defined as the number of nodes in the longest path from root to the leaf node. i.e. if node is 3 with (height 2) then height = 3 (a/c to question).

basically it is saying with node = 1 height = 1.

now, for complete binary tree h= ceil(log(n+1)-1) [with height starting from h=0 with node=1.]

ceil(log(256+1)-1=8

hence for this question 8+1= 9.

by

1 comment

@  I think you have wrongly taken the formula. In question its mentioned that complete tree with total  256 nodes. The height of complete binary tree is floor value (log n+1)  with base 2. Hence height should be 8

Please refer underlined part of the image

0
0