previous | index | next

Maximum and Minimum Height

Q: If a binary tree has n nodes, what is the maximum height it can be?

A: n-1

Q: If a binary tree has n nodes, what is the minimum height it can be?

A: Since n ≤ nodes(h),

n ≤ 2h+1 − 1
n < 2h+1

Now n cannot be less than 2h, because then a tree of height h-1 could hold all the nodes. So

2h ≤ n < 2h+1

Now take log base 2 of all terms:

h ≤ log2n < h+1

Since the height is always an integer, and the log of a number could be fractional, we see that the minimum height of a tree with n nodes is log2n.


previous | index | next