11

I stumbled upon this most interesting problem whose solution has so far escaped me and I think that it'd be very fascinating to see how it may be precisely dealt with.

It runs as follows,

If some series of $n$ terms is deranged, how can we first calculate the probability that no term shall stand next to a term it was next to originally, and further, if $n$ happens to be infinite, how can we prove that the probability is $e^{-2}$?

String
  • 18,838
Fine
  • 632
  • 1
    Can you define "deranged"? – Michael Lugo Jun 04 '17 at 22:25
  • 4
    A derangement is a permutation with no fixed points. – Thompson Jun 04 '17 at 23:57
  • 2
    Calculate the answers for $n=4,5,6$ and then look it up in the Encyclopedia of Integer Sequences. – Gerry Myerson Jun 05 '17 at 07:00
  • 1
    Here is an OEIS result for the 'no adjacent pair is again adjacent' rule only. A002464 – Sangchul Lee Jun 05 '17 at 14:15
  • Using the computed values I checked the ratio and it seems in an agreement with the proposed value $e^{-2}$. Since this is also the limiting ratio without derangement condition, somehow this is suggesting that deranging and avoiding neighbors are approximately independent. Of course, this seems quite a hard problem. – Sangchul Lee Jun 05 '17 at 14:30
  • @SangchulLee, could you add this sequence to the OEIS with the Mathematica code? $0, 0, 0, 2, 4, 29, 241, 1909, 17177, \cdots$. – Peter Kagey Jun 06 '17 at 20:55
  • @PeterKagey, My algorithm was pretty awful in terms of performance, I prepared all the possible permutations using Permutations function and devised the test function to sift up the case of interest. I am pretty sure there is a better way, for instance tweaking Fisher-Yates shuffling algorithm. – Sangchul Lee Jun 06 '17 at 21:31
  • @SangchulLee, My implementation only returns two derangements for $n = 5$: $[3,1,5,2,4]$ and $[2,4,1,5,3]$. What are the other two that you get? – Peter Kagey Jun 06 '17 at 22:25
  • @PeterKagey, I checked my test function and it missed the condition for whether $n$ is a fixed point or not. That being said, you listed all the case for $n = 5$. Now I get $$ 0, 0, 0, 2, 2, 27, 214, 1695, 15482, \cdots. $$ Hope this matches your result as well. – Sangchul Lee Jun 06 '17 at 23:30
  • I've added this to the OEIS as sequence A288208. (At the time of this comment, it is still a draft.) (Draft) (Published) – Peter Kagey Jun 06 '17 at 23:57
  • @PeterKagey I just discovered this sequence, do you know any direct formula to calculate the values? Thank you – user967210 Feb 24 '25 at 15:00
  • @user967210—I don't know of any, but you might reach out to Max Alekseyev, who added terms a(17)–a(30) just a couple weeks ago. – Peter Kagey Feb 24 '25 at 18:26

1 Answers1

7

The limiting ratio is not hard to derive via the method of moments.

In a random permutation $\sigma$ of $\{1,2,\dots,n\}$ (not necessarily a derangement), let $X_n$ be

  • the total number of integers $i$, $1 \le i \le n$, such that $\sigma(i) = i$, plus
  • the total number of integers $i$, $1 \le i \le n-1$, such that $\sigma(i+1) = \sigma(i)+1$, plus
  • the total number of integers $i$, $1 \le i \le n-1$, such that $\sigma(i) = \sigma(i+1)+1$.

We'll show that for any fixed $k$, we have $\lim_{n \to \infty} \mathbb E[\binom{X_n}{k}] = \frac{3^k}{k!}.$ If a random variable $X$ is Poisson with mean $3$, we also have $\mathbb E[\binom{X}{k}] = \frac{3^k}{k!}$. The Poisson distribution is determined by its moments, so it follows that $X_n$ converges in distribution to $X$, and in particular $\lim_{n \to \infty} \Pr[X_n = 0] = e^{-3}$.

To see this, note that $X_n$ is the sum of $3n-2$ indicator variables corresponding to each of the events (listed above) that $X_n$ counts, so $\binom{X_n}{k}$ counts the number of size-$k$ sets of events that occur. The calculation is difficult to do exactly but more or less straightforward asymptotically. Out of the $\binom{3n-2}{k}$ choices of $k$ events, $(1-o(1))\binom{3n-2}{k}$ never involve the same value $\sigma(i)$ more than once, so the probability that they occur is $(1+o(1))n^{-k}$. These contribute $(1+o(1))\frac{3^k}{k!}$ to the expected value $\mathbb E[\binom{X}{k}]$, which is all that we wanted.

So it remains to reassure ourselves that the contribution from all other choices of $k$ events is insignificant in the limit. Muddying the picture, some groups of $j \le k$ events that overlap have a significantly higher probability than a group of $j$ nonoverlapping events. For example, the events that $\sigma(3)=3$, that $\sigma(4)=4$, and that $\sigma(4)=\sigma(3)+1$ have this property.

However, we can never win this way, because there are $O(n)$ ways to pick that a group of $j$ overlapping events (with a constant factor depending on $k$) but a $O(n^{-2})$ chance that all of the events occur (since at least two values of $\sigma$ are involved). So for any possible overlapping structure, the contribution to $\mathbb E[\binom{X}{k}]$ is $O(n^{-1})$, and there is a constant number (depending only on $k$) of overlapping structures.

As a result, we can ignore all overlaps, conclude that $\lim_{n\to\infty}\mathbb E[\binom{X}{k}] = \frac{3^k}{k!}$, and deduce that $\lim_{n\to\infty} \Pr[X_n = 0] = e^{-3}$. Therefore $$\lim_{n\to\infty} \Pr[X_n = 0 \mid \text{$\sigma$ is a derangement}] = \lim_{n\to\infty} \frac{\Pr[X_n=0]}{\Pr[\text{$\sigma$ is a derangement}]} = \frac{e^{-3}}{e^{-1}} = e^{-2}.$$

Misha Lavrov
  • 159,700