Random permutation statistics
From Wikipedia, the free encyclopedia
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.
[edit] The fundamental relation
Permutations are sets of labelled cycles. Using the labelled case of the fundamental theorem of combinatorial enumeration and writing for the set of permutations and for the singleton set, we have
Translating into exponential generating functions, we have
where we have used the fact that the EGF of the set of permutations (there are n! permutations of n elements) is
This one equation will allow us to derive a surprising number of permutation statistics. Firstly, by dropping terms from , i.e. exp, we may constrain the number of cycles that a permutation contains, e.g. by restricting the EGF to we obtain permutations containing two cycles. Secondly, note that the EGF of labelled cycles, i.e. of , is
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.
Now instead of dropping, let's put different weights on different size cycles. If is a weight function that depends only on the size k of the cycle and for brevity we write
the value of b for a permutation σ to be the sum of its values on the cycles, then we may mark cycles of length k with ub(k) and obtain a bivariate generating function g(z, u) that describes the parameter, i.e.
This is a mixed generating function which is exponential in the permutation size and ordinary in the secondary parameter u. Differentiating and evaluating at u = 1, we have
i.e. the EGF of the sum of b over all permutations, or alternatively, the OGF, or more precisely, PGF (probability generating function) of the expectation of b.
This article uses the coefficient extraction operator [zn], documented on the page for formal power series.
[edit] 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 EGF g(z) of these permutations is
This gives the explicit formula for the total number I(n) of involutions among the permutations σ ∈ Sn:
Dividing by n! yields the probability that a random permutation is an involution.
[edit] 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
When m = p, where p is prime, this simplifies to
[edit] 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, and hence the EGF (subtract out fixed points by removing z) g(x) is
Now multiplication by 1 / (1 − z) just sums coefficients, so that we have the following formula for D(n), the total number of derangements:
Hence there are about n! / e derangements and the probability that a random permutation is a derangement is 1 / e.
This result may also be proved by inclusion-exclusion. Using the sets Ap where to denote the set of permutations that fix p, we have
This formula counts the number of permutations that have at least one fixed point. The cardinalities are as follows:
Hence the number of permutations with no fixed point is
or
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) of permutations of [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 and zero otherwise, which yields the generating function g(z,u) of the set of permutations by the number of fixed points:
It follows that
and hence
This immediately implies that
for n large, m fixed.
[edit] 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, what is it?
First of all, the survival probablity using random choices is
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%.
We consider the general case of 2n prisoners and n urns being opened. We first calculate the complementary probability, i.e. that there is a cycle of more than n elements. With this in mind, we introduce
or
so that the desired probability is
because the cycle of more than n elements will necessarily be unique. Using the fact that 2(n + 1) > 2n, we find that
which yields
Finally, using an integral estimate such as Euler–MacLaurin summation, or the asymptotic expansion of the nth harmonic number, we obtain
so that
or at least 30%, as claimed.
This example is due to Anna Gál and Peter Bro Miltersen. Consult the paper by Peter Winkler for more information. The example was subject of a discussion on Les-Mathematiques.net. Consult the section on external links for more information
[edit] Number of permutations containing m cycles
Applying the fundamental theorem of combinatorial enumeration, i.e. the labelled enumeration theorem with G = Sm, to the set
we obtain the generating function
The term
yields the Stirling numbers of the first kind, i.e. gm(z) is the EGF of the unsigned Stirling numbers of the first kind.
We can compute the OGF of these numbers for n fixed, i.e.
Start with
which yields
Summing this, we obtain
Using the formula for gm(z) on the left, the definition of sn(w) on the right, and the binomial theorem, we obtain
Comparing the coefficients of zn, and using the definition of the binomial coefficient, we finally have
[edit] 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
or
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
where Hm is the mth harmonic number. Hence the expected number of cycles of length at most m in a random permutation is about
[edit] Moments of fixed points
The mixed GF g(z,u) of the set of permutations by the number of fixed points is
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:
where (X)k is a falling factorial. Using g(z,u), we have
which is zero when k > n, and one otherwise. Hence only terms with k < = n contribute to the sum. This yields
[edit] Expected number of cycles of any length of a random permutation
We construct the bivariate generating function g(z,u) using b(k), where b(k) is one for all cycles (every cycle contributes one to the total number of cycles).
Note that g(z,u) has the closed form
and generates the unsigned Stirling numbers of the first kind.
We have
Hence the expected number of cycles is Hn, or about The average length of a cycle is thus .
[edit] 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 factors as . The function b(k) for cycles is equal to k − 1 and we obtain
and
Hence the expected number of transpositions T(n) is
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 by the previous section).
Note that g(z,u) again generates the unsigned Stirling numbers of the first kind, but in reverse order. More precisely, we have
To see this, note that the above is equivalent to
and that
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.
[edit] Expected cycle size of a random element
We select a random element q of a random permutation σ and ask about the expected size of the cycle that contains q. Here the function b(k) is equal to k2, 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
Hence the expected length of the cycle that contains q is
[edit] 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] of a random permutation, the element lies on a cycle of size m. The function b(k) is equal to m for 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
It follows that the probability that a random element lies on a cycle of length m is
[edit] 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 , because a cycle of length k contributes subsets of size m, where for k < m. This yields
Averaging out we obtain that the probability of the elements of Q being on the same cycle is
or
In particular, the probability that two elements p < q are on the same cycle is 1 / 2.
[edit] Number of permutations containing an even number of even cycles
We may use the Fundamental Theorem of Combinatorial Enumeration 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
Translating to EGFs, we obtain
or
This simplifies to
or
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 , there are such permutations.
[edit] 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 turns into . Even cycles split in two and produce a pair of cycles of half the size of the original cycle, e.g. turns into . 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
which yields the EGF
[edit] 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.
[edit] Permutations where the sum of the lengths of the even cycles is six
This class has the specification
and the generating function
The first few values are
[edit] Permutations where all even cycles have the same length
This class has the specification
and the generating function
There is a sematic nuance here. We could consider permutations containing no even cycles as belonging to this class, since zero is even. The first few values are
[edit] Permutations where the maximum length of an even cycle is four
This class has the specification
and the generating function
The first few values are
[edit] 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 . 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
where h(z) is an even function. This means that
is even, too, and hence
Letting and extracting coefficients, we find that
which yields the recurrence
[edit] 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
where the sum is over all n! permutations of [n], σ(π) is the sign of π, i.e. σ(π) = 1 if π is even and σ(π) = − 1 if π is odd, and ν(π) is the number of fixed points of π.
Now the sign of π is given by
where the product is over all cycles c of π, as explained e.g. on the page on even and odd permutations.
Hence we consider the combinatorial class
where marks one minus the length of a contributing cycle, and marks fixed points. Translating to generating functions, we obtain
or
Now we have
and hence the desired quantity is given by
Doing the computation, we obtain
or
Extracting coefficients, we find that the coefficient of 1 / z is zero. The constant is one, which does not agree with the formula (should be zero). For n positive, however, we obtain
or
which is the desired result.
As an interesting aside, we observe that g(z,u,v) may be used to evaluate the following determinant of an matrix:
where . Recall the formula for the determinant:
Now the value of the product on the right for a permutation π is , where f is the number of fixed points of π. Hence
which yields
and finally
[edit] Expected number of inversions
This parameter is not computed from the cycle structure of the permutation An inversion is a pair (p,q) where p < q and , i.e. the elements at positions p and q are not in order.
Now n will not contribute any inversions, because it is the largest element; n − 1 may contribute one or zero inversions (with n); n − 2 may contribute two, one, or zero inversions (with n or n − 1), etc. so that the OGF g(z)of the set of permutations by inversions is
We use this to compute the expected number I(n) of inversions of a random permutation:
or
which yields
[edit] See also
[edit] External links
- Alois Panholzer, Helmut Prodinger, Marko Riedel, Measuring post-quickselect disorder.
- Marko Riedel, The statistics of random permutations.
- Putnam Competition Archive,William Lowell Putnam Competition Archive
- Philip Sung, Yan Zhang, Recurring Recurrences in Counting Permutations
- Anna Gál, Peter Bro Miltersen, The cell probe complexity of succinct data structures
- Peter Winkler, Seven puzzles you think you must not have heard correctly
- Alois Panholzer, Helmut Prodinger, Marko Riedel, Measuring post-quickselect disorder.
- Marko Riedel, The statistics of random permutations.
- Putnam Competition Archive,William Lowell Putnam Competition Archive
- Philip Sung, Yan Zhang, Recurring Recurrences in Counting Permutations
- Various authors, Les-Mathematiques.net. Cent prisonniers In French.