Generating Functions $\newcommand{\nats}{\mathbb{N}}$
Every series of numbers corresponds to a generating function. It can often be comfortably obtained from a recurrence to have its coefficients -- the series' elements -- plucked.
This answer includes the general ansatz with a complete example, a shortcut for a special case and some notes about using this method to obtain asymptotics (even if the precise result can not be obtained).
The Method
Let $(a_n)_{n\in\nats}$ a series of numbers. Then, the formal power series
$\qquad \displaystyle A(z) = \sum_{n=0}^\infty a_nz^n$
is the ordinary generating function¹ of $(a_n)_{n\in\nats}$. The coefficients in the series expansion of $A(z)$ equal the sequence, i.e. $[z^n]A(z) = a_n$. For example, the ordinary generating function of the famous Catalan numbers $C_n$ is
$\qquad \displaystyle C(z) = \frac{1 - \sqrt{1 - 4z}}{2z}$.
The definition of $A$ is also our ansatz for solving a recurrence. This works best for linear recurrences, so assume for the sake of simplicity a recurrence of the form
$\qquad \begin{align}
a_0 &= c_0 \\
&\vdots \\
a_{k-1} &= c_{k-1} \\
a_n &= f(n) + \sum_{i=1}^k b_i a_{n-i} \qquad , n \geq k
\end{align}$
for some fixed $b_1, \dots, b_k \in \mathbb{R}$ and $f(n) : \nats \to \nats$ a function independent of all $a_i$. Now we simply insert both anchors and recursive part into the ansatz, that is
$\qquad \begin{align}
A(z) &= \sum_{n=0}^\infty a_nz^n \\
&= c_0z^0 + c_1z^1 + \dots + c_{k-1}z^{k-1} + \sum_{n=k}^\infty \left[ f(n) + \left(\sum_{i=1}^k b_i a_{n-i}\right)\right] z^n
\end{align}$
Using mechanics of sum manipulation, properties of formal power series and known identities², the last right-hand side has to be brought into closed forms, typically in terms of $A(z)$. The resulting equation can (often) be solved for $A(z)$. The series expansion of the result (which may be easily obtained, known or otherwise approachable) is essentially the solution.
Good introductions can be found in Wilf's book [3] and in GKP [4]. Advanced material has been collected by Flajolet and Sedgewick [5].
Example
Consider
$\qquad \begin{align}
a_0 &= 1 \\
a_1 &= 2 \\
a_n &= 5n + 3a_{n-1} - 2a_{n_2} \qquad , n > 1
\end{align}$
We calculate:
$\qquad \begin{align}
A(z) &= \sum_{n=0}^\infty a_n z^n \\
&= 1 + 2z + \sum_{n=2}^\infty \left[ 3a_{n-1} - 2a_{n-2} + 5n\right]z^n \\
&= 1 + 2z + 3\sum_{n=2}^\infty a_{n-1}z^n - 2\sum_{n=2}^\infty a_{n-2}z^n + 5\sum_{n=2}^\infty n z^n \\
&= 1 + 2z + 3z\sum_{n=1}^\infty a_nz^n - 2z^2\sum_{n=0}^\infty a_n z^n + 5\sum_{n=2}^\infty n z^n \\
&= 1 + 2z + 3z(A(z) - a_0) - 2z^2A(z) + 5 \left( \frac{z}{(1-z)^2} - z\right) \\
&= 1 - 6z + (3z - 2z^2)A(z) + \frac{5z}{(1-z)^2}
\end{align}$
This solves to
$\qquad \begin{align}
A(z) &= \frac{1 - 3z + 13z^2 - 6z^3}{(1-2z)(1-z)^3} \\
&= \frac{16}{1-2z} - \frac{5}{1-z} - \frac{5}{(1-z)^2} - \frac{5}{(1-z)^3} \\
&= 16\sum_{n=0}^\infty 2^n z^n - 5\sum_{n=0}^\infty z^n - 5 \sum_{n=0}^\infty (n+1) z^n - 5\sum_{n=0}^\infty \frac{(n+1)(n+2)}{2} z^n
\end{align}$
Now we can finally read off
$\qquad \begin{align}
a_n &= 16 \cdot 2^n - 5 - 5(n+1) - \frac{5}{2}(n+1)(n+2) \\
&= 2^{n+4} - \frac{5}{2}n^2 - \frac{25}{2}n - 15
\end{align}$
Once you get used to it, you notice that this is all quite mechanic. In fact, computer algebra can do all this stuff for you in many cases. The good is that it remains (more or less) that mechanic even if the recurrence is more complex. See here for a more involved, less mechanic example.
Also note that the general techniques also work if the objects sought are complex numbers, or even polynomials.
A Shortcut
For linear and homogeneous recurrences, i.e. such of the form
$\qquad \begin{align}
a_0 &= c_0 \\
&\vdots \\
a_{k-1} &= c_{k-1} \\
a_n &= \sum_{i=1}^k b_i a_{n-i} \qquad , n \geq k
\end{align}$
the above goes through in exactly the same way, every time. By performing above calculation symbolically, we find the following lemma. Let
$\qquad \displaystyle z^k - b_1 z^{k-1} - b_2 z^{k-2} - \dots - b_k$
be the characteristic polynomal (of the recurrence). Let furthermore $\lambda_1, \dots, \lambda_l$ the (pairwise distinct) zeros of said polynomial with multiplicity $r_i$, respectively. Then, the desired coefficient is given by
$\qquad \displaystyle a_n = \sum_{i=1}^l \sum_{j=1}^{r_i} b_{i,j} \cdot n^{j-1} \cdot \lambda_i^n$
with unknown $b_{i,j}$. As the characteristic polynomial has degree $k$, there are exactly $k$ (complex) zeros, i.e. the $r_i$ sum to $k$. Therefore, the missing coefficients can be determined by solving the linear equation system with $k$ equations obtained by equating above formula with any $k$ of the $a_n$ (e.g. the anchors).
Asymptotics
Getting to a closed form for $A(z)$ is usually the easy part. Expressing it in generating functions we know the coefficiencts of (as we did in the example) quickly becomes hard, though. Examples are $C(z)$ from above and the one for the number of Dyck words mentioned in the question.
One can employ complex analysis machinery, specifically singularity analysis, in order to obtain asymptotics for the coefficients; buzzwords include Darboux's method and saddle-point method. These are based on the residue theorem and Cauchy's integral formula. See [6] for details.
- You can do similar things with exponential, Dirichlet and some other generating functions. Which works best depends on the sequence at hand and in particular whether you find the necessary closed forms.
- For example from the TCS Cheat Sheet or [3].
- generatingfunctionology by H. Wilf (1994, 2nd ed.) -- available for free download
- Concrete Mathematics by R.L. Graham, D.E. Knuth and O. Patashnik (1994, 2nd ed.)
- Introduction to the Analysis of Algorithms by R. Sedgewick and P. Flajolet (2nd edition, 2013) -- available for free download
- Analytic Combinatorics by P. Flajolet and R. Sedgewick (2009) -- available for free download