The Gateway to Computer Science Excellence
0 votes
136 views

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 by Loyal (5.3k points) | 136 views
+2

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

1 Answer

+1 vote

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 (291 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,741 questions
57,251 answers
198,059 comments
104,692 users