Suppose we're given a set $S=\{1,2,3,4,5\}$. From elements in $S$, we form an array/sequence of length $n$, such that difference between neighboring elements is strictly $1$. For example, one valid sequence of length $n = 5$ is $32345$. What is the generating function for the number of such sequences?
My approach is to let $f(n)$ be a number of such sequences starting with 1 or 5 (only one neighboring number). Then, $f(n) = 2 * n-1$. Similiarly, let $g(n)$ be a number of sequences staring with $2,3,4$. Unfortunately, I can't find a proper formula for $g(n)$, although I'm quite convinced it's in the form of $a\times g(n-1) + b\times f(n-1)$.
Here is an alternative approach which you may find interesting.
What you want to count is the same as the number of walks of length $k$ in this graph:
This is given by the trace of the $k$'th power of its adjacency matrix $\begin{pmatrix} 0 & 1 & 0 & 0 & 0\\ 1 & 0 & 1 & 0 & 0\\ 0 & 1 & 0 & 1 & 0\\ 0 & 0 & 1 & 0 & 1\\ 0 & 0 & 0 & 1 & 0 \end{pmatrix}$
In order to get a formula for these entries we can diagonalize the matrix.
The spectrum of the path $P_n$ is $2\cos(\frac{j\pi}{n+1})$ where $1\leq j \leq n$.
An orthogonal basis for the respective eigenvectors is $U_{i,j} = \frac{\sqrt{2} \sin(ij\pi/(n+1))}{\sqrt{n+1}}$
Hence we have $A=UDU^{-1}$ and $A^k = UD^kU^{-1}$. This gives us a a linear formula for the number of sequences of length $k$, in which the variables are the elements of the spectrum raised to the $k$.