A Dyck path from $(0,0)$ to $(2n+2,0)$ is a lattice path with steps $(1,1)$ and $(1,-1)$, never falling below the $x$-axis.
Find the number of Dyck paths from $(0,0)$ to $(2n+2,0)$ such that any maximal sequence of consecutive steps $(1,-1)$ ending on the $x$-axis has odd length.
The above question is from Richard Stanley's Enumerative Combinatorics. In fact, a solution is given by Stanley, but I am not sure why we should proceed like that.
Let $A(x)=x+x^3+2x^4+6x^5+\cdots$ (respectively, $B(x)=x^2+x^3+3x^4+8x^5+\cdots$) be the generating function for Dyck paths from $(0,0)$ to $(2n, 0)$ such that the path only touches the $x$-axis at the beginning and end, and the number of steps $(1,-1)$ at the end is odd (respectively, even).
How do we obtain these two generating functions? Why does it suffice to consider the paths that touch the $x$-axis at the beginning and the end?
Let $C(x)=1+x+2x^2+5x^3+\cdots$ be the generating function for all Dyck paths from $(0,0)$ to $(2n,0)$. Note that the coefficients are Catalan numbers. It is easy to see that $A=x(1+CB)$ and $B=xCA$. Solving for $A$ gives $$A=\frac{x}{1-x^2C^2}.$$
Although I may not understand how to come up with $A$ and $B$, this part is simply computation.
The generating function we want is $$\frac{1}{1-A}.$$
I again do not understand this part. Why do we have such a generating function?
The above simplifies to $1+xC$, which means that the required number follows the Catalan numbers.
Any help for the above question is appreciated.
We put the focus on Dyck paths of length $2n$, starting at $(0,0)$ and ending at $(2n,0)$ which do not touch the x-axis between the start and end point. The number $n$ specifies the number of up steps which is equal to the number of down steps.
It is convenient to split these Dyck paths in paths which end with an odd number of down steps and those which end with an even number of down steps.
$n=2$: We get one path $\color{blue}{ud}$
$n=4$: We get no path, since $udud$ touches the $x$-axis between start and end point and $uudd$ does not end with an odd sequence.
$n=6$: We consider the pattern $\color{blue}{u(..)ddd}$ and obtain one path $\color{blue}{uuuddd}$.
$n=8$: We consider the pattern $\color{blue}{uu(..)uddd}$. Since we have to start with two $u$'s in order to not touch the $x$-axis in between and we have due to the same reason to terminate with three $d$'s, which implies that there is an up step $u$ before them. We find the paths $\color{blue}{uu(ud)uddd}$ and $\color{blue}{uu(du)uddd}$.
$n=10$: We consider the path $\color{blue}{uuuuuddddd}$ and the pattern $\color{blue}{uu(....)uddd}$ giving $1+\left(\binom{4}{2}-1\right)=6$ Dyck paths. Note, that we have to exclude $uu(dduu)uddd$ to not touch the $x$-axis in between.
$$ $$
If we consider e.g. the coefficient of $x^4$ we see \begin{align*} C_0A_4+C_1A_3+C_2A_2+C_3A_1+C_4A_0 \end{align*}
So, the coefficient of $x^4$ specifies the number of all Dyck paths $C_k$ of length $k\, (0\leq k \leq 4)$ concatenated with all specific Dyck paths $A_{4-k}$.
$$ $$