Number of subsets $\{1, 2, \dots, n\}$ without numbers with forbidden differences.

113 Views Asked by At

Let $S = \{1, 2, \dots, n\}$. Let $R = \{r_1, r_2, \dots, r_m\}$ be a set of forbidden differences. How many subsets of $S$ don't have two numbers the difference of which belongs to $R$?

I have found that recursive approach helps to solve some cases. For example let's start with $R = \{1, 2\}$. Then let $a_n$ be a number of these subsets of $\{1, 2, \dots, n\}$. Let $A$ be a subset with given conditions. We begin by looking at some cases:
$n \in A$, then $n-1 \not\in A$ and $n-2 \not \in A$, so $a_n = a_{n-3}$

$n\not\in A$, then $a_n = a_{n-1}$
So $a_n = a_{n-1} + a_{n-3}$. Similarly if $R = \{1, \dots, m\}$ then $a_n = a_{n-1} + a_{n-m-1}$.
Let then $R = \{2\}$. Again some cases:
$n \in A, n-1 \in A$. Then $n-2 \not\in A$ and $n-3 \not\in A$, $a_n = a_{n-4}$.

$n \in A, n-1 \not\in A$. Then $n-2 \not\in A$ so $a_n = a_{n-3}$.

Finally if $n \not\in A$ $a_n = a_{n-1}$
This way $a_n = a_{n-1} + a_{n-3} + a_{n-4}$.
However I struggle to find a recurrence for $R = \{m\}$ and generalize solution to any set of $R$.

1

There are 1 best solutions below

0
On

For $R = \{m\}$ one should probably use the more complicated recursion with banned positions. Namely, let $S = \{s_1, \ldots, s_k\}$ be a set of nonnegative integer numbers not exceeding $m$. Let $a(n, S)$ be a number of subsets of $\{1,\ldots, n\}$ where the elements $n-s_1, \ldots, n-s_k$ are not taken. In this setting the recursion step is simple: $$ \begin{cases} a(n , S) = a(n - 1, \tilde{S}), \quad &0\in S, \\ a(n , S) = a(n - 1, \tilde{S}) + a(n - 1, \tilde{S}\cup\{m - 1\}), \quad &0\notin S, \end{cases} $$ where $\tilde S$ is the set of numbers $\{s_1 - 1, \ldots, s_k - 1\}\setminus \{-1\}$. Indeed, if $0\in S$ then the element $n$ cannot be taken hence the answer can be calculated for $n-1$ with the restrictions shifted by $1$, if $0\notin S$ then one can take $n$ and create another restriction for number $n - m$ or skip the number $n$ and again shift the restrictions.

The answer to your problem is $a(n, \emptyset)$.

However there are $2^m$ different sets of restrictions $S$ hence t0 calculate $a(n, \emptyset)$ one needs to calculate $O(n\times 2^m)$ other positions.

This method can be easily generalized for an arbitrary subset $R$, the recursion step will change in the second case, because there will be more new restrictions. The complexity will be $O(n\times 2^{\max (R)}\times |R|)$.