Fixed Points in Random Permutations

0. Introduction and problem statement

A standard question in probability theory and combinatorics is to determine the probability of having a specific number of fixed points in a random permutation. For instance, a real life problem that features this question is given in [1, Chapter 2 Exercises] and reads as follows.

Suppose nn people leave their coats at the the theatre wardrobe prior to the show and, due to a power outage, they each get handed a coat randomly in the dark later. What is the probability that knk \leq n people then have their own coat?

There are several interesting approaches to solving this and recently, I found another one that reminded me of Fibonacci numbers. With those you have the relationship

fn+1=fn+fn1,f2=1=f1,n2

that can be transformed into the matrix representation

(fn+1fn)=(1110)(fnfn1)=(1110)n(f2f1)

Diagonalizing that matrix then gives an explicit expression for fn+1f_{n + 1}.

In the following I’ll show that a similar recurrence relation also holds for the number of fixed points in a permutation.

1. Definitions and Notation

First, we define the necessary terminology and notation.

Definition. A bijective function π:{1,,n}{1,,n}\pi: \{1, \ldots, n\} \to \{1, \ldots, n\} is called a permutation.

For n=3n = 3, an example for a permutation would be 12,23,311 \rightarrow 2, 2 \rightarrow 3, 3 \rightarrow 1 or

π(1)=2,π(2)=1,π(3)=2\pi(1) = 2, \pi(2) = 1, \pi(3) = 2

A common way to denote permutations is by way of permutation tables, e.g. π=(123231).

Definition. A fixed point of a permutation π\pi is an element l{1,,n}l \in \{1, \ldots, n\} for which it holds that π(l)=l\pi(l) = l.

For example, there are no fixed points in the above permutation because π(l)l\pi(l) \neq l for all l{1,,3}l \in \{1, \ldots, 3\}.

To derive the probability of having kk fixed points in a permutation we need to set up (i). an appropriate probability space (Ω,A,P)(\Omega, \mathcal{A}, P) and (ii). a random variable XX that maps permutations to the number of permutations kk.

(i). Obviously, it is Ω=Sn\Omega = \mathscr{S}^n as we care about permutations and Sn\mathscr{S}^n is the set of all permutations with nn elements. Since it clearly holds that Sn=n!<\vert \mathscr{S}^n \vert = n! < \infty for n<n < \infty, we set A=P(Sn)\mathcal{A} = \mathcal{P}(\mathscr{S}^n). Furthermore, we assume that each permutation is equally likely to occur, i.e., uniformly distributed. Hence, PΩ=UΩP_{\Omega} = \mathcal{U}_{\Omega}.

In sum, our probability space is (Sn,P(Sn),UΩ)(\mathscr{S}^n, \mathcal{P}(\mathscr{S}^n), \mathcal{U}_{\Omega}).

(ii). Consider the random variable X:Sn{0,,n}X: \mathscr{S}^n \to \{0, \ldots, n\} mit X(π)=i=1N1i=π(i)X(\pi) = \sum\limits_{i = 1}^{N} 1_{{i = \pi(i)}}. It maps each permutation to its number of fixed points and is thus appropriate for our task.

2. Solving the problem theoretically

Because of the uniformness distribution on Sn\mathscr{S}^n with PΩ=UΩP_{\Omega} = \mathcal{U}_{\Omega} and according to basic results of probability theory it holds that PX(k)=PΩ(X1(k))=|X(ω)=k||Ω|=|X(ω)=k|n! according to basic results of probability theory.

The problem now reduces to deriving an explicit expression for X(π)=k\vert X(\pi) = k\vert, i.e. the number of permutations of nn elements that exhibit kk fixed points.

Define T0,nT^{0, n} as the number of permutations of nn elements without any fixed points. These are all permutations that don’t have exactly one fixed point, exactly two fixed points, \ldots, exactly n1=nn - 1 = n fixed points.

To construct a permutation with exactly one fixed point, we fix one element and permutate the remaining n1n - 1 elements in such a way that there no fixed points. There are T0,n1T^{0, n - 1} permutations to choose from. Since you can choose (n1)=n\binom{n}{1} = n different 1-element sets out of nn elements, there in total (n1)T0,n1\binom{n}{1}T^{0, n - 1} permutations that exhibit exactly one fixed point. Analogously, there are (n2)T0,n2\binom{n}{2}T^{0, n - 2} permutations that have exactly two fixed points and so on for any knk \leq n.

Since for nn elements, there are n!n! permutations in total, we can recover the number of fixed-point free permutations of nn elements as

T0,n=n!(n1)T0,n1(n2)T0,n2

Here the connection to Fibonacci numbers emerges. The expression above is recursive. Therefore, we’ll transform the equation into matrix format,

T=(T0,nT0,n1 T0,1)=(n!(n1)! 1)(0(n1)(n2)100(n11)10001)(T0,nT0,n1 T0,1)

Some algebraic manipulations give

T=(1(n1)(n2)101(n11)10001)1A1(n!(n1)! 1)(1)

Note that det(A)=λ1λn\det(A) = \lambda_1\cdot \ldots\cdot \lambda_n. But since AA is diagonal, the eigenvalues are the diagonal elements and as such det(A)=1>0\det(A) = 1 > 0, i.e. AA is indeed invertible!

But AA is the so-called Pascal matrix with known inverse A1=(0(n1)(n2)100(n11)10001)1=(0(n1)(n2)100(n11)1 0001)=(1)j+1Aij

After multiplying the inverse with the vector on the right-hand side in (1), we arrive at

T0,n=i=0n(1)i(ni)(ni)!

Finally, the number of permutations with kk fixed points is now immediately derived as

|X=k|=(nk)T0,nk=(nk)i=0nk(1)i(nki)(nki)!

and with it the desired probability as

PX(k)=PΩ(X1(k))=|X(π)=k||Sn|=|X(π)=k|n!=(nk)i=0nk(1)i(nki)(nki)!n!=1k!(nk)!i=0nk(1)i(nki)(nki)!=1k!(nk)!i=0nk(1)i(nk)!i!(nki)!(nki)!=1k!i=0nk(1)i1i!

To return to the initial real-life application. For n=5n = 5 coats und k=1k = 1, i.e. only one person receives her own coat, the probability reads as

PX(1)=11!i=04(1)i1i!=11+1216+124=924=37.5%

3. Solving the problem computationally

The following R code produces simulation results that closely resemble the theoretical assertions.

Anzahl.Mantel = 5
Anzahl.Rep = 1000

Mantel = replicate(Anzahl.Rep, {
sample(1:Anzahl.Mantel, Anzahl.Mantel, replace = FALSE)
})

Test = matrix(1:Anzahl.Mantel, nrow = Anzahl.Mantel, ncol = Anzahl.Rep)

Vergleich = (Mantel == Test) %>% 
                  t() %>% 
             as.data.frame() %>%
             mutate(Anzahl = rowSums(.))

table(Vergleich$Anzahl)/sum(table(Vergleich$Anzahl))

The resulting distribution is as follows.

> table(Vergleich$Anzahl)/sum(table(Vergleich$Anzahl))

0     1     2     3     5 
0.397 0.365 0.149 0.079 0.010 

The difference to the true theoretical results is hence small after already 1000 draws.

4. Epilogue

It can be shown that the number of fixed points kk in a permutation of nn elements is poisson-distributed for nn \to \infty. Also, the number of permutations without any fixed points is equivalent to the rencontre problem. The latter is also solvable by the inclusion-exclusion principle, see [1, Chapter 1 exercises].

References

[1] H.-O. Georgii (2014): Stochastik. Eine Einführung.