How many subsets contain no 3 consecutive elements

combinatoricsdiscrete mathematicsgenerating-functions

How many subsets of $\{1,2,…,n\}$ have no $3$ consecutive numbers ?

My solution:

Inspired by How many subsets contain no consecutive elements? I decided to write recurrence:
Let be set with numbers from $1$ to $n$ and let $A$ – subset of given set
$$ a_n = \underbrace{a_{n-1}}_{n \notin A} + \underbrace{a_{n-2}}_{n \in A , n-1 \notin A} + \underbrace{a_{n-3}}_{n \in A, n-1 \in A, n-2 \notin A} $$

After examining corner cases I use iverson bracket to write full recurrence:
$$ a_n = a_{n-1}+ a_{n-2} + a_{n-3} + [n=0] + [n=1] + [n=2]$$
After multiplying by $x^n$ and summing by all $n$ I got generating function:
$$A(x) = x A(x) + x^2 A(x) + x^3 A(x) +1+ x + x^2 $$
$$A(x) = \frac{1+x+x^2}{1-x-x^2-x^3} $$
But how to solve this generating function to get coefficient with $x^n$?

Best Answer

To summarize the discussion in the comments:

The recursion: $$a_n=a_{n-1}+a_{n-2}+a_{n-3}\quad a_1=2\quad a_2=4 \quad a_3=7$$

has characteristic polynomial $$x^3-x^2-x-1$$ which doesn't have particularly pleasant roots, which means that there isn't a simple closed formula for the results. The sequence $$\{a_n\}=\{2,4,7,13, 24, 44, 81, \cdots \}$$ is part of A000073 in oeis.org and that link contains a lot of information on the sequence, though of course it does not present a simple closed formula. Note that the characterization given there as the number of binary sequences of length $n$ for which the string $000$ does not appear is entirely equivalent the one given by the OP here, as each string corresponds to a subset (where a $1$ indicates that the entry is absent and a $0$ indicates that it is present).

Related Question