When trees are tall!

Given 10 elements, how many ways are there of making a binary search trees such that it has the maximum possible height (nine)?


The answer is 512.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Let us consider the generalized problem of a tall binary tree with n n nodes.

To make the tree as tall as possible, we require that it has no "branches", i.e, there are no nodes which have both left and right children. This means that we have two choices, to make the entire subtree towards the right, in which case the root element is the minimum, or towards the left, in which case the root element is the maximum.

After we have made that choice, all we need to do is build a rebuild a tall tree with n 1 n-1 nodes and root it according to the choice we made.

So, T r e e s ( n ) = 2 T r e e s ( n 1 ) Trees(n) = 2 \; Trees(n-1)

It is clear that with a single node there is only a single such tree. Hence, T r e e s ( 1 ) = 1 Trees(1) = 1

That gives us the general formula T r e e s ( n ) = 2 n 1 Trees(n) = 2^{n-1} . Plugging in 10 10 gives 512 512 .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...