How many ways is there to build an arithmetic expression with fixed number of terms and fixed order? Let’s assume we have only one distinct operation that is neither commutative nor associative. The problem can be reduced to the question of how many different, full, binary trees could be constructed with a fixed number of leaves.

Suppose we have a list of n elements which have to become leaves in a full, binary tree. The root could be chosen between each two sequential numbers. Thus, there is (n-1) different ways to choose the root. If the root is located after the i-th number, we can still construct the left child as a binary tree with i leaves and the right one with (n – i) leaves.

The formula for the number of different ways to construct a full, binary tree is

$ \Phi(n) = \sum^{n-1}_{i=1}\Phi(i).\Phi(n-i)$

The first value for n=1 ist set to:

$ \Phi(1) = 1 $

Is there a closed formula for this function? Is it - maybe - a popular problem in the Graph Theory with known solutions?


There is a general algorithm that solves this kind of problem.

  1. Calculate the first terms of your sequence by hand.
  2. Plug them into Sloane's and see if it is a known sequence.


Here you see that your numbers are called Catalan numbers; they are extremely well-studied.

| cite | improve this answer | |
  • $\begingroup$ Amazing! Thanks a lot for the very handy site! $\endgroup$ – Mouk Feb 25 '10 at 15:43

This is a very well-known enumeration problem. The number of full binary rooted trees with $n+1$ leaves is just the $n$-th Catalan number $$C_n = \frac{(2n)!}{(n+1)!n!}.$$

You can read more by looking at Wikipedia's entry on Catalan numbers, for example.

| cite | improve this answer | |
  • $\begingroup$ That can definitely be calculated faster than the recursion :) Sorry for not voting you up. It seems I need more reputation for voting! $\endgroup$ – Mouk Feb 25 '10 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.