previous | start | next

Perfectly Balanced Binary Search Trees

One definition of balanced is too restrictive:

For every node, the height of the left and right subtrees of the node should be equal.

How many nodes are in such a tree if the height if h?

Answer:

      2h + 1 - 1
   

Proof:

Correct for h = 0.

If T(h) is such a tree of height h > 0, then its left and right subtrees are of height h - 1.

So the number of nodes in each subtree must be:

      2h - 1
   

The total number of nodes in T(h) is then

      2 * (2h - 1) + 1 = 2h + 1 - 2 + 1 =
      2h + 1 - 1
   

So only "balanced trees" with this definition could only exist provided the number of nodes is of this this special form!

So we need a slightly less restrictive definition.



previous | start | next