6
$\begingroup$

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?

$\endgroup$

2 Answers 2

20
$\begingroup$

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.

http://oeis.org?q=1%2C1%2C2%2C5%2C14&sort=0&fmt=0&language=english&go=Search

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

$\endgroup$
1
  • $\begingroup$ Amazing! Thanks a lot for the very handy site! $\endgroup$
    – Mouk
    Commented Feb 25, 2010 at 15:43
13
$\begingroup$

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.

$\endgroup$
1
  • $\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
    Commented Feb 25, 2010 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .