Catalan number with 2 kind of parenthesis and stack.

320 Views Asked by At

how many ways are there to construct a valid sequence of n () and k[] parenthesis. with the limitation that the parenthesis could represent a computer program that "(" represent push 0 and ")" represent pop 0 and "{" represent push 1 and "}" represent pop 1. example: for n = 1 and k=1 the sequences valid:

()[]

([])

[()]

and the sequences invalid:

([)]

[(])

the ways to constract a valid sequences without the limitation is:

$$C_kCn\binom{2(k+n)}{2k}=\frac1{(k+1)(n+1)}\binom{2k}k\binom{2n}n\binom{2(k+n)}{2k}$$

2

There are 2 best solutions below

0
On BEST ANSWER

Ignoring the distinction between brackets, there are $C_{n+k}$ distinct bracket arrangements. Of the $n+k$ pairs of brackets we must then choose $k$ of them to be square. So the answer is $C_{n+k}\binom{n+k}k$.

0
On

There are $C_{n+k}$ ways to arrange $n+k$ parenthesis accordingly, where $C_i = \binom{2i}{i+1}$.

Each initial arrangement only containing parenthesis will correspond to exactly one valid rearrangement into parenthesis and brackets. If we choose $k$ of the $n+k$ parenthesis to turn into brackets, we will have $(C_{n+k})(\binom{n+k}{k})$.

For example, for the initial arrangement $(())$, we can transform the inside or outside pair into brackets: $([])$ or $[()]$. Thus, we multiple $C_2$ by $\binom{2}{1}$.