TITLE: A way to list $1,\, 2,\, 3,\cdots,\, n$.
QUESTION [8 upvotes]: In how many ways can list the number $1,\, 2,\, 3,\cdots,\, n$ such that apart from the leading element the number $k$ can be placed only if either $k-1$ or $k+1$ already appears? Example: $324516$, $435216$, but not $351246$.

This is a problem in GTM  A Course in Enumeration. And inspired by the textbook context, I want to solve the problem by applying

(Rule of Counting in Two Ways). When two formulas enumerates the same set, then they must be equal.

Define $d(i,\,k)$ be the number of permutation of $1,\,2,\cdots,\,n$ satisfies such property with $k$ in $i$th position.
Then we have
$$
d(1,\,1)=1,\quad d(1,\,n)=1
$$
and
$$
\sum_{k=1}^{n}d(i,\,k)\quad\text{and}\quad\sum_{i=1}^{n}d(i,\,k)
$$
is the desired result for all $i,\,k=1,\,2,\cdots,\,n$ respectively.
But I don't know how to go on.

REPLY [5 votes]: Here is a different approach: given a starting number $m$, for each subsequent spot, you can either place the number that is one lower than the lowest number places so far, or the number which is one higher than the highest number places so far.
Thus the sequence is entirely decided by its starting number and whether you go "low" or "high" in each subsequent spot. For instance, the first given example of a valid sequence, 324516, is given by its starting number 3, and the sequence low, high, high, low, high.
There is room for $m-1$ "low"s, and $n-m$ "high"s, and they can come in any order. Thus the number of valid sequences that start with $m$ is given by $\binom{n-1}{m-1}$. Adding them all together for all possible $m$, we get that the total number of valid sequences is
$$
\sum_{m=1}^n\binom{n-1}{m-1}=2^{n-1}
$$