Biology, asked by AnushkaSharma3662, 1 year ago

What is the minimum and maximum height possible of a binary tree with n nodes?

Answers

Answered by krishvermA
0
N - number of nodes.
H - height of the binary tree.

Complete Binary Tree:
Then, with H height N would lie between:

2^H <= N <= (2^(H+1) - 1)

Thus, solving this inequality; we get :

H <= lg(N) and H >= (lg(N+1) - 1)

Hence we finally get:

H = floor( lg(N) ) = ceil( (lg(N+1) - 1) ) //as H is integer

(lg : log base 2)

Binary Tree (not necessarily complete):

Max height = N; Min Height = floor( lg(N) ) = ceil( (lg(N+1) - 1) )

We get minimum height when binary tree is complete.

Similar questions