- Source: Random permutation statistics
The statistics of random permutations, such as the cycle structure of a random permutation are of fundamental importance in the analysis of algorithms, especially of sorting algorithms, which operate on random permutations. Suppose, for example, that we are using quickselect (a cousin of quicksort) to select a random element of a random permutation. Quickselect will perform a partial sort on the array, as it partitions the array according to the pivot. Hence a permutation will be less disordered after quickselect has been performed. The amount of disorder that remains may be analysed with generating functions. These generating functions depend in a fundamental way on the generating functions of random permutation statistics. Hence it is of vital importance to compute these generating functions.
The article on random permutations contains an introduction to random permutations.
The fundamental relation
Permutations are sets of labelled cycles. Using the labelled case of the Flajolet–Sedgewick fundamental theorem and writing
P
{\displaystyle \scriptstyle {\mathcal {P}}}
for the set of permutations and
Z
{\displaystyle \scriptstyle {\mathcal {Z}}}
for the singleton set, we have
SET
(
CYC
(
Z
)
)
=
P
.
{\displaystyle \operatorname {SET} (\operatorname {CYC} ({\mathcal {Z}}))={\mathcal {P}}.}
Translating into exponential generating functions (EGFs), we have
exp
(
log
1
1
−
z
)
=
1
1
−
z
{\displaystyle \exp \left(\log {\frac {1}{1-z}}\right)={\frac {1}{1-z}}}
where we have used the fact that the EGF of the combinatorial species of permutations (there are n! permutations of n elements) is
∑
n
≥
0
n
!
n
!
z
n
=
1
1
−
z
.
{\displaystyle \sum _{n\geq 0}{\frac {n!}{n!}}z^{n}={\frac {1}{1-z}}.}
This one equation allows one to derive a large number of permutation statistics. Firstly, by dropping terms from
SET
{\displaystyle \scriptstyle \operatorname {SET} }
, i.e. exp, we may constrain the number of cycles that a permutation contains, e.g. by restricting the EGF to
SET
2
{\displaystyle \scriptstyle \operatorname {SET} _{2}}
we obtain permutations containing two cycles. Secondly, note that the EGF of labelled cycles, i.e. of
CYC
(
Z
)
{\displaystyle \scriptstyle \operatorname {CYC} ({\mathcal {Z}})}
, is
∑
k
≥
1
(
k
−
1
)
!
z
k
k
!
=
∑
k
≥
1
z
k
k
=
log
1
1
−
z
{\displaystyle \sum _{k\geq 1}{\frac {(k-1)!z^{k}}{k!}}=\sum _{k\geq 1}{\frac {z^{k}}{k}}=\log {\frac {1}{1-z}}}
because there are k! / k labelled cycles. This means that by dropping terms from this generating function, we may constrain the size of the cycles that occur in a permutation and obtain an EGF of the permutations containing only cycles of a given size.
Instead of removing and selecting cycles, one can also put different weights on different size cycles. If
b
:
N
→
R
{\displaystyle b:\mathbb {N} \rightarrow \mathbb {R} }
is a weight function that depends only on the size k of the cycle and for brevity we write
b
(
σ
)
=
∑
c
∈
σ
b
(
c
)
,
{\displaystyle b(\sigma )=\sum _{c\in \sigma }b(c),}
defining the value of b for a permutation
σ
{\displaystyle \sigma }
to be the sum of its values on the cycles, then we may mark cycles of length k with ub(k) and obtain a two-variable generating function
g
(
z
,
u
)
=
1
+
∑
n
≥
1
(
∑
σ
∈
S
n
u
b
(
σ
)
)
z
n
n
!
=
exp
∑
k
≥
1
u
b
(
k
)
z
k
k
{\displaystyle g(z,u)=1+\sum _{n\geq 1}\left(\sum _{\sigma \in S_{n}}u^{b(\sigma )}\right){\frac {z^{n}}{n!}}=\exp \sum _{k\geq 1}u^{b(k)}{\frac {z^{k}}{k}}}
This is a "mixed" generating function: it is an exponential generating function in z and an ordinary generating function in the secondary parameter u. Differentiating and evaluating at u = 1, we have
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
1
b
(
k
)
z
k
k
=
∑
n
≥
1
(
∑
σ
∈
S
n
b
(
σ
)
)
z
n
n
!
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq 1}b(k){\frac {z^{k}}{k}}=\sum _{n\geq 1}\left(\sum _{\sigma \in S_{n}}b(\sigma )\right){\frac {z^{n}}{n!}}}
This is the probability generating function of the expectation of b. In other words, the coefficient of
z
n
{\displaystyle z^{n}}
in this power series is the expected value of b on permutations in
S
n
{\displaystyle S_{n}}
, given that each permutation is chosen with the same probability
1
/
n
!
{\displaystyle 1/n!}
.
This article uses the coefficient extraction operator [zn], documented on the page for formal power series.
Number of permutations that are involutions
An involution is a permutation σ so that σ2 = 1 under permutation composition. It follows that σ may only contain cycles of length one or two, i.e. the exponential generating function g(z) of these permutations is
g
(
z
)
=
exp
(
z
+
1
2
z
2
)
.
{\displaystyle g(z)=\exp \left(z+{\frac {1}{2}}z^{2}\right).}
This gives the explicit formula for the total number
I
(
n
)
{\displaystyle I(n)}
of involutions among the permutations σ ∈ Sn:
I
(
n
)
=
n
!
[
z
n
]
g
(
z
)
=
n
!
∑
a
+
2
b
=
n
1
a
!
2
b
b
!
=
n
!
∑
b
=
0
⌊
n
/
2
⌋
1
(
n
−
2
b
)
!
2
b
b
!
.
{\displaystyle I(n)=n![z^{n}]g(z)=n!\sum _{a+2b=n}{\frac {1}{a!\;2^{b}\;b!}}=n!\sum _{b=0}^{\lfloor n/2\rfloor }{\frac {1}{(n-2b)!\;2^{b}\;b!}}.}
Dividing by n! yields the probability that a random permutation is an involution.
These numbers are known as telephone numbers.
Number of permutations that are mth roots of unity
This generalizes the concept of an involution. An mth root of unity is a permutation σ so that σm = 1 under permutation composition. Now every time we apply σ we move one step in parallel along all of its cycles. A cycle of length d applied d times produces the identity permutation on d elements (d fixed points) and d is the smallest value to do so. Hence m must be a multiple of all cycle sizes d, i.e. the only possible cycles are those whose length d is a divisor of m. It follows that the EGF g(x) of these permutations is
g
(
z
)
=
exp
(
∑
d
∣
m
z
d
d
)
.
{\displaystyle g(z)=\exp \left(\sum _{d\mid m}{\frac {z^{d}}{d}}\right).}
When m = p, where p is prime, this simplifies to
n
!
[
z
n
]
g
(
z
)
=
n
!
∑
a
+
p
b
=
n
1
a
!
p
b
b
!
=
n
!
∑
b
=
0
⌊
n
/
p
⌋
1
(
n
−
p
b
)
!
p
b
b
!
.
{\displaystyle n![z^{n}]g(z)=n!\sum _{a+pb=n}{\frac {1}{a!\;p^{b}\;b!}}=n!\sum _{b=0}^{\lfloor n/p\rfloor }{\frac {1}{(n-pb)!\;p^{b}\;b!}}.}
Number of permutations of order exactly k
This one can be done by Möbius inversion. Working with the same concept as in the previous entry we note that the combinatorial species
Q
{\displaystyle {\mathcal {Q}}}
of permutations whose order divides k is given by
Q
=
SET
(
∑
d
∣
k
CYC
=
d
(
Z
)
)
.
{\displaystyle {\mathcal {Q}}=\operatorname {SET} \left(\sum _{d\mid k}\operatorname {CYC} _{=d}({\mathcal {Z}})\right).}
Translation to exponential generating functions we obtain the EGF of permutations whose order divides k, which is
Q
k
(
z
)
=
exp
(
∑
d
∣
k
z
d
d
)
.
{\displaystyle Q_{k}(z)=\exp \left(\sum _{d\mid k}{\frac {z^{d}}{d}}\right).}
Now we can use this generating function to count permutations of order exactly k. Let
p
n
,
d
{\displaystyle p_{n,d}}
be the number of permutations on n whose order is exactly d and
q
n
,
k
{\displaystyle q_{n,k}}
the number of permutations on n the permutation count whose order divides k.
Then we have
∑
d
|
k
p
n
,
d
=
q
n
,
k
.
{\displaystyle \sum _{d|k}p_{n,d}=q_{n,k}.}
It follows by Möbius inversion that
∑
d
|
k
q
n
,
d
×
μ
(
k
/
d
)
=
p
n
,
k
.
{\displaystyle \sum _{d|k}q_{n,d}\times \mu (k/d)=p_{n,k}.}
Therefore, we have the EGF
Q
(
z
)
=
∑
d
∣
k
μ
(
k
/
d
)
×
Q
d
(
z
)
=
∑
d
∣
k
μ
(
k
/
d
)
exp
(
∑
m
∣
d
z
m
m
)
.
{\displaystyle Q(z)=\sum _{d\mid k}\mu (k/d)\times Q_{d}(z)=\sum _{d\mid k}\mu (k/d)\exp \left(\sum _{m\mid d}{\frac {z^{m}}{m}}\right).}
The desired count is then given by
n
!
[
z
n
]
Q
(
z
)
.
{\displaystyle n![z^{n}]Q(z).}
This formula produces e.g. for k = 6 the EGF
Q
(
z
)
=
e
z
−
e
z
+
1
/
2
z
2
−
e
z
+
1
/
3
z
3
+
e
z
+
1
/
2
z
2
+
1
/
3
z
3
+
1
/
6
z
6
{\displaystyle Q(z)={\rm {e}}^{z}-{\rm {e}}^{z+1/2\,z^{2}}-{\rm {e}}^{z+1/3\,z^{3}}+{\rm {e}}^{z+1/2\,z^{2}+1/3\,z^{3}+1/6\,z^{6}}}
with the sequence of values starting at n = 5
20
,
240
,
1470
,
10640
,
83160
,
584640
,
4496030
,
42658440
,
371762820
,
3594871280
,
…
{\displaystyle 20,240,1470,10640,83160,584640,4496030,42658440,371762820,3594871280,\ldots }
(sequence A061121 in the OEIS)
For k = 8 we get the EGF
Q
(
z
)
=
−
e
z
+
1
/
2
z
2
+
1
/
4
z
4
+
e
z
+
1
/
2
z
2
+
1
/
4
z
4
+
1
/
8
z
8
{\displaystyle Q(z)=-{\rm {e}}^{z+1/2\,z^{2}+1/4\,z^{4}}+{\rm {e}}^{z+1/2\,z^{2}+1/4\,z^{4}+1/8\,z^{8}}}
with the sequence of values starting at n = 8
5040
,
45360
,
453600
,
3326400
,
39916800
,
363242880
,
3874590720
,
34767532800
,
…
{\displaystyle 5040,45360,453600,3326400,39916800,363242880,3874590720,34767532800,\ldots }
(sequence A061122 in the OEIS)
Finally for k = 12 we get the EGF
Q
(
z
)
=
e
z
+
1
/
2
z
2
−
e
z
+
1
/
2
z
2
+
1
/
4
z
4
−
e
z
+
1
/
2
z
2
+
1
/
3
z
3
+
1
/
6
z
6
+
e
z
+
1
/
2
z
2
+
1
/
3
z
3
+
1
/
4
z
4
+
1
/
6
z
6
+
1
/
12
z
12
{\displaystyle Q(z)={\rm {e}}^{z+1/2\,z^{2}}-{\rm {e}}^{z+1/2\,z^{2}+1/4\,z^{4}}-{\rm {e}}^{z+1/2\,z^{2}+1/3\,{z}^{3}+1/6\,z^{6}}+{\rm {e}}^{z+1/2\,z^{2}+1/3\,z^{3}+1/4\,z^{4}+1/6\,z^{6}+1/12\,z^{12}}}
with the sequence of values starting at n = 7
420
,
3360
,
30240
,
403200
,
4019400
,
80166240
,
965284320
,
12173441280
,
162850287600
,
…
{\displaystyle 420,3360,30240,403200,4019400,80166240,965284320,12173441280,162850287600,\ldots }
(sequence A061125 in the OEIS)
Number of permutations that are derangements
Suppose there are n people at a party, each of whom brought an umbrella. At the end of the party everyone picks an umbrella out of the stack of umbrellas and leaves. What is the probability that no one left with his/her own umbrella? This problem is equivalent to counting permutations with no fixed points (called derangements), and hence the EGF, where we subtract out fixed points (cycles of length 1) by removing the term z from the fundamental relation is
exp
(
−
z
+
∑
k
≥
1
z
k
k
)
=
e
−
z
1
−
z
.
{\displaystyle \exp \left(-z+\sum _{k\geq 1}{\frac {z^{k}}{k}}\right)={\frac {e^{-z}}{1-z}}.}
Multiplication by
1
/
(
1
−
z
)
{\displaystyle 1/(1-z)}
sums the coefficients of
e
−
z
{\displaystyle e^{-z}}
, so
D
(
n
)
{\displaystyle D(n)}
, the total number of derangements, is given by:
D
(
n
)
=
n
!
∑
k
=
0
n
(
−
1
)
k
k
!
≈
n
!
e
.
{\displaystyle D(n)=n!\sum _{k=0}^{n}{\frac {(-1)^{k}}{k!}}\;\approx \;{\frac {n!}{e}}.}
Hence there are about
n
!
/
e
{\displaystyle n!/e}
derangements and the probability that a random permutation is a derangement is
1
/
e
.
{\displaystyle 1/e.}
This result may also be proved by inclusion–exclusion. Using the sets
A
p
{\displaystyle A_{p}}
where
1
≤
p
≤
n
{\displaystyle {\begin{matrix}1\leq p\leq n\end{matrix}}}
to denote the set of permutations that fix p, we have
|
⋃
p
A
p
|
=
∑
p
|
A
p
|
−
∑
p
<
q
|
A
p
∩
A
q
|
+
∑
p
<
q
<
r
|
A
p
∩
A
q
∩
A
r
|
−
⋯
±
|
A
p
∩
⋯
∩
A
s
|
.
{\displaystyle \left|\bigcup _{p}A_{p}\right|=\sum _{p}\left|A_{p}\right|\;-\;\sum _{p
This formula counts the number of permutations that have at least one fixed point.
The cardinalities are as follows:
|
A
p
|
=
(
n
−
1
)
!
,
|
A
p
∩
A
q
|
=
(
n
−
2
)
!
,
|
A
p
∩
A
q
∩
A
r
|
=
(
n
−
3
)
!
,
…
{\displaystyle \left|A_{p}\right|=(n-1)!\;,\;\;\left|A_{p}\cap A_{q}\right|=(n-2)!\;,\;\;\left|A_{p}\cap A_{q}\cap A_{r}\right|=(n-3)!\;,\;\ldots }
Hence the number of permutations with no fixed point is
n
!
−
(
n
1
)
(
n
−
1
)
!
+
(
n
2
)
(
n
−
2
)
!
−
(
n
3
)
(
n
−
3
)
!
+
⋯
±
(
n
n
)
(
n
−
n
)
!
{\displaystyle n!\;\;-\;\;{n \choose 1}(n-1)!\;\;+\;\;{n \choose 2}(n-2)!\;\;-\;\;{n \choose 3}(n-3)!\;\;+\;\;\cdots \;\;\pm \;\;{n \choose n}(n-n)!}
or
n
!
(
1
−
1
1
!
+
1
2
!
−
1
3
!
+
⋯
±
1
n
!
)
=
n
!
∑
k
=
0
n
(
−
1
)
k
k
!
{\displaystyle n!\left(1-{\frac {1}{1!}}+{\frac {1}{2!}}-{\frac {1}{3!}}+\cdots \pm {\frac {1}{n!}}\right)=n!\sum _{k=0}^{n}{\frac {(-1)^{k}}{k!}}}
and we have the claim.
There is a generalization of these numbers, which is known as rencontres numbers, i.e.
the number
D
(
n
,
m
)
{\displaystyle D(n,m)}
of permutations of
[
n
]
{\displaystyle [n]}
containing m fixed points.
The corresponding EGF is obtained by marking cycles of size one with the variable u,
i.e. choosing b(k) equal to one for
k
=
1
{\displaystyle k=1}
and zero otherwise, which yields
the generating function
g
(
z
,
u
)
{\displaystyle g(z,u)}
of the set of permutations by the number of fixed points:
g
(
z
,
u
)
=
exp
(
−
z
+
u
z
+
∑
k
≥
1
z
k
k
)
=
e
−
z
1
−
z
e
u
z
.
{\displaystyle g(z,u)=\exp \left(-z+uz+\sum _{k\geq 1}{\frac {z^{k}}{k}}\right)={\frac {e^{-z}}{1-z}}e^{uz}.}
It follows that
[
u
m
]
g
(
z
,
u
)
=
e
−
z
1
−
z
z
m
m
!
{\displaystyle [u^{m}]g(z,u)={\frac {e^{-z}}{1-z}}{\frac {z^{m}}{m!}}}
and hence
D
(
n
,
m
)
=
n
!
[
z
n
]
[
u
m
]
g
(
z
,
u
)
=
n
!
m
!
[
z
n
−
m
]
e
−
z
1
−
z
=
n
!
m
!
∑
k
=
0
n
−
m
(
−
1
)
k
k
!
.
{\displaystyle D(n,m)=n![z^{n}][u^{m}]g(z,u)={\frac {n!}{m!}}[z^{n-m}]{\frac {e^{-z}}{1-z}}={\frac {n!}{m!}}\sum _{k=0}^{n-m}{\frac {(-1)^{k}}{k!}}.}
This immediately implies that
D
(
n
,
m
)
=
(
n
m
)
D
(
n
−
m
,
0
)
and
D
(
n
,
m
)
n
!
≈
e
−
1
m
!
{\displaystyle D(n,m)={n \choose m}D(n-m,0)\;\;{\text{ and }}\;\;{\frac {D(n,m)}{n!}}\approx {\frac {e^{-1}}{m!}}}
for n large, m fixed.
Order of a random permutation
If P is a permutation, the order of P is the smallest positive integer n for which
P
n
{\displaystyle P^{n}}
is the identity permutation. This is the least common multiple of the lengths of the cycles of P.
A theorem of Goh and Schmutz
states that if
μ
n
{\displaystyle \mu _{n}}
is the expected order of a random permutation of size n, then
log
μ
n
∼
c
n
log
n
{\displaystyle \log \mu _{n}\sim c{\sqrt {\frac {n}{\log n}}}}
where the constant c is
2
2
∫
0
∞
log
log
(
e
1
−
e
−
t
)
d
t
≈
1.1178641511899
{\displaystyle 2{\sqrt {2\int _{0}^{\infty }\log \log \left({\frac {e}{1-e^{-t}}}\right)dt}}\approx 1.1178641511899}
Derangements containing an even and an odd number of cycles
We can use the same construction as in the previous section to compute the number of derangements
D
0
(
n
)
{\displaystyle D_{0}(n)}
containing an even number of cycles and the number
D
1
(
n
)
{\displaystyle D_{1}(n)}
containing an odd number of cycles. To do this we need to mark all cycles and subtract fixed points, giving
g
(
z
,
u
)
=
exp
(
−
u
z
+
u
log
1
1
−
z
)
=
exp
(
−
u
z
)
(
1
1
−
z
)
u
.
{\displaystyle g(z,u)=\exp \left(-uz+u\log {\frac {1}{1-z}}\right)=\exp(-uz)\left({\frac {1}{1-z}}\right)^{u}.}
Now some very basic reasoning shows that the EGF
q
(
z
)
{\displaystyle q(z)}
of
D
0
(
n
)
{\displaystyle D_{0}(n)}
is given by
q
(
z
)
=
1
2
×
g
(
z
,
−
1
)
+
1
2
×
g
(
z
,
1
)
=
1
2
exp
(
−
z
)
1
1
−
z
+
1
2
exp
(
z
)
(
1
−
z
)
.
{\displaystyle q(z)={\frac {1}{2}}\times g(z,-1)+{\frac {1}{2}}\times g(z,1)={\frac {1}{2}}\exp(-z){\frac {1}{1-z}}+{\frac {1}{2}}\exp(z)(1-z).}
We thus have
D
0
(
n
)
=
n
!
[
z
n
]
q
(
z
)
=
1
2
n
!
∑
k
=
0
n
(
−
1
)
k
k
!
+
1
2
n
!
1
n
!
−
1
2
n
!
1
(
n
−
1
)
!
{\displaystyle D_{0}(n)=n![z^{n}]q(z)={\frac {1}{2}}n!\sum _{k=0}^{n}{\frac {(-1)^{k}}{k!}}+{\frac {1}{2}}n!{\frac {1}{n!}}-{\frac {1}{2}}n!{\frac {1}{(n-1)!}}}
which is
1
2
n
!
∑
k
=
0
n
(
−
1
)
k
k
!
+
1
2
(
1
−
n
)
∼
1
2
e
n
!
+
1
2
(
1
−
n
)
.
{\displaystyle {\frac {1}{2}}n!\sum _{k=0}^{n}{\frac {(-1)^{k}}{k!}}+{\frac {1}{2}}(1-n)\sim {\frac {1}{2e}}n!+{\frac {1}{2}}(1-n).}
Subtracting
D
0
(
n
)
{\displaystyle D_{0}(n)}
from
D
(
n
)
{\displaystyle D(n)}
, we find
D
1
(
n
)
=
1
2
n
!
∑
k
=
0
n
(
−
1
)
k
k
!
−
1
2
(
1
−
n
)
.
{\displaystyle D_{1}(n)={\frac {1}{2}}n!\sum _{k=0}^{n}{\frac {(-1)^{k}}{k!}}-{\frac {1}{2}}(1-n).}
The difference of these two (
D
0
(
n
)
{\displaystyle D_{0}(n)}
and
D
1
(
n
)
{\displaystyle D_{1}(n)}
) is
n
−
1.
{\displaystyle n-1.}
One hundred prisoners
A prison warden wants to make room in his prison and is considering liberating one hundred prisoners, thereby freeing one hundred cells. He therefore assembles one hundred prisoners and asks them to play the following game: he lines up one hundred urns in a row, each containing the name of one prisoner, where every prisoner's name occurs exactly once. The game is played as follows: every prisoner is allowed to look inside fifty urns. If he or she does not find his or her name in one of the fifty urns, all prisoners will immediately be executed, otherwise the game continues. The prisoners have a few moments to decide on a strategy, knowing that once the game has begun, they will not be able to communicate with each other, mark the urns in any way or move the urns or the names inside them. Choosing urns at random, their chances of survival are almost zero, but there is a strategy giving them a 30% chance of survival, assuming that the names are assigned to urns randomly – what is it?
First of all, the survival probability using random choices is
(
(
99
49
)
(
100
50
)
)
100
=
1
2
100
,
{\displaystyle \left({\frac {99 \choose 49}{100 \choose 50}}\right)^{100}={\frac {1}{2^{100}}},}
so this is definitely not a practical strategy.
The 30% survival strategy is to consider the contents of the urns to be a permutation of the prisoners, and traverse cycles. To keep the notation simple, assign a number to each prisoner, for example by sorting their names alphabetically. The urns may thereafter be considered to contain numbers rather than names. Now clearly the contents of the urns define a permutation. The first prisoner opens the first urn. If he finds his name, he has finished and survives. Otherwise he opens the urn with the number he found in the first urn. The process repeats: the prisoner opens an urn and survives if he finds his name, otherwise he opens the urn with the number just retrieved, up to a limit of fifty urns. The second prisoner starts with urn number two, the third with urn number three, and so on. This strategy is precisely equivalent to a traversal of the cycles of the permutation represented by the urns. Every prisoner starts with the urn bearing his number and keeps on traversing his cycle up to a limit of fifty urns. The number of the urn that contains his number is the pre-image of that number under the permutation. Hence the prisoners survive if all cycles of the permutation contain at most fifty elements. We have to show that this probability is at least 30%.
Note that this assumes that the warden chooses the permutation randomly; if the warden anticipates this strategy, he can simply choose a permutation with a cycle of length 51. To overcome this, the prisoners may agree in advance on a random permutation of their names.
We consider the general case of
2
n
{\displaystyle 2n}
prisoners and
n
{\displaystyle n}
urns being opened. We first calculate the complementary probability, i.e. that there is a cycle of more than
n
{\displaystyle n}
elements. With this in mind, we introduce
g
(
z
,
u
)
=
exp
(
z
+
z
2
2
+
z
3
3
+
⋯
+
u
z
n
+
1
n
+
1
+
u
z
n
+
2
n
+
2
+
⋯
)
{\displaystyle g(z,u)=\exp \left(z+{\frac {z^{2}}{2}}+{\frac {z^{3}}{3}}+\cdots +u{\frac {z^{n+1}}{n+1}}+u{\frac {z^{n+2}}{n+2}}+\cdots \right)}
or
1
1
−
z
exp
(
(
u
−
1
)
(
z
n
+
1
n
+
1
+
z
n
+
2
n
+
2
+
⋯
)
)
,
{\displaystyle {\frac {1}{1-z}}\exp \left((u-1)\left({\frac {z^{n+1}}{n+1}}+{\frac {z^{n+2}}{n+2}}+\cdots \right)\right),}
so that the desired probability is
[
z
2
n
]
[
u
]
g
(
z
,
u
)
,
{\displaystyle [z^{2n}][u]g(z,u),}
because the cycle of more than
n
{\displaystyle n}
elements will necessarily be unique. Using the fact that
2
(
n
+
1
)
>
2
n
{\displaystyle 2(n+1)>2n}
, we find that
[
z
2
n
]
[
u
]
g
(
z
,
u
)
=
[
z
2
n
]
[
u
]
1
1
−
z
(
1
+
(
u
−
1
)
(
z
n
+
1
n
+
1
+
z
n
+
2
n
+
2
+
⋯
)
)
,
{\displaystyle [z^{2n}][u]g(z,u)=[z^{2n}][u]{\frac {1}{1-z}}\left(1+(u-1)\left({\frac {z^{n+1}}{n+1}}+{\frac {z^{n+2}}{n+2}}+\cdots \right)\right),}
which yields
[
z
2
n
]
[
u
]
g
(
z
,
u
)
=
[
z
2
n
]
1
1
−
z
(
z
n
+
1
n
+
1
+
z
n
+
2
n
+
2
+
⋯
)
=
∑
k
=
n
+
1
2
n
1
k
=
H
2
n
−
H
n
.
{\displaystyle [z^{2n}][u]g(z,u)=[z^{2n}]{\frac {1}{1-z}}\left({\frac {z^{n+1}}{n+1}}+{\frac {z^{n+2}}{n+2}}+\cdots \right)=\sum _{k=n+1}^{2n}{\frac {1}{k}}=H_{2n}-H_{n}.}
Finally, using an integral estimate such as Euler–Maclaurin summation, or the asymptotic expansion of the nth harmonic number, we obtain
H
2
n
−
H
n
∼
log
2
−
1
4
n
+
1
16
n
2
−
1
128
n
4
+
1
256
n
6
−
17
4096
n
8
+
⋯
,
{\displaystyle H_{2n}-H_{n}\sim \log 2-{\frac {1}{4n}}+{\frac {1}{16n^{2}}}-{\frac {1}{128n^{4}}}+{\frac {1}{256n^{6}}}-{\frac {17}{4096n^{8}}}+\cdots ,}
so that
[
z
2
n
]
[
u
]
g
(
z
,
u
)
<
log
2
and
1
−
[
z
2
n
]
[
u
]
g
(
z
,
u
)
>
1
−
log
2
=
0.30685281
,
{\displaystyle [z^{2n}][u]g(z,u)<\log 2\quad {\mbox{and}}\quad 1-[z^{2n}][u]g(z,u)>1-\log 2=0.30685281,}
or at least 30%, as claimed.
A related result is that asymptotically, the expected length of the longest cycle is λn, where λ is the Golomb–Dickman constant, approximately 0.62.
This example is due to Anna Gál and Peter Bro Miltersen;
consult the paper by Peter Winkler for more information, and
see the discussion on Les-Mathematiques.net.
Consult the references on 100 prisoners for links to these references.
The above computation may be performed in a more simple and direct way, as follows: first note that a permutation of
2
n
{\displaystyle 2n}
elements contains at most one cycle of length strictly greater than
n
{\displaystyle n}
. Thus, if we denote
p
k
=
Pr
[
there is a cycle of length
k
]
,
{\displaystyle p_{k}=\Pr[{\mbox{there is a cycle of length }}k],}
then
Pr
[
there is a cycle of length
>
n
]
=
∑
k
=
n
+
1
2
n
p
k
.
{\displaystyle \Pr[{\mbox{there is a cycle of length}}>n]=\sum _{k=n+1}^{2n}p_{k}.}
For
k
>
n
{\displaystyle k>n}
, the number of permutations that contain a cycle of length exactly
k
{\displaystyle k}
is
(
2
n
k
)
⋅
k
!
k
⋅
(
2
n
−
k
)
!
.
{\displaystyle {{2n} \choose k}\cdot {\frac {k!}{k}}\cdot (2n-k)!.}
Explanation:
(
2
n
k
)
{\displaystyle {{2n} \choose k}}
is the number of ways of choosing the
k
{\displaystyle k}
elements that comprise the cycle;
k
!
k
{\displaystyle {\frac {k!}{k}}}
is the number of ways of arranging
k
{\displaystyle k}
items in a cycle; and
(
2
n
−
k
)
!
{\displaystyle (2n-k)!}
is the number of ways to permute the remaining elements. There is no double counting here because there is at most one cycle of length
k
{\displaystyle k}
when
k
>
n
{\displaystyle k>n}
. Thus,
p
k
=
(
2
n
k
)
⋅
k
!
k
⋅
(
2
n
−
k
)
!
(
2
n
)
!
=
1
k
.
{\displaystyle p_{k}={\frac {{{2n} \choose k}\cdot {\frac {k!}{k}}\cdot (2n-k)!}{(2n)!}}={\frac {1}{k}}.}
We conclude that
Pr
[
there is a cycle of length
>
n
]
=
∑
k
=
n
+
1
2
n
1
k
=
H
2
n
−
H
n
.
{\displaystyle \Pr[{\mbox{there is a cycle of length}}>n]=\sum _{k=n+1}^{2n}{\frac {1}{k}}=H_{2n}-H_{n}.}
A variation on the 100 prisoners problem (keys and boxes)
There is a closely related problem that fits the method presented here quite nicely. Say you have n ordered boxes. Every box contains a key to some other box or possibly itself giving a permutation of the keys. You are allowed to select k of these n boxes all at once and break them open simultaneously, gaining access to k keys. What is the probability that using these keys you can open all n boxes, where you use a found key to open the box it belongs to and repeat.
The mathematical statement of this problem is as follows: pick a random permutation on n elements and k values from the range 1 to n, also at random, call these marks. What is the probability that there is at least one mark on every cycle of the permutation? The claim is this probability is k/n.
The species
Q
{\displaystyle {\mathcal {Q}}}
of permutations by
cycles with some non-empty subset of every cycle being marked has the
specification
Q
=
SET
(
∑
q
≥
1
CYC
=
q
(
Z
)
×
∑
p
=
1
q
(
q
p
)
U
p
)
.
{\displaystyle {\mathcal {Q}}=\operatorname {SET} \left(\sum _{q\geq 1}\operatorname {CYC} _{=q}({\mathcal {Z}})\times \sum _{p=1}^{q}{q \choose p}{\mathcal {U}}^{p}\right).}
The index in the inner sum starts at one because we must have at least one
mark on every cycle.
Translating the specification to generating functions we obtain the
bivariate generating function
G
(
z
,
u
)
=
exp
(
∑
q
≥
1
z
q
q
∑
p
=
1
q
(
q
p
)
u
p
)
.
{\displaystyle G(z,u)=\exp \left(\sum _{q\geq 1}{\frac {z^{q}}{q}}\sum _{p=1}^{q}{q \choose p}u^{p}\right).}
This simplifies to
exp
(
∑
q
≥
1
z
q
q
(
u
+
1
)
q
−
∑
q
≥
1
z
q
q
)
{\displaystyle \exp \left(\sum _{q\geq 1}{\frac {z^{q}}{q}}(u+1)^{q}-\sum _{q\geq 1}{\frac {z^{q}}{q}}\right)}
or
exp
(
log
1
1
−
(
u
+
1
)
z
−
log
1
1
−
z
)
=
1
−
z
1
−
(
u
+
1
)
z
.
{\displaystyle \exp \left(\log {\frac {1}{1-(u+1)z}}-\log {\frac {1}{1-z}}\right)={\frac {1-z}{1-(u+1)z}}.}
In order to extract coefficients from this re-write like so
(
1
−
z
)
∑
q
≥
0
(
u
+
1
)
q
z
q
.
{\displaystyle (1-z)\sum _{q\geq 0}(u+1)^{q}z^{q}.}
It now follows that
[
z
n
]
G
(
z
,
u
)
=
(
u
+
1
)
n
−
(
u
+
1
)
n
−
1
{\displaystyle [z^{n}]G(z,u)=(u+1)^{n}-(u+1)^{n-1}}
and hence
[
u
k
]
[
z
n
]
G
(
z
,
u
)
=
(
n
k
)
−
(
n
−
1
k
)
.
{\displaystyle [u^{k}][z^{n}]G(z,u)={n \choose k}-{n-1 \choose k}.}
Divide by
(
n
k
)
{\displaystyle {n \choose k}}
to obtain
1
−
(
n
−
1
)
!
k
!
(
n
−
1
−
k
)
!
k
!
(
n
−
k
)
!
n
!
=
1
−
n
−
k
n
=
k
n
.
{\displaystyle 1-{\frac {(n-1)!}{k!(n-1-k)!}}{\frac {k!(n-k)!}{n!}}=1-{\frac {n-k}{n}}={\frac {k}{n}}.}
We do not need to divide by n! because
G
(
z
,
u
)
{\displaystyle G(z,u)}
is exponential in z.
Number of permutations containing m cycles
Applying the Flajolet–Sedgewick fundamental theorem, i.e. the labelled enumeration theorem with
G
=
S
m
{\displaystyle G=S_{m}}
, to the set
SET
=
m
(
CYC
(
Z
)
)
{\displaystyle \operatorname {SET} _{=m}(\operatorname {CYC} ({\mathcal {Z}}))}
we obtain the generating function
g
m
(
z
)
=
1
|
S
m
|
(
log
1
1
−
z
)
m
=
1
m
!
(
log
1
1
−
z
)
m
.
{\displaystyle g_{m}(z)={\frac {1}{|S_{m}|}}\left(\log {\frac {1}{1-z}}\right)^{m}={\frac {1}{m!}}\left(\log {\frac {1}{1-z}}\right)^{m}.}
The term
(
−
1
)
n
+
m
n
!
[
z
n
]
g
m
(
z
)
=
s
(
n
,
m
)
{\displaystyle (-1)^{n+m}n!\;[z^{n}]g_{m}(z)=s(n,m)}
yields the signed Stirling numbers of the first kind, and
g
m
(
z
)
{\displaystyle g_{m}(z)}
is the EGF of the unsigned Stirling numbers of the first kind, i.e.
n
!
[
z
n
]
g
m
(
z
)
=
[
n
m
]
.
{\displaystyle n![z^{n}]g_{m}(z)=\left[{\begin{matrix}n\\m\end{matrix}}\right].}
We can compute the OGF of the signed Stirling numbers for n fixed, i.e.
s
n
(
w
)
=
∑
m
=
0
n
s
(
n
,
m
)
w
m
.
{\displaystyle s_{n}(w)=\sum _{m=0}^{n}s(n,m)w^{m}.}
Start with
g
m
(
z
)
=
∑
n
≥
m
(
−
1
)
n
+
m
n
!
s
(
n
,
m
)
z
n
{\displaystyle g_{m}(z)=\sum _{n\geq m}{\frac {(-1)^{n+m}}{n!}}s(n,m)z^{n}}
which yields
(
−
1
)
m
g
m
(
z
)
w
m
=
∑
n
≥
m
(
−
1
)
n
n
!
s
(
n
,
m
)
w
m
z
n
.
{\displaystyle (-1)^{m}g_{m}(z)w^{m}=\sum _{n\geq m}{\frac {(-1)^{n}}{n!}}s(n,m)w^{m}z^{n}.}
Summing this, we obtain
∑
m
≥
0
(
−
1
)
m
g
m
(
z
)
w
m
=
∑
m
≥
0
∑
n
≥
m
(
−
1
)
n
n
!
s
(
n
,
m
)
w
m
z
n
=
∑
n
≥
0
(
−
1
)
n
n
!
z
n
∑
m
=
0
n
s
(
n
,
m
)
w
m
.
{\displaystyle \sum _{m\geq 0}(-1)^{m}g_{m}(z)w^{m}=\sum _{m\geq 0}\sum _{n\geq m}{\frac {(-1)^{n}}{n!}}s(n,m)w^{m}z^{n}=\sum _{n\geq 0}{\frac {(-1)^{n}}{n!}}z^{n}\sum _{m=0}^{n}s(n,m)w^{m}.}
Using the formula involving the logarithm for
g
m
(
z
)
{\displaystyle g_{m}(z)}
on the left, the definition of
s
n
(
w
)
{\displaystyle s_{n}(w)}
on the right, and the binomial theorem, we obtain
(
1
−
z
)
w
=
∑
n
≥
0
(
w
n
)
(
−
1
)
n
z
n
=
∑
n
≥
0
(
−
1
)
n
n
!
s
n
(
w
)
z
n
.
{\displaystyle (1-z)^{w}=\sum _{n\geq 0}{w \choose n}(-1)^{n}z^{n}=\sum _{n\geq 0}{\frac {(-1)^{n}}{n!}}s_{n}(w)z^{n}.}
Comparing the coefficients of
z
n
{\displaystyle z^{n}}
, and using the definition of the binomial coefficient, we finally have
s
n
(
w
)
=
w
(
w
−
1
)
(
w
−
2
)
⋯
(
w
−
(
n
−
1
)
)
=
(
w
)
n
,
{\displaystyle s_{n}(w)=w\;(w-1)\;(w-2)\;\cdots \;(w-(n-1))=(w)_{n},}
a falling factorial. The computation of the OGF of the unsigned Stirling numbers of the first kind works in a similar way.
Expected number of cycles of a given size m
In this problem we use a bivariate generating function g(z, u) as described in the introduction. The value of b for a cycle not of size m is zero, and one for a cycle of size m. We have
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
1
b
(
k
)
z
k
k
=
1
1
−
z
z
m
m
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq 1}b(k){\frac {z^{k}}{k}}={\frac {1}{1-z}}{\frac {z^{m}}{m}}}
or
1
m
z
m
+
1
m
z
m
+
1
+
1
m
z
m
+
2
+
⋯
{\displaystyle {\frac {1}{m}}z^{m}\;+\;{\frac {1}{m}}z^{m+1}\;+\;{\frac {1}{m}}z^{m+2}\;+\;\cdots }
This means that the expected number of cycles of size m in a permutation of length n less than m is zero (obviously). A random permutation of length at least m contains on average 1/m cycles of length m. In particular, a random permutation contains about one fixed point.
The OGF of the expected number of cycles of length less than or equal to m is therefore
1
1
−
z
∑
k
=
1
m
z
k
k
and
[
z
n
]
1
1
−
z
∑
k
=
1
m
z
k
k
=
H
m
for
n
≥
m
{\displaystyle {\frac {1}{1-z}}\sum _{k=1}^{m}{\frac {z^{k}}{k}}{\mbox{ and }}[z^{n}]{\frac {1}{1-z}}\sum _{k=1}^{m}{\frac {z^{k}}{k}}=H_{m}{\mbox{ for }}n\geq m}
where Hm is the mth harmonic number. Hence the expected number of cycles of length at most m in a random permutation is about ln m.
Moments of fixed points
The mixed GF
g
(
z
,
u
)
{\displaystyle g(z,u)}
of the set of permutations by the number of fixed points is
g
(
z
,
u
)
=
exp
(
−
z
+
u
z
+
log
1
1
−
z
)
=
1
1
−
z
exp
(
−
z
+
u
z
)
.
{\displaystyle g(z,u)=\exp \left(-z+uz+\log {\frac {1}{1-z}}\right)={\frac {1}{1-z}}\exp(-z+uz).}
Let the random variable X be the number of fixed points of a random permutation.
Using Stirling numbers of the second kind, we have the following formula for the mth moment of X:
E
(
X
m
)
=
E
(
∑
k
=
0
m
{
m
k
}
(
X
)
k
)
=
∑
k
=
0
m
{
m
k
}
E
(
(
X
)
k
)
,
{\displaystyle E(X^{m})=E\left(\sum _{k=0}^{m}\left\{{\begin{matrix}m\\k\end{matrix}}\right\}(X)_{k}\right)=\sum _{k=0}^{m}\left\{{\begin{matrix}m\\k\end{matrix}}\right\}E((X)_{k}),}
where
(
X
)
k
{\displaystyle (X)_{k}}
is a falling factorial.
Using
g
(
z
,
u
)
{\displaystyle g(z,u)}
, we have
E
(
(
X
)
k
)
=
[
z
n
]
(
d
d
u
)
k
g
(
z
,
u
)
|
u
=
1
=
[
z
n
]
z
k
1
−
z
exp
(
−
z
+
u
z
)
|
u
=
1
=
[
z
n
]
z
k
1
−
z
,
{\displaystyle E((X)_{k})=[z^{n}]\left({\frac {d}{du}}\right)^{k}g(z,u){\Bigg |}_{u=1}=[z^{n}]{\frac {z^{k}}{1-z}}\exp(-z+uz){\Bigg |}_{u=1}=[z^{n}]{\frac {z^{k}}{1-z}},}
which is zero when
k
>
n
{\displaystyle k>n}
, and one otherwise.
Hence only terms with
k
<=
n
{\displaystyle k<=n}
contribute to the sum.
This yields
E
(
X
m
)
=
∑
k
=
0
n
{
m
k
}
.
{\displaystyle E(X^{m})=\sum _{k=0}^{n}\left\{{\begin{matrix}m\\k\end{matrix}}\right\}.}
Expected number of fixed points in random permutation raised to some power k
Suppose you pick a random permutation
σ
{\displaystyle \sigma }
and raise it to some power
k
{\displaystyle k}
, with
k
{\displaystyle k}
a positive integer and ask about the expected number of fixed points in the result. Denote this value by
E
[
F
k
]
{\displaystyle E[F_{k}]}
.
For every divisor
d
{\displaystyle d}
of
k
{\displaystyle k}
a cycle of length
d
{\displaystyle d}
splits into
d
{\displaystyle d}
fixed points when raised to the power
k
.
{\displaystyle k.}
Hence we need to mark these cycles with
u
d
.
{\displaystyle u^{d}.}
To illustrate this consider
E
[
F
6
]
.
{\displaystyle E[F_{6}].}
We get
g
(
z
,
u
)
=
exp
(
u
z
−
z
+
u
2
z
2
2
−
z
2
2
+
u
3
z
3
3
−
z
3
3
+
u
6
z
6
6
−
z
6
6
+
log
1
1
−
z
)
{\displaystyle g(z,u)=\exp \left(uz-z+u^{2}{\frac {z^{2}}{2}}-{\frac {z^{2}}{2}}+u^{3}{\frac {z^{3}}{3}}-{\frac {z^{3}}{3}}+u^{6}{\frac {z^{6}}{6}}-{\frac {z^{6}}{6}}+\log {\frac {1}{1-z}}\right)}
which is
1
1
−
z
exp
(
u
z
−
z
+
u
2
z
2
2
−
z
2
2
+
u
3
z
3
3
−
z
3
3
+
u
6
z
6
6
−
z
6
6
)
.
{\displaystyle {\frac {1}{1-z}}\exp \left(uz-z+u^{2}{\frac {z^{2}}{2}}-{\frac {z^{2}}{2}}+u^{3}{\frac {z^{3}}{3}}-{\frac {z^{3}}{3}}+u^{6}{\frac {z^{6}}{6}}-{\frac {z^{6}}{6}}\right).}
Once more continuing as described in the introduction, we find
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
z
+
z
2
+
z
3
+
z
6
1
−
z
exp
(
u
z
−
z
+
u
2
z
2
2
−
z
2
2
+
u
3
z
3
3
−
z
3
3
+
u
6
z
6
6
−
z
6
6
)
|
u
=
1
{\displaystyle \left.{\frac {\partial }{\partial u}}g(z,u)\right|_{u=1}=\left.{\frac {z+z^{2}+z^{3}+z^{6}}{1-z}}\exp \left(uz-z+u^{2}{\frac {z^{2}}{2}}-{\frac {z^{2}}{2}}+u^{3}{\frac {z^{3}}{3}}-{\frac {z^{3}}{3}}+u^{6}{\frac {z^{6}}{6}}-{\frac {z^{6}}{6}}\right)\right|_{u=1}}
which is
z
+
z
2
+
z
3
+
z
6
1
−
z
.
{\displaystyle {\frac {z+z^{2}+z^{3}+z^{6}}{1-z}}.}
The conclusion is that
E
[
F
6
]
=
4
{\displaystyle E[F_{6}]=4}
for
n
≥
6
{\displaystyle n\geq 6}
and there are four fixed points on average.
The general procedure is
g
(
z
,
u
)
=
exp
(
∑
d
∣
k
(
u
d
z
d
d
−
z
d
d
)
+
log
1
1
−
z
)
=
1
1
−
z
exp
(
∑
d
∣
k
(
u
d
z
d
d
−
z
d
d
)
)
.
{\displaystyle g(z,u)=\exp \left(\sum _{d\mid k}\left(u^{d}{\frac {z^{d}}{d}}-{\frac {z^{d}}{d}}\right)+\log {\frac {1}{1-z}}\right)={\frac {1}{1-z}}\exp \left(\sum _{d\mid k}\left(u^{d}{\frac {z^{d}}{d}}-{\frac {z^{d}}{d}}\right)\right).}
Once more continuing as before, we find
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
∑
d
∣
k
z
d
1
−
z
exp
(
∑
d
∣
k
(
u
d
z
d
d
−
z
d
d
)
)
|
u
=
1
=
∑
d
∣
k
z
d
1
−
z
.
{\displaystyle \left.{\frac {\partial }{\partial u}}g(z,u)\right|_{u=1}=\left.{\frac {\sum _{d\mid k}z^{d}}{1-z}}\exp \left(\sum _{d\mid k}\left(u^{d}{\frac {z^{d}}{d}}-{\frac {z^{d}}{d}}\right)\right)\right|_{u=1}={\frac {\sum _{d\mid k}z^{d}}{1-z}}.}
We have shown that the value of
E
[
F
k
]
{\displaystyle E[F_{k}]}
is equal to
τ
(
k
)
{\displaystyle \tau (k)}
(the number of divisors of
k
{\displaystyle k}
) as soon as
n
≥
k
.
{\displaystyle n\geq k.}
It starts out at
1
{\displaystyle 1}
for
n
=
1
{\displaystyle n=1}
and increases by one every time
n
{\displaystyle n}
hits a divisor of
k
{\displaystyle k}
up to and including
k
{\displaystyle k}
itself.
Expected number of cycles of any length of a random permutation
We construct the bivariate generating function
g
(
z
,
u
)
{\displaystyle g(z,u)}
using
b
(
k
)
{\displaystyle b(k)}
, where
b
(
k
)
{\displaystyle b(k)}
is one for all cycles (every cycle contributes one to the total number of cycles).
Note that
g
(
z
,
u
)
{\displaystyle g(z,u)}
has the closed form
g
(
z
,
u
)
=
(
1
1
−
z
)
u
{\displaystyle g(z,u)=\left({\frac {1}{1-z}}\right)^{u}}
and generates the unsigned Stirling numbers of the first kind.
We have
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
1
b
(
k
)
z
k
k
=
1
1
−
z
∑
k
≥
1
z
k
k
=
1
1
−
z
log
1
1
−
z
.
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq 1}b(k){\frac {z^{k}}{k}}={\frac {1}{1-z}}\sum _{k\geq 1}{\frac {z^{k}}{k}}={\frac {1}{1-z}}\log {\frac {1}{1-z}}.}
Hence the expected number of cycles is the harmonic number
H
n
{\displaystyle H_{n}}
, or about
log
n
{\displaystyle \log n}
.
Number of permutations with a cycle of length larger than n/2
(Note that Section One hundred prisoners contains exactly the same problem with a very similar calculation, plus also a simpler elementary proof.)
Once more, start with the exponential generating function
g
(
z
,
u
)
{\displaystyle g(z,u)}
, this time of the class
P
{\displaystyle {\mathcal {P}}}
of permutations according to size where cycles of length more than
n
/
2
{\displaystyle n/2}
are marked with the variable
u
{\displaystyle u}
:
g
(
z
,
u
)
=
exp
(
u
∑
k
>
⌊
n
2
⌋
∞
z
k
k
+
∑
k
=
1
⌊
n
2
⌋
z
k
k
)
.
{\displaystyle g(z,u)=\exp \left(u\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}+\sum _{k=1}^{\lfloor {\frac {n}{2}}\rfloor }{\frac {z^{k}}{k}}\right).}
There can only be one cycle of length more than
n
2
{\displaystyle {\frac {n}{2}}}
, hence the answer to the question is given by
n
!
[
u
z
n
]
g
(
z
,
u
)
=
n
!
[
z
n
]
exp
(
∑
k
=
1
⌊
n
2
⌋
z
k
k
)
∑
k
>
⌊
n
2
⌋
∞
z
k
k
{\displaystyle n![uz^{n}]g(z,u)=n![z^{n}]\exp \left(\sum _{k=1}^{\lfloor {\frac {n}{2}}\rfloor }{\frac {z^{k}}{k}}\right)\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}}
or
n
!
[
z
n
]
exp
(
log
1
1
−
z
−
∑
k
>
⌊
n
2
⌋
∞
z
k
k
)
∑
k
>
⌊
n
2
⌋
∞
z
k
k
{\displaystyle n![z^{n}]\exp \left(\log {\frac {1}{1-z}}-\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}\right)\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}}
which is
n
!
[
z
n
]
1
1
−
z
exp
(
−
∑
k
>
⌊
n
2
⌋
∞
z
k
k
)
∑
k
>
⌊
n
2
⌋
∞
z
k
k
=
n
!
[
z
n
]
1
1
−
z
∑
m
=
0
∞
(
−
1
)
m
m
!
(
∑
k
>
⌊
n
2
⌋
∞
z
k
k
)
m
+
1
{\displaystyle n![z^{n}]{\frac {1}{1-z}}\exp \left(-\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}\right)\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}=n![z^{n}]{\frac {1}{1-z}}\sum _{m=0}^{\infty }{\frac {(-1)^{m}}{m!}}\left(\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}\right)^{m+1}}
The exponent of
z
{\displaystyle z}
in the term being raised to the power
m
+
1
{\displaystyle m+1}
is larger than
⌊
n
2
⌋
{\displaystyle \lfloor {\frac {n}{2}}\rfloor }
and hence no value for
m
>
0
{\displaystyle m>0}
can possibly contribute to
[
z
n
]
.
{\displaystyle [z^{n}].}
It follows that the answer is
n
!
[
z
n
]
1
1
−
z
∑
k
>
⌊
n
2
⌋
∞
z
k
k
=
n
!
∑
k
=
⌊
n
2
⌋
+
1
n
1
k
.
{\displaystyle n![z^{n}]{\frac {1}{1-z}}\sum _{k>\lfloor {\frac {n}{2}}\rfloor }^{\infty }{\frac {z^{k}}{k}}=n!\sum _{k=\lfloor {\frac {n}{2}}\rfloor +1}^{n}{\frac {1}{k}}.}
The sum has an alternate representation that one encounters e.g. in the OEIS OEIS: A024167.
∑
k
=
1
n
1
k
−
∑
k
=
1
⌊
n
2
⌋
1
k
=
∑
k
=
1
n
1
k
−
2
∑
k
=
1
⌊
n
2
⌋
1
2
k
=
∑
k
=
1
k
even
n
(
1
−
2
)
1
k
+
∑
k
=
1
k
odd
n
1
k
{\displaystyle \sum _{k=1}^{n}{\frac {1}{k}}-\sum _{k=1}^{\lfloor {\frac {n}{2}}\rfloor }{\frac {1}{k}}=\sum _{k=1}^{n}{\frac {1}{k}}-2\sum _{k=1}^{\lfloor {\frac {n}{2}}\rfloor }{\frac {1}{2k}}=\sum _{k=1 \atop k\;{\text{even}}}^{n}(1-2){\frac {1}{k}}+\sum _{k=1 \atop k\;{\text{odd}}}^{n}{\frac {1}{k}}}
finally giving
n
!
∑
k
=
1
n
(
−
1
)
k
+
1
k
∼
n
!
log
2.
{\displaystyle n!\sum _{k=1}^{n}{\frac {(-1)^{k+1}}{k}}\sim n!\log 2.}
Expected number of transpositions of a random permutation
We can use the disjoint cycle decomposition of a permutation to factorize it as a product of transpositions by replacing a cycle of length k by k − 1 transpositions. E.g. the cycle
(
1
2
34
)
{\displaystyle (1\;2\;34)}
factors as
(
1
2
)
(
2
3
)
(
3
4
)
{\displaystyle (1\;2)\;(2\;3)\;(3\;4)}
. The function
b
(
k
)
{\displaystyle b(k)}
for cycles is equal to
k
−
1
{\displaystyle k-1}
and we obtain
g
(
z
,
u
)
=
(
1
1
−
u
z
)
1
/
u
{\displaystyle g(z,u)=\left({\frac {1}{1-uz}}\right)^{1/u}}
and
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
1
(
k
−
1
)
z
k
k
=
z
(
1
−
z
)
2
−
1
1
−
z
log
1
1
−
z
.
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq 1}(k-1){\frac {z^{k}}{k}}={\frac {z}{(1-z)^{2}}}-{\frac {1}{1-z}}\log {\frac {1}{1-z}}.}
Hence the expected number of transpositions
T
(
n
)
{\displaystyle T(n)}
is
T
(
n
)
=
n
−
H
n
{\displaystyle T(n)=n-H_{n}}
where
H
n
{\displaystyle H_{n}}
is the
n
t
h
{\displaystyle n^{th}}
Harmonic number.
We could also have obtained this formula by noting that the number of transpositions is obtained by adding the lengths of all cycles (which gives n) and subtracting one for every cycle (which gives
log
n
{\displaystyle \log n}
by the previous section).
Note that
g
(
z
,
u
)
{\displaystyle g(z,u)}
again generates the unsigned Stirling numbers of the first kind, but in reverse order. More precisely, we have
(
−
1
)
m
n
!
[
z
n
]
[
u
m
]
g
(
z
,
u
)
=
[
n
n
−
m
]
{\displaystyle (-1)^{m}n!\;[z^{n}][u^{m}]g(z,u)=\left[{\begin{matrix}n\\n-m\end{matrix}}\right]}
To see this, note that the above is equivalent to
(
−
1
)
n
+
m
n
!
[
z
n
]
[
u
m
]
g
(
z
,
u
)
|
u
=
1
/
u
|
z
=
u
z
=
[
n
m
]
{\displaystyle (-1)^{n+m}n!\;[z^{n}][u^{m}]g(z,u)|_{u=1/u}|_{z=uz}=\left[{\begin{matrix}n\\m\end{matrix}}\right]}
and that
[
u
m
]
g
(
z
,
u
)
|
u
=
1
/
u
|
z
=
u
z
=
[
u
m
]
(
1
1
−
z
)
u
=
1
m
!
(
log
1
1
−
z
)
m
,
{\displaystyle [u^{m}]g(z,u)|_{u=1/u}|_{z=uz}=[u^{m}]\left({\frac {1}{1-z}}\right)^{u}={\frac {1}{m!}}\left(\log {\frac {1}{1-z}}\right)^{m},}
which we saw to be the EGF of the unsigned Stirling numbers of the first kind in the section on permutations consisting of precisely m cycles.
Expected cycle size of a random element
We select a random element q of a random permutation
σ
{\displaystyle \sigma }
and ask about the expected size of the cycle that contains q. Here the function
b
(
k
)
{\displaystyle b(k)}
is equal to
k
2
{\displaystyle k^{2}}
, because a cycle of length k contributes k elements that are on cycles of length k. Note that unlike the previous computations, we need to average out this parameter after we extract it from the generating function (divide by n). We have
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
1
k
2
z
k
k
=
1
1
−
z
z
(
1
−
z
)
2
=
z
(
1
−
z
)
3
.
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq 1}k^{2}{\frac {z^{k}}{k}}={\frac {1}{1-z}}{\frac {z}{(1-z)^{2}}}={\frac {z}{(1-z)^{3}}}.}
Hence the expected length of the cycle that contains q is
1
n
[
z
n
]
z
(
1
−
z
)
3
=
1
n
1
2
n
(
n
+
1
)
=
1
2
(
n
+
1
)
.
{\displaystyle {\frac {1}{n}}[z^{n}]{\frac {z}{(1-z)^{3}}}={\frac {1}{n}}{\frac {1}{2}}n(n+1)={\frac {1}{2}}(n+1).}
Probability that a random element lies on a cycle of size m
This average parameter represents the probability that if we again select a random element of
[
n
]
{\displaystyle [n]}
of a random permutation, the element lies on a cycle of size m. The function
b
(
k
)
{\displaystyle b(k)}
is equal to
m
{\displaystyle m}
for
m
=
k
{\displaystyle m=k}
and zero otherwise, because only cycles of length m contribute, namely m elements that lie on a cycle of length m. We have
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
1
b
(
k
)
z
k
k
=
1
1
−
z
m
z
m
m
=
z
m
1
−
z
.
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq 1}b(k){\frac {z^{k}}{k}}={\frac {1}{1-z}}\;m\;{\frac {z^{m}}{m}}={\frac {z^{m}}{1-z}}.}
It follows that the probability that a random element lies on a cycle of length m is
1
n
[
z
n
]
z
m
1
−
z
=
{
1
n
,
if
n
≥
m
0
,
otherwise.
{\displaystyle {\frac {1}{n}}[z^{n}]{\frac {z^{m}}{1-z}}={\begin{cases}{\frac {1}{n}},&{\mbox{if }}n\geq m\\0,&{\mbox{otherwise.}}\end{cases}}}
Probability that a random subset of [n] lies on the same cycle
Select a random subset Q of [n] containing m elements and a random permutation, and ask about the probability that all elements of Q lie on the same cycle. This is another average parameter. The function b(k) is equal to
(
k
m
)
{\displaystyle {\begin{matrix}{k \choose m}\end{matrix}}}
, because a cycle of length k contributes
(
k
m
)
{\displaystyle {\begin{matrix}{k \choose m}\end{matrix}}}
subsets of size m, where
(
k
m
)
=
0
{\displaystyle {\begin{matrix}{k \choose m}=0\end{matrix}}}
for k < m. This yields
∂
∂
u
g
(
z
,
u
)
|
u
=
1
=
1
1
−
z
∑
k
≥
m
(
k
m
)
z
k
k
=
1
1
−
z
1
m
z
m
(
1
−
z
)
m
=
1
m
z
m
(
1
−
z
)
m
+
1
.
{\displaystyle {\frac {\partial }{\partial u}}g(z,u){\Bigg |}_{u=1}={\frac {1}{1-z}}\sum _{k\geq m}{k \choose m}{\frac {z^{k}}{k}}={\frac {1}{1-z}}{\frac {1}{m}}{\frac {z^{m}}{(1-z)^{m}}}={\frac {1}{m}}{\frac {z^{m}}{(1-z)^{m+1}}}.}
Averaging out we obtain that the probability of the elements of Q being on the same cycle is
(
n
m
)
−
1
[
z
n
]
1
m
z
m
(
1
−
z
)
m
+
1
=
(
n
m
)
−
1
1
m
[
z
n
−
m
]
1
(
1
−
z
)
m
+
1
{\displaystyle {n \choose m}^{-1}[z^{n}]{\frac {1}{m}}{\frac {z^{m}}{(1-z)^{m+1}}}={n \choose m}^{-1}{\frac {1}{m}}[z^{n-m}]{\frac {1}{(1-z)^{m+1}}}}
or
1
m
(
n
m
)
−
1
(
(
n
−
m
)
+
m
m
)
=
1
m
.
{\displaystyle {\frac {1}{m}}{n \choose m}^{-1}{(n-m)\;+\;m \choose m}={\frac {1}{m}}.}
In particular, the probability that two elements p < q are on the same cycle is 1/2.
Number of permutations containing an even number of even cycles
We may use the Flajolet–Sedgewick fundamental theorem directly and compute more advanced permutation statistics. (Check that page for an explanation of how the operators we will use are computed.) For example, the set of permutations containing an even number of even cycles is given by
SET
(
CYC
odd
(
Z
)
)
SET
even
(
CYC
even
(
Z
)
)
.
{\displaystyle \operatorname {SET} (\operatorname {CYC} _{\operatorname {odd} }({\mathcal {Z}}))\operatorname {SET} _{\operatorname {even} }(\operatorname {CYC} _{\operatorname {even} }({\mathcal {Z}})).}
Translating to exponential generating functions (EGFs), we obtain
exp
(
1
2
log
1
+
z
1
−
z
)
cosh
(
1
2
log
1
1
−
z
2
)
{\displaystyle \exp \left({\frac {1}{2}}\log {\frac {1+z}{1-z}}\right)\cosh \left({\frac {1}{2}}\log {\frac {1}{1-z^{2}}}\right)}
or
1
2
exp
(
1
2
(
log
1
+
z
1
−
z
+
log
1
1
−
z
2
)
)
+
1
2
exp
(
1
2
(
log
1
+
z
1
−
z
−
log
1
1
−
z
2
)
)
.
{\displaystyle {\frac {1}{2}}\exp \left({\frac {1}{2}}\left(\log {\frac {1+z}{1-z}}+\log {\frac {1}{1-z^{2}}}\right)\right)+{\frac {1}{2}}\exp \left({\frac {1}{2}}\left(\log {\frac {1+z}{1-z}}-\log {\frac {1}{1-z^{2}}}\right)\right).}
This simplifies to
1
2
exp
(
1
2
log
1
(
1
−
z
)
2
)
+
1
2
exp
(
1
2
log
(
1
+
z
)
2
)
{\displaystyle {\frac {1}{2}}\exp \left({\frac {1}{2}}\log {\frac {1}{(1-z)^{2}}}\right)+{\frac {1}{2}}\exp \left({\frac {1}{2}}\log(1+z)^{2}\right)}
or
1
2
1
1
−
z
+
1
2
(
1
+
z
)
=
1
+
z
+
1
2
z
2
1
−
z
.
{\displaystyle {\frac {1}{2}}{\frac {1}{1-z}}+{\frac {1}{2}}(1+z)=1+z+{\frac {1}{2}}{\frac {z^{2}}{1-z}}.}
This says that there is one permutation of size zero containing an even number of even cycles (the empty permutation, which contains zero cycles of even length), one such permutation of size one (the fixed point, which also contains zero cycles of even length), and that for
n
≥
2
{\displaystyle n\geq 2}
, there are
n
!
/
2
{\displaystyle n!/2}
such permutations.
Permutations that are squares
Consider what happens when we square a permutation. Fixed points are mapped to fixed points. Odd cycles are mapped to odd cycles in a one-to-one correspondence, e.g.
(
1
8
9
11
13
)
{\displaystyle (1\;8\;9\;11\;13)}
turns into
(
1
9
13
8
11
)
{\displaystyle (1\;9\;13\;8\;11)}
. Even cycles split in two and produce a pair of cycles of half the size of the original cycle, e.g.
(
5
13
6
9
)
{\displaystyle (5\;13\;6\;9)}
turns into
(
5
6
)
(
9
13
)
{\displaystyle (5\;6)\;(9\;13)}
. Hence permutations that are squares may contain any number of odd cycles, and an even number of cycles of size two, an even number of cycles of size four etc., and are given by
SET
(
CYC
odd
(
Z
)
)
SET
even
(
CYC
=
2
(
Z
)
)
SET
even
(
CYC
=
4
(
Z
)
)
SET
even
(
CYC
=
6
(
Z
)
)
⋯
{\displaystyle \operatorname {SET} (\operatorname {CYC} _{\operatorname {odd} }({\mathcal {Z}}))\operatorname {SET} _{\operatorname {even} }(\operatorname {CYC} _{=2}({\mathcal {Z}}))\operatorname {SET} _{\operatorname {even} }(\operatorname {CYC} _{=4}({\mathcal {Z}}))\operatorname {SET} _{\operatorname {even} }(\operatorname {CYC} _{=6}({\mathcal {Z}}))\cdots }
which yields the EGF
exp
(
1
2
log
1
+
z
1
−
z
)
∏
m
≥
1
cosh
z
2
m
2
m
=
1
+
z
1
−
z
∏
m
≥
1
cosh
z
2
m
2
m
.
{\displaystyle \exp \left({\frac {1}{2}}\log {\frac {1+z}{1-z}}\right)\prod _{m\geq 1}\cosh {\frac {z^{2m}}{2m}}={\sqrt {\frac {1+z}{1-z}}}\prod _{m\geq 1}\cosh {\frac {z^{2m}}{2m}}.}
Odd cycle invariants
The types of permutations presented in the preceding two sections, i.e. permutations containing an even number of even cycles and permutations that are squares, are examples of so-called odd cycle invariants, studied by Sung and Zhang (see external links). The term odd cycle invariant simply means that membership in the respective combinatorial class is independent of the size and number of odd cycles occurring in the permutation. In fact we can prove that all odd cycle invariants obey a simple recurrence, which we will derive. First, here are some more examples of odd cycle invariants.
= Permutations where the sum of the lengths of the even cycles is six
=This class has the specification
SET
(
CYC
odd
(
Z
)
)
(
SET
=
3
(
CYC
=
2
(
Z
)
)
+
CYC
=
2
(
Z
)
CYC
=
4
(
Z
)
+
CYC
=
6
(
Z
)
)
{\displaystyle \operatorname {SET} (\operatorname {CYC} _{\operatorname {odd} }({\mathcal {Z}}))\left(\operatorname {SET} _{=3}(\operatorname {CYC} _{=2}({\mathcal {Z}}))+\operatorname {CYC} _{=2}({\mathcal {Z}})\operatorname {CYC} _{=4}({\mathcal {Z}})+\operatorname {CYC} _{=6}({\mathcal {Z}})\right)}
and the generating function
1
+
z
1
−
z
(
1
6
(
z
2
2
)
3
+
z
2
2
z
4
4
+
z
6
6
)
=
5
16
z
6
1
+
z
1
−
z
.
{\displaystyle {\sqrt {\frac {1+z}{1-z}}}\left({\frac {1}{6}}\left({\frac {z^{2}}{2}}\right)^{3}+{\frac {z^{2}}{2}}{\frac {z^{4}}{4}}+{\frac {z^{6}}{6}}\right)={\frac {5}{16}}z^{6}{\sqrt {\frac {1+z}{1-z}}}.}
The first few values are
0
,
0
,
0
,
0
,
0
,
225
,
1575
,
6300
,
56700
,
425250
,
4677750
,
46777500
,
608107500
,
…
{\displaystyle 0,0,0,0,0,225,1575,6300,56700,425250,4677750,46777500,608107500,\ldots }
= Permutations where all even cycles have the same length
=This class has the specification
SET
(
CYC
odd
(
Z
)
)
(
SET
≥
1
(
CYC
=
2
(
Z
)
)
+
SET
≥
1
(
CYC
=
4
(
Z
)
)
+
SET
≥
1
(
CYC
=
6
(
Z
)
)
+
⋯
)
{\displaystyle \operatorname {SET} (\operatorname {CYC} _{\operatorname {odd} }({\mathcal {Z}}))\left(\operatorname {SET} _{\geq 1}(\operatorname {CYC} _{=2}({\mathcal {Z}}))+\operatorname {SET} _{\geq 1}(\operatorname {CYC} _{=4}({\mathcal {Z}}))+\operatorname {SET} _{\geq 1}(\operatorname {CYC} _{=6}({\mathcal {Z}}))+\cdots \right)}
and the generating function
1
+
z
1
−
z
(
exp
(
z
2
2
)
−
1
+
exp
(
z
4
4
)
−
1
+
exp
(
z
6
6
)
−
1
+
⋯
)
.
{\displaystyle {\sqrt {\frac {1+z}{1-z}}}\left(\exp \left({\frac {z^{2}}{2}}\right)-1\,+\,\exp \left({\frac {z^{4}}{4}}\right)-1\,+\,\exp \left({\frac {z^{6}}{6}}\right)-1\,+\,\cdots \right).}
There is a semantic nuance here. We could consider permutations containing no even cycles as belonging to this class, since zero is even. The first few values are
0
,
1
,
3
,
15
,
75
,
405
,
2835
,
22155
,
199395
,
1828575
,
…
{\displaystyle 0,1,3,15,75,405,2835,22155,199395,1828575,\ldots }
= Permutations where the maximum length of an even cycle is four
=This class has the specification
SET
(
CYC
odd
(
Z
)
)
SET
(
CYC
=
2
(
Z
)
+
CYC
=
4
(
Z
)
)
{\displaystyle \operatorname {SET} (\operatorname {CYC} _{\operatorname {odd} }({\mathcal {Z}}))\operatorname {SET} (\operatorname {CYC} _{=2}({\mathcal {Z}})+\operatorname {CYC} _{=4}({\mathcal {Z}}))}
and the generating function
1
+
z
1
−
z
exp
(
z
2
2
+
z
4
4
)
.
{\displaystyle {\sqrt {\frac {1+z}{1-z}}}\exp \left({\frac {z^{2}}{2}}+{\frac {z^{4}}{4}}\right).}
The first few values are
1
,
2
,
6
,
24
,
120
,
600
,
4200
,
28560
,
257040
,
2207520
,
24282720
,
258128640
,
…
{\displaystyle 1,2,6,24,120,600,4200,28560,257040,2207520,24282720,258128640,\ldots }
= The recurrence
=Observe carefully how the specifications of the even cycle component are constructed. It is best to think of them in terms of parse trees. These trees have three levels. The nodes at the lowest level represent sums of products of even-length cycles of the singleton
Z
{\displaystyle {\mathcal {Z}}}
. The nodes at the middle level represent restrictions of the set operator. Finally the node at the top level sums products of contributions from the middle level. Note that restrictions of the set operator, when applied to a generating function that is even, will preserve this feature, i.e. produce another even generating function. But all the inputs to the set operators are even since they arise from even-length cycles. The result is that all generating functions involved have the form
g
(
z
)
=
h
(
z
)
1
+
z
1
−
z
,
{\displaystyle g(z)=h(z){\sqrt {\frac {1+z}{1-z}}},}
where
h
(
z
)
{\displaystyle h(z)}
is an even function. This means that
1
1
+
z
g
(
z
)
=
h
(
z
)
1
1
−
z
2
{\displaystyle {\frac {1}{1+z}}\;g(z)=h(z)\;{\frac {1}{\sqrt {1-z^{2}}}}}
is even, too, and hence
1
1
+
z
g
(
z
)
=
1
1
−
z
g
(
−
z
)
or
(
1
−
z
)
g
(
z
)
=
(
1
+
z
)
g
(
−
z
)
.
{\displaystyle {\frac {1}{1+z}}\;g(z)={\frac {1}{1-z}}\;g(-z)\quad {\mbox{ or }}\quad (1-z)\;g(z)=(1+z)\;g(-z).}
Letting
g
n
=
n
!
[
z
n
]
g
(
z
)
{\textstyle g_{n}=n![z^{n}]g(z)}
and extracting coefficients, we find that
g
2
m
+
1
(
2
m
+
1
)
!
−
g
2
m
(
2
m
)
!
=
−
g
2
m
+
1
(
2
m
+
1
)
!
+
g
2
m
(
2
m
)
!
or
2
g
2
m
+
1
(
2
m
+
1
)
!
=
2
g
2
m
(
2
m
)
!
{\displaystyle {\frac {g_{2m+1}}{(2m+1)!}}-{\frac {g_{2m}}{(2m)!}}=-{\frac {g_{2m+1}}{(2m+1)!}}+{\frac {g_{2m}}{(2m)!}}\quad {\mbox{ or }}\quad 2{\frac {g_{2m+1}}{(2m+1)!}}=2{\frac {g_{2m}}{(2m)!}}}
which yields the recurrence
g
2
m
+
1
=
(
2
m
+
1
)
g
2
m
.
{\displaystyle g_{2m+1}=(2m+1)g_{2m}\,.}
A problem from the 2005 Putnam competition
A link to the Putnam competition website appears in the section
External links.
The problem asks for a proof that
∑
π
∈
S
n
σ
(
π
)
ν
(
π
)
+
1
=
(
−
1
)
n
+
1
n
n
+
1
,
{\displaystyle \sum _{\pi \in S_{n}}{\frac {\sigma (\pi )}{\nu (\pi )+1}}=(-1)^{n+1}{\frac {n}{n+1}},}
where the sum is over all
n
!
{\displaystyle n!}
permutations of
[
n
]
{\displaystyle [n]}
,
σ
(
π
)
{\displaystyle \sigma (\pi )}
is the sign of
π
{\displaystyle \pi }
, i.e.
σ
(
π
)
=
1
{\displaystyle \sigma (\pi )=1}
if
π
{\displaystyle \pi }
is even and
σ
(
π
)
=
−
1
{\displaystyle \sigma (\pi )=-1}
if
π
{\displaystyle \pi }
is odd, and
ν
(
π
)
{\displaystyle \nu (\pi )}
is the number of fixed points of
π
{\displaystyle \pi }
.
Now the sign of
π
{\displaystyle \pi }
is given by
σ
(
π
)
=
∏
c
∈
π
(
−
1
)
|
c
|
−
1
,
{\displaystyle \sigma (\pi )=\prod _{c\in \pi }(-1)^{|c|-1},}
where the product is over all cycles c of
π
{\displaystyle \pi }
,
as explained e.g. on the page on even and odd permutations.
Hence we consider the combinatorial class
SET
(
−
Z
+
V
Z
+
CYC
=
1
(
Z
)
+
U
CYC
=
2
(
Z
)
+
U
2
CYC
=
3
(
Z
)
+
U
3
CYC
=
4
(
Z
)
+
⋯
)
{\displaystyle \operatorname {SET} (-{\mathcal {Z}}+{\mathcal {V}}{\mathcal {Z}}+\operatorname {CYC} _{=1}({\mathcal {Z}})+{\mathcal {U}}\operatorname {CYC} _{=2}({\mathcal {Z}})+{\mathcal {U}}^{2}\operatorname {CYC} _{=3}({\mathcal {Z}})+{\mathcal {U}}^{3}\operatorname {CYC} _{=4}({\mathcal {Z}})+\cdots )}
where
U
{\displaystyle {\mathcal {U}}}
marks one minus the length of a contributing cycle,
and
V
{\displaystyle {\mathcal {V}}}
marks fixed points. Translating to generating functions, we obtain
g
(
z
,
u
,
v
)
=
exp
(
−
z
+
v
z
+
∑
k
≥
1
u
k
−
1
z
k
k
)
{\displaystyle g(z,u,v)=\exp \left(-z+vz+\sum _{k\geq 1}u^{k-1}{\frac {z^{k}}{k}}\right)}
or
exp
(
−
z
+
v
z
+
1
u
log
1
1
−
u
z
)
=
exp
(
−
z
+
v
z
)
(
1
1
−
u
z
)
1
/
u
.
{\displaystyle \exp \left(-z+vz+{\frac {1}{u}}\log {\frac {1}{1-uz}}\right)=\exp(-z+vz)\left({\frac {1}{1-uz}}\right)^{1/u}.}
Now we have
n
!
[
z
n
]
g
(
z
,
−
1
,
v
)
=
n
!
[
z
n
]
exp
(
−
z
+
v
z
)
(
1
+
z
)
=
∑
π
∈
S
n
σ
(
π
)
v
ν
(
π
)
{\displaystyle n![z^{n}]g(z,-1,v)=n![z^{n}]\exp(-z+vz)(1+z)=\sum _{\pi \in S_{n}}\sigma (\pi )v^{\nu (\pi )}}
and hence the desired quantity is given by
n
!
[
z
n
]
∫
0
1
g
(
z
,
−
1
,
v
)
d
v
=
∑
π
∈
S
n
σ
(
π
)
ν
(
π
)
+
1
.
{\displaystyle n![z^{n}]\int _{0}^{1}g(z,-1,v)dv=\sum _{\pi \in S_{n}}{\frac {\sigma (\pi )}{\nu (\pi )+1}}.}
Doing the computation, we obtain
∫
0
1
g
(
z
,
−
1
,
v
)
d
v
=
exp
(
−
z
)
(
1
+
z
)
(
1
z
exp
(
z
)
−
1
z
)
{\displaystyle \int _{0}^{1}g(z,-1,v)dv=\exp(-z)(1+z)\left({\frac {1}{z}}\exp(z)-{\frac {1}{z}}\right)}
or
(
1
z
+
1
)
(
1
−
exp
(
−
z
)
)
=
1
z
+
1
−
exp
(
−
z
)
−
1
z
exp
(
−
z
)
.
{\displaystyle \left({\frac {1}{z}}+1\right)\left(1-\exp(-z)\right)={\frac {1}{z}}+1-\exp(-z)-{\frac {1}{z}}\exp(-z).}
Extracting coefficients, we find that the coefficient of
1
/
z
{\displaystyle 1/z}
is zero.
The constant is one, which does not agree with the formula (should be zero).
For
n
{\displaystyle n}
positive, however, we obtain
n
!
[
z
n
]
(
−
exp
(
−
z
)
−
1
z
exp
(
−
z
)
)
=
n
!
(
−
(
−
1
)
n
1
n
!
−
(
−
1
)
n
+
1
1
(
n
+
1
)
!
)
{\displaystyle n![z^{n}]\left(-\exp(-z)-{\frac {1}{z}}\exp(-z)\right)=n!\left(-(-1)^{n}{\frac {1}{n!}}-(-1)^{n+1}{\frac {1}{(n+1)!}}\right)}
or
(
−
1
)
n
+
1
(
1
−
1
n
+
1
)
=
(
−
1
)
n
+
1
n
n
+
1
,
{\displaystyle (-1)^{n+1}\left(1-{\frac {1}{n+1}}\right)=(-1)^{n+1}{\frac {n}{n+1}},}
which is the desired result.
As an interesting aside, we observe that
g
(
z
,
u
,
v
)
{\displaystyle g(z,u,v)}
may be used to evaluate the following determinant of an
n
×
n
{\displaystyle n\times n}
matrix:
d
(
n
)
=
det
(
A
n
)
=
|
a
b
b
⋯
b
b
a
b
⋯
b
b
b
a
⋯
b
⋮
⋮
⋮
⋱
⋮
b
b
b
⋯
a
|
.
{\displaystyle d(n)=\det(A_{n})={\begin{vmatrix}a&&b&&b&&\cdots &&b\\b&&a&&b&&\cdots &&b\\b&&b&&a&&\cdots &&b\\\vdots &&\vdots &&\vdots &&\ddots &&\vdots \\b&&b&&b&&\cdots &&a\end{vmatrix}}.}
where
a
,
b
≠
0
{\displaystyle a,b\neq 0}
. Recall the formula for the determinant:
det
(
A
)
=
∑
π
∈
S
n
σ
(
π
)
∏
i
=
1
n
A
i
,
π
(
i
)
.
{\displaystyle \det(A)=\sum _{\pi \in S_{n}}\sigma (\pi )\prod _{i=1}^{n}A_{i,\pi (i)}.}
Now the value of the product on the right for a permutation
π
{\displaystyle \pi }
is
a
f
b
n
−
f
{\displaystyle a^{f}b^{n-f}}
,
where f is the number of fixed points of
π
{\displaystyle \pi }
. Hence
d
(
n
)
=
b
n
n
!
[
z
n
]
g
(
z
,
−
1
,
a
b
)
=
b
n
n
!
[
z
n
]
exp
(
a
−
b
b
z
)
(
1
+
z
)
{\displaystyle d(n)=b^{n}n![z^{n}]g\left(z,-1,{\frac {a}{b}}\right)=b^{n}n![z^{n}]\exp \left({\frac {a-b}{b}}z\right)(1+z)}
which yields
b
n
(
a
−
b
b
)
n
+
b
n
n
(
a
−
b
b
)
n
−
1
=
(
a
−
b
)
n
+
n
b
(
a
−
b
)
n
−
1
{\displaystyle b^{n}\left({\frac {a-b}{b}}\right)^{n}+b^{n}n\left({\frac {a-b}{b}}\right)^{n-1}=(a-b)^{n}+nb(a-b)^{n-1}}
and finally
d
(
n
)
=
(
a
+
(
n
−
1
)
b
)
(
a
−
b
)
n
−
1
.
{\displaystyle d(n)=(a+(n-1)b)(a-b)^{n-1}\,.}
The difference between the number of cycles in even and odd permutations
Here we seek to show that this difference is given by
(
−
1
)
n
(
n
−
2
)
!
{\displaystyle (-1)^{n}(n-2)!}
Recall that the sign
σ
(
π
)
{\displaystyle \sigma (\pi )}
of a permutation
π
{\displaystyle \pi }
is given by
σ
(
π
)
=
∏
c
∈
π
(
−
1
)
|
c
|
−
1
{\displaystyle \sigma (\pi )=\prod _{c\in \pi }(-1)^{|c|-1}}
where the product ranges over the cycles c from the disjoint cycle composition of
π
{\displaystyle \pi }
.
It follows that the combinatorial species
Q
{\displaystyle {\mathcal {Q}}}
that reflects the signs and the cycle count of the set of permutations is given by
Q
=
SET
(
V
CYC
1
(
Z
)
+
U
V
CYC
=
2
(
Z
)
)
+
U
2
V
CYC
=
3
(
Z
)
+
U
3
V
CYC
=
4
(
Z
)
+
U
4
V
CYC
=
5
(
Z
)
+
⋯
)
{\displaystyle {\mathcal {Q}}=\operatorname {SET} ({\mathcal {V}}\operatorname {CYC} _{1}({\mathcal {Z}})+{\mathcal {U}}{\mathcal {V}}\operatorname {CYC} _{=2}({\mathcal {Z}}))+{\mathcal {U}}^{2}{\mathcal {V}}\operatorname {CYC} _{=3}({\mathcal {Z}})+{\mathcal {U}}^{3}{\mathcal {V}}\operatorname {CYC} _{=4}({\mathcal {Z}})+{\mathcal {U}}^{4}{\mathcal {V}}\operatorname {CYC} _{=5}({\mathcal {Z}})+\cdots )}
where we have used
U
{\displaystyle {\mathcal {U}}}
to mark signs and
V
{\displaystyle {\mathcal {V}}}
for the cycle count.
Translating to generating functions we have
Q
(
z
,
u
,
v
)
=
exp
(
v
z
1
+
v
u
z
2
2
+
v
u
2
z
3
3
+
v
u
3
z
4
4
+
v
u
4
z
5
5
+
⋯
)
.
{\displaystyle Q(z,u,v)=\exp \left(v{\frac {z}{1}}+vu{\frac {z^{2}}{2}}+vu^{2}{\frac {z^{3}}{3}}+vu^{3}{\frac {z^{4}}{4}}+vu^{4}{\frac {z^{5}}{5}}+\cdots \right).}
This simplifies to
Q
(
z
,
u
,
v
)
=
exp
(
v
u
(
z
u
1
+
z
2
u
2
2
+
z
3
u
3
3
+
z
4
u
4
4
+
z
5
u
5
5
+
⋯
)
)
{\displaystyle Q(z,u,v)=\exp \left({\frac {v}{u}}\left({\frac {zu}{1}}+{\frac {z^{2}u^{2}}{2}}+{\frac {z^{3}u^{3}}{3}}+{\frac {z^{4}u^{4}}{4}}+{\frac {z^{5}u^{5}}{5}}+\cdots \right)\right)}
which is
exp
(
v
u
log
1
1
−
u
z
)
=
(
1
1
−
u
z
)
v
u
.
{\displaystyle \exp \left({\frac {v}{u}}\log {\frac {1}{1-uz}}\right)=\left({\frac {1}{1-uz}}\right)^{\frac {v}{u}}.}
Now the two generating functions
Q
1
(
z
,
v
)
{\displaystyle Q_{1}(z,v)}
and
Q
2
(
z
,
v
)
{\displaystyle Q_{2}(z,v)}
of even and odd permutations by cycle count are given by
Q
1
(
z
,
v
)
=
1
2
Q
(
z
,
+
1
,
v
)
+
1
2
Q
(
z
,
−
1
,
v
)
=
1
2
(
1
1
−
z
)
v
+
1
2
(
1
1
+
z
)
−
v
{\displaystyle Q_{1}(z,v)={\frac {1}{2}}Q(z,+1,v)+{\frac {1}{2}}Q(z,-1,v)={\frac {1}{2}}\left({\frac {1}{1-z}}\right)^{v}+{\frac {1}{2}}\left({\frac {1}{1+z}}\right)^{-v}}
and
Q
2
(
z
,
v
)
=
1
2
Q
(
z
,
+
1
,
v
)
−
1
2
Q
(
z
,
−
1
,
v
)
=
1
2
(
1
1
−
z
)
v
−
1
2
(
1
1
+
z
)
−
v
.
{\displaystyle Q_{2}(z,v)={\frac {1}{2}}Q(z,+1,v)-{\frac {1}{2}}Q(z,-1,v)={\frac {1}{2}}\left({\frac {1}{1-z}}\right)^{v}-{\frac {1}{2}}\left({\frac {1}{1+z}}\right)^{-v}.}
We require the quantity
G
(
z
,
v
)
=
d
d
v
(
Q
1
(
z
,
v
)
−
Q
2
(
z
,
v
)
)
|
v
=
1
{\displaystyle G(z,v)=\left.{\frac {d}{dv}}(Q_{1}(z,v)-Q_{2}(z,v))\right|_{v=1}}
which is
d
d
v
(
1
1
+
z
)
−
v
|
v
=
1
=
−
log
1
1
+
z
(
1
1
+
z
)
−
v
|
v
=
1
=
−
(
1
+
z
)
log
1
1
+
z
.
{\displaystyle \left.{\frac {d}{dv}}\left({\frac {1}{1+z}}\right)^{-v}\right|_{v=1}=-\left.\log {\frac {1}{1+z}}\left({\frac {1}{1+z}}\right)^{-v}\right|_{v=1}=-(1+z)\log {\frac {1}{1+z}}.}
Finally, extracting coefficients from this generating function, we obtain
−
n
!
[
z
n
]
(
1
+
z
)
log
1
1
+
z
=
−
n
!
(
(
−
1
)
n
n
+
(
−
1
)
n
−
1
n
−
1
)
{\displaystyle -n![z^{n}](1+z)\log {\frac {1}{1+z}}=-n!\left({\frac {(-1)^{n}}{n}}+{\frac {(-1)^{n-1}}{n-1}}\right)}
which is
−
n
!
(
−
1
)
n
−
1
(
−
1
n
+
1
n
−
1
)
=
n
!
(
−
1
)
n
n
−
(
n
−
1
)
n
(
n
−
1
)
{\displaystyle -n!(-1)^{n-1}\left(-{\frac {1}{n}}+{\frac {1}{n-1}}\right)=n!(-1)^{n}{\frac {n-(n-1)}{n(n-1)}}}
which is in turn
n
!
(
−
1
)
n
1
n
(
n
−
1
)
=
(
−
1
)
n
(
n
−
2
)
!
{\displaystyle n!(-1)^{n}{\frac {1}{n(n-1)}}=(-1)^{n}(n-2)!}
This concludes the proof.
Generalizations
Similar statistics are available for random endomorphisms on a finite set.
See also
Golomb–Dickman constant
References
External links
Sung, Philip; Zhang, Yan (2003). "Recurring Recurrences in Counting Permutations". CiteSeerX 10.1.1.91.1088.
Marko Riedel et al., The difference of number of cycles of even and odd permutations
Marko Riedel et al., Keys inside closed boxes, a question on probability
= 100 prisoners
=Various authors, Permutations with a cycle > n/2
Various authors, A property of derangements
Various authors, Expected number of fixed points
Peter Winkler, Seven puzzles you think you must not have heard correctly
Various authors, Les-Mathematiques.net. Cent prisonniers (in French)
Kata Kunci Pencarian:
- Statistika
- Statistika matematika
- Variabel acak
- Statistika nonparametrik
- Ilmu aktuaria
- Bhramar Mukherjee
- Model generatif
- Efek pengacau
- Eksperimen semu
- Random permutation
- Random permutation statistics
- Permutation test
- List of permutation topics
- Random forest
- Discrete uniform distribution
- Resampling (statistics)
- List of statistics articles
- Stratified sampling
- Random number