How to calculate all possible combinations of brackets order?

8.9k Views Asked by At

Hey I would like to find out a formula on calculating the maximum possible combinations of brackets order.

First of all there a few rules: - Brackets have to be valid (Every bracket has a closing bracket) - n % 2 == 0 (n = Brackets, only pairs) - The order is sensitive, e.g.: a,b and b,a equals 2 combinations

What is a valid combination ? Lets say n is our variable for the brackets count:

n = 2: () - Only 1 combination possible

n = 4 () (), (()) - Only 2 combinations possible

n = 6 ((())), () () (), (()()), (())(), ()(()) - 5 possible combinations

Now any ideas how to calculate the combinations number when I only have n = ?

Greetings

1

There are 1 best solutions below

0
On

These are the Catalan numbers $C_n=\frac 1{n+1}{2n \choose n}$ The second example in the Wikipedia article is this one.