2

$N$ students are standing in a line. How many permutations exist such that no two students who were originally next to each other remain next to each other?

Suppose $n=4$ and assuming the original permutation to be $ABCD$,then valid permutations are $BDAC$ and $CADB$, so the answer for $n=4$ is $2$.

f.nasim
  • 628
SHB
  • 121
  • 3
  • 2
    Please do not cut'n'paste questions here without telling us where they are from, why they interest you, what you have been able to do about them, where you get stuck, and so on. – Gerry Myerson May 30 '13 at 13:32
  • 1
    Try the following. Work out the answer by hand (=brute force) when $N=2,3,4,\ldots$ Do you see anything interesting? I'm not sure that you will, but I would never ask for help before I tried things like that! When you can report your findings like about experiments like that, others will be more eager to help you in turn. Also, before you prove anything, you need to know what you want to prove! – Jyrki Lahtonen May 30 '13 at 13:34
  • My intuition says a recursive solution is possible. – f.nasim May 30 '13 at 14:07
  • @Jyrki Lahtonen, I have tried finding the answer by brute force till n=5 which is as follows, for n=0 ans=0,n=1 ans=0,n=2 ans=0,n=3 ans=0, n=4 ans=2 and n=5 ans=14. Finding out the ans for n>5 is a bit difficulted bcoz of the number of permutations involved. – SHB May 30 '13 at 18:32
  • @Shubham: I got 14 for $N=5$ as well, but no matter how I went about it, it didn't look like the approach would generalize. I tried Abhra's suggestion, but it also ran into complexities. If you can do it for $N=6$, then you can try your luck with the on-line encyclopedia of integer sequences. – Jyrki Lahtonen May 30 '13 at 18:44
  • Surprisingly OEIS didn't give me anything that fits 0,2,14. The most promising ones were special cases such as the number of permutations $p$ such that $|p(i+1)-p(i)|\in{2,3,4}$ for all $i$. Nothing about $|p(i+1)-p(i)|>1$ for all $i$!! – Jyrki Lahtonen May 30 '13 at 19:13
  • 1
    Here's a way to think about the problem (whether it helps to solve it, I don't know). Take the complete graph on $n$ vertices, remove one Hamiltonian path (not cycle) from it, then we want to know how many Hamiltonian paths there are in the new graph. – Gerry Myerson May 31 '13 at 12:54
  • Something like what's in my last comment is discussed at http://mathoverflow.net/questions/28649/how-many-hamiltonians-paths-there-are-in-almost-regular-graph – Gerry Myerson May 31 '13 at 13:01
  • 1
    @JyrkiLahtonen: The OEIS sequence existed at the time (see my answer), but with only $0,2,14$ to go by, there were probably too many hits to sift through :-) – joriki Mar 24 '23 at 05:25
  • A likely explanation, @joriki. This turned out to be trickier. Well done anyway. – Jyrki Lahtonen Mar 24 '23 at 08:48

1 Answers1

1

As suggested at the time in a now deleted answer, this can be solved using inclusion–exclusion.

There are $n-1$ conditions, one for each pair of neighbours.

We need to count the ways of violating any subset of these conditions. Say we want to violate $k$ of them. We can tell the $k$ pairs of neighbours who stay together to hold hands, and then we can still permute the line in $(n-k)!$ ways. But any consecutive run of neighbours holding hands can also reverse their order; so we also get a factor $2^r$, where $r$ is the number of such runs. There are $\binom{k-1}{r-1}$ ways to distribute $k$ pairs over $r$ runs and $\binom{n-k}r$ ways to position those runs in the line. Thus, by inclusion–exclusion, there are

$$ n!+\sum_{k=1}^{n-1}(-1)^k\sum_{r=1}^k\binom{n-k}r\binom{k-1}{r-1}(n-k)!2^r $$

permutations that fulfil all the conditions.

Here’s Java code that performs this computation. The result is OEIS sequence A002464, for which a number of references and expressions are given, including the one above, contributed by Max Alekseyev.

joriki
  • 242,601