Preserving the Number of Cycles of Length K in a Growing Uniform Permutation

The goal of this work is to describe a uniform generation tree for permutations which preserves the number of k-cycles between any permutation (except for a small unavoidable subset of optimal size) of the tree and its direct children. Moreover, the tree we describe has the property that if the number of k-cycles does not change during any k consecutive levels, then any further random descent will always yield permutations with that same number of k-cycles. This specific additional property yields interesting applications for exact sampling. We describe a new random generation algorithm for permutations with a fixed number of k-cycles in n + O(1) expected calls to a random integer sampler. Another application is a combinatorial algorithm for exact sampling from the Poisson distribution with parameter 1/k.


Introduction 1.Overview of results
Throughout the paper, k 1 is a predefined constant representing some fixed length of cycles in permutations.
It is a well-known 1 fact, that given an infinite vector (σ n ) n 1 such that σ n is a permutation of n elements chosen uniformly at random, c k (σ n ), the number of cycles of length k in σ n , converges in distribution to a random Poisson distributed variable X k with expectation 1/k, i.e., It is a standard result of probability theory that convergence in distribution can always be realized as almost sure convergence.In our setting, this means one can construct a probability distribution µ on sequences of permutations (whose n-th element σ n is always uniform among permutations of size n) such that, for µ-almost all sequences, c k (σ n ) converges to a Poisson random variable with parameter 1/k.Since we are dealing with integer valued sequences, convergence is equivalent to the sequence being ultimately constant.The main contribution of this paper is the explicit combinatorial description of one such probability distribution.
Since permutations have the very particular property that the number of permutations of each size is a multiple of the number of permutations of the preceding size, a particular type of probability distributions on size-indexed sequences of permutations is given by so-called generation trees: infinite trees with the unique permutation of size 1 as the root, where each permutation of size n has exactly n + 1 children, each a permutation of size n + 1, and such that each permutation of size n appears exactly once among the nodes of level n.The corresponding probability distribution on sequences corresponds to a random descent in the tree, where, at each step, one of the children is picked uniformly at random, independently of the previous choices.Because each permutation appears only once in the tree, the obtained sequences of permutations are very particular; any permutation in the sequence uniquely determines all previous permutations.Still, such sequences are sufficient for our purpose, so that we solely concentrate on the description of one such generation tree.
Our tree construction also exhibits a property that can be described in standard probabilistic terminology.Not only do µ-almost all permutation sequences ultimately stabilize their number of k-cycles; we explicitly describe a subclass of permutations (called non-special permutations) such that µ-almost all sequences contain such a permutation, and that all permutations that follow a non-special permutation (that is, its descendents in the tree) are also non-special, and have the same number of k-cycles.In probabilistic terms, the stabilization time T for the number of k-cycles is not a stopping time, but is upper bounded by a stopping time T , which is none other than the index of the first non-special permutation, and for which we prove that T T T + k holds a.s.One direct consequence is that c k (σ T ) is exactly Poisson distributed with parameter 1/k; this provides a "purely discrete" algorithm for sampling from this Poisson distribution by only using integers and no floating point computations.It also allows for the sampling from the distribution of the number of k-cycles in a uniform permutation of size n, in constant expected time (independently of n).
This paper is an extensive generalization of a previous work by the authors [6] where a similar construction is given for the case k = 1.

Outline of the paper
The paper is organized as follows.In the next section, we give some notations and briefly discuss generation trees for permutations in general.In Section 3 we describe our generation tree, define a number of operations and prove their properties.The proof of the main theorem is in Section 4. In Section 5, we use the tree to describe new algorithms for random generation and simulation of random variates.We finish the paper with a conclusion outlining further possible applications and directions for future research along the same vein.
2 Uniform generation trees for permutations

Notations and definitions
We use the notation [a, b] for the set of integers i such that a i b and [n] = [1, n] = {1, . . ., n} for the set of the first n positive integers.We shall write S V for the set of all permutations over the set V (bijections from V to itself).If σ ∈ S V , we set |σ| = |V | and call it the size of σ.The set S = ∪ n S [n] is thus the set of all permutations on initial segments of positive integers.When V is not specified, the phrase "permutation of size n" refers to an element of S [n] .
A cycle in a permutation σ ∈ S V is a minimum nonempty subset V that is closed under the action of σ; we slightly abuse this definition by considering the empty set to be a cycle (of length 0).
A cycle C of length k, abbreviated as a k-cycle, is a cycle such that |C| = k.We shall denote by L σ (j) the length of the cycle containing j in the permutation σ; we further assume L σ (j) = 0 if j is not an element of the permutation σ.
A uniform generation tree for permutations can be seen as the description, for each nonnegative integer n, of a bijection φ n from S [n] × [n + 1] to S [n+1] .The countable set S can thus be seen as the nodes of an infinite rooted tree, with the unique permutation of size 1 as the root, and where each permutation σ ∈ S [n] has exactly n + 1 children, obtained by applying φ n to the pairs (σ, i) for i ∈ [n + 1].The n! nodes at distance n − 1 from the root are then all permutations of S [n] .Such a generation tree can also be seen as the description of a procedure for the random generation of uniform permutations: from a random permutation of size n and an independent uniform integer in the range [n + 1], φ n gives us a uniform random permutation of size n + 1.Thus, starting from the root and repeating n − 1 times the simple procedure of moving to a uniformly chosen child of the current node yields a uniform permutation of size n.We refer to this procedure as a random descent (possibly infinite) in the tree.
Consistently with the tree terminology, φ n (σ, i) will be called the i-th child of σ, and σ will be called the parent of each of its children.All permutations in the subtree rooted at σ are collectively called the descendants of σ.

Some classical generation trees
Many simple combinatorial descriptions of uniform generation trees can be given.We briefly describe two of them.
• Last value insertion: from a permutation σ ∈ S [n−1] and an integer i ∈ [n], we obtain a new permutation σ ∈ S [n] as follows: set σ (n) = i, and for 1 j n − 1, σ (j) = σ(j) if σ(j) < i, and σ (j) = 1 + σ(j) if σ(j) i.In other words, i gives the value of σ (n), and all previous values at least i are shifted up by 1.
• Cycle insertion: this generation scheme is best described by its action on the cycles of the permutation.From a permutation σ ∈ S [n−1] and an integer i , and σ (j) = σ(j) for all other values of j.In other words, n is inserted "right after i" in its pre-existing cycle -or is added as a new fixed point, if i = n.
Because last value insertion often shifts many values by 1, it can dramatically change the number of k-cycles -that is, c k (σ) and c k (φ n (σ, i)) can be very different.For instance, the first child of the permutation (12 . . .k)(k + 1 . . .2k) . . .(n − k + 1 . . .n) formed entirely of n/k cycles of length k has no k-cycles (it is cyclic for odd k, and, for even k, it has n/k (k/2)-cycles and one (n/2 + 1)-cycle).
On the other hand, the number of k-cycles can only change by ±1 under cycle insertion: it increases by 1 if the selected element is in a (k − 1)-cycle (or if n is added as a new fixed point for k = 1), and decreases by 1 if j was previously in a k-cycle.As one descends in the tree according to the random choices of children, the probability of changing the number of k-cycles becomes arbitrarily small: it is exactly 2/n on the n-th step, as on average there is 1 element belonging to each cycle length.One can easily prove, though, that in an infinite random descent into the tree, this change in the number of k-cycles will almost surely happen infinitely often.The property holds for k = 1: the last child of any permutation always has one more fixed point; since the series n 1/n is divergent, the second Borel-Cantelli lemma implies that almost all infinite descents pass through infinitely many last children.The property for general k follows by induction on k: since the expected number of k-cycles in permutations of size n 1 is exactly 1/k (thus finite), the fact that the number of k-cycles almost surely increases infinitely often in a random descent implies that it also decreases infinitely often; and, under cycle insertion, the number of k-cycles decreases exactly when the number of (k + 1)-cycles increases.
The specific generation tree we describe in this paper has the following properties: 1.For each n 2 not multiple of k, all permutations at level n have the same number of k-cycles as their parent in the tree.
2. For each n 2 such that n = mk, all but exactly have the same number of k-cycles as their parent.
3. Whenever a permutation has the same number of k-cycles as its k-th ancestor in the tree, then all its children (and, by immediate induction, all its descendants) also have this property.
4. If a permutation σ does not have the same number of k-cycles as its parent, then the difference is ±1.
As a consequence, the evolution of the number of k-cycles in an infinite random descent through the tree is quite different from the "cycle insertion" generation tree: with probability 1, the descent will, at some (random) level in the tree, reach a permutation whose number of k-cycles is the same as its k-th antecedent; and, once this happens, this number of k-cycles will remain constant for the rest of the descent.
The first property above is only possible because of a specific property on the distribution of k-cycles in random permutations, which we have not been able to find in previous literature: if n/k = n /k , then for any integer , the proportion of permutations having exactly k-cycles is the same in S [n] and in S [n ] .We give an elementary proof, using generating functions, of this fact in the next section, and a bijective proof is a byproduct of our tree construction.
The number of permutations having a different number of k-cycles from their parent, as described in the second property above, is also minimum possible, as we shall prove in the next section.Overall, this means that our generation tree is optimal in this sense.

The generation tree
The main objective of our generation tree is to preserve, as much as possible, the number of k-cycles between any permutation σ and its direct children in the tree.Our construction often corresponds to the cycle insertion procedure as described in the previous section.
Cycle insertion will change the number of k-cycles exactly when the picked integer i belongs to a (k −1)-or k-cycle, so a natural idea when trying to design the generation tree is to use cycle insertion in all other cases (thus obtaining only permutations in which the maximum element is neither in a k-nor a (k + 1)-cycle), and somehow "fix" the remaining cases.
In these two cases, we will deviate from the cycle insertion construction.When L σ (i) = k − 1, we will most often produce a permutation σ with L σ (n) = k + 1 which cannot be obtained otherwise.When L σ (i) = k, we will most often replace i with n in its cycle, then somehow insert i somewhere else, taking care not to create or suppress any k-cycles.
The situation is made a bit more complicated by the requirement for the hereditary property (condition 3 in the previous section).

Description of the tree
We now give the global description of the tree, that is, describe, for any σ ∈ S [n] and i ∈ [n], how to construct the i-th child σ of σ.The description uses several operations and notations which will only be described later.

Generation-Tree
The root of our tree is the unique permutation of size 1.
In our generation tree, the i-th child σ of σ is defined in the following fashion: I. If all other rules do not apply: V. If = 2k, σ is special, i > δ(σ) and k n: In the description of our generation tree, we use the following notations: • Some permutations will be called special ; their full definition is postponed to § 3.3.2.Special permutations have only cycles of lengths k and 2k, with the possible addition of a single special cycle, denoted sc(σ), whose length is at most k − 1. Non-special permutations have the important property of having only non-special permutations as their children, all of which have the same number of k-cycles as their parent.
The notation τ = insert(σ, a, b) corresponds to a variant of cycle insertion: if b is not an element of σ, then it is exactly the result of inserting b after a in σ; if b is an element of σ, then one must first "remove" it from its cycle, i.e., set τ (a) = b, τ (b) = σ(a), τ (σ −1 (b)) = σ(b) unless b = σ(b), and τ (j) = σ(j) for all other j.
The tree description uses some additional operations pop, shift, cut and merge, which will be defined later.
Theorem 1.The description Generation-Tree defines a uniform generation tree for permutations, satisfying the conditions 1, 2, 3 and 4 above.
The next subsection is devoted to some enumerative considerations.The rest of the section contains the definitions of the missing operators, and the proof of some of their properties.

Optimum number of changing permutations
In any possible uniform generation tree for permutations, we will call a permutation changing if it has a different number of k-cycles from that of its parent.Because the the electronic journal of combinatorics 23(4) (2016), #P4.22 when n is a multiple of k, any generation tree will have at least some number of changing permutations at those levels.We now make this quantitatively precise.
We start by proving the fact, mentioned in § 2.2, that the distribution of the c k statistic over S [n] only changes when n is a multiple of k.
Let f k (n, ) denote the number of permutations of size n with exactly k-cycles, and q k (n, ) = f k (n, )/n! their proportion among permutations of size n.We will call such permutations (n, )-permutations.
Proposition 2. For any n 2 and , we have Proof.The statement is equivalent to a reformulation in terms of the q k 's: q k (n, ) = q k (n − 1, ) if n is not a multiple of k, and We start from the generating function for permutations according to size (exponential, counted by variable x) and number of k-cycles (ordinary, counted by variable y).From ( [14], Thm.4.7.2), this generating function is Multiplying by 1 − x, we get a new generating function: This new function is analytic in y and x k , so the coefficient of x n is zero unless n is a multiple of k, proving the first case.The second case follows immediately from the Taylor expansion of the exponential function.
The first case of Proposition 2 shows that it is at least conceivable to look for a generation tree where every permutation of size not multiple of k has the same number of k-cycles as its parent.For n multiple of k, it gives us a lower bound on the total number of changing permutations at level n of any uniform generation tree.Corollary 3. In any uniform generation tree, for any m 1, at least (mk)!k m m! 2 m−1 permutations of level mk are changing permutations.
Proof.If n = km and m − is even, then by Proposition 2 there are more (n, )permutations than children of (n−1, )-permutations.Hence at least f k (n, )−nf k (n−1, ) among the (n, )-permutations must have a parent with a different number of k-cycles.Summing over the possible gives the lower bound we are looking for: the number of changing permutations at level n = mk must be at least

Some special families of permutations
Our construction is strongly dependent on a family of permutations that we identify as special.These permutations play a key role in our generation tree and are exactly the permutations that have descendants with a different number of k-cycles than themselves.Special permutations are defined through a smaller family of permutations which we call critical.
A last family of permutations, quasi-special permutations, plays a minor role in the construction and are described at the end of this section.

Critical permutations
In Proposition 3, we gave an a priori lower bound on the number of changing permutations, valid for any possible uniform generation tree.We now define a subset of permutations with the appropriate cardinality, which will play this role in our tree.
If σ is a permutation over V and i ∈ V , σ [ ] (i) stands for the set {σ(i), • • • , σ (i)} of the first iterated images of i under σ.More generally, we let σ [a,b] (i) = {σ j (i) | a j b} and in particular σ [a,b] (i) = ∅ if b < a, and σ [0,0] (i) = {σ 0 (i)} = {i}.Definition 4. For any permutation σ over some set V of integers, let C 1 , . . ., C m be the cycles of length other than k in σ, ordered by their smallest element.Also, let s i = min C i be the minima of these cycles, with the convention that s m+1 = |σ| + 1.
All cycles of length k in σ are considered critical.Among the other cycles, C i is also said to be critical if Definition 5. A permutation σ is critical if all its cycles are critical.
Note that critical permutations have only k-and (2k)-cycles, with extra conditions on the (2k)-cycles.
Permutations of size mk made of m k-cycles are easily enumerated: there are exactly (mk)!/(m!k m ) of them.Note that this is exactly the product of all integers not a multiple of k up to 2mk.
It is easy to see that critical permutations of size mk with k-cycles are in bijection with permutations of the same size with exactly m k-cycles, among which an even number m − are selected.Indeed, merging the selected cycles pairwise into 2k-cycles (in order of their smallest elements), we obtain a critical permutation (see § 3.6.1 for the precise definition of this bijection).Note that we can easily reverse the procedure and identify which cycles have been chosen in the process.
Thus the number C(mk, ) of critical permutations of size mk with k-cycles (which implies that m − has to be even) is given by Summing over values of with the appropriate parity, we get the total number C(mk) of critical permutations of size mk as These permutations will be exactly the changing permutations in our generation tree.Note that their number matches the lower bound on the number of such permutations given by Proposition 3.

Special permutations
We now define the set of special permutations, which, in our tree, will be exactly those permutations with at least one descendent having a different number of k-cycles.In other words, special permutations will be all ancestors of critical permutations.Definition 6.A permutation σ is said to be special if it has at most one cycle of length strictly less than k (called its special cycle, and denoted sc(σ)), and the elements not in this cycle form a critical permutation.
Note that for k = 1, critical and special permutations are the same.Contrary to critical permutations, there are special permutations of all sizes n.The length of the special cycle must be |sc(σ)| = n mod k.However, for any n, all special permutations of size n have numbers of k-cycles of the same parity: for a critical permutation over the elements not in sc(σ) to exist, n/k − must be even.As for critical permutations, it is not very hard to count the number of special permutations of a given size n.
In order to construct a special (n, )-permutation σ with n/k − even, we can first build the cycle sc(σ) of size h = n mod k: there are n h (h − 1)! possibilities for this cycle if h > 0, and obviously 1 possibility if h = 0.The rest of the permutation is any critical permutation with k-cycles over the remaining elements.
Hence the number S(n, ) of special permutations of size Summing over values of yields the total number S(n) of special permutations, which we write as a proposition for further reference: Proposition 7.For n = mk + h with 0 h k − 1, the total number S(n) of special permutations of size n is given by otherwise .
Let us close this section by introducing an additional notation we shall use on special permutations in the following sections.Definition 8.For any special permutation σ of size n, we let p 1 (σ), p 3 (σ), . . ., p 2m−1 (σ) be the m minima of the m (2k)-cycles of σ, and we let The elements p j (σ) for j ∈ [2m] are called the critical elements of σ.

Quasi-special permutations
We now define a third family of permutations which we need in order to describe our uniform generation tree when k 2. Definition 9.For k 2, a permutation σ over V is said to be quasi-special if: 1. it has one (k − 1)-cycle D 1 and one (k + 1)-cycle D 2 ; 2. the permutation τ formed by the elements of σ belonging neither to 4. if τ has (2k)-cycles, its last critical element is smaller than min(D 1 ).
For k = 1, a permutation is quasi-special if and only if it is special.
Note that no constraints are imposed on the elements of the cycle D 2 other than γ(σ) and its image; in fact, these elements can be anything between 1 and γ(σ) − 1.
We now compute the number of quasi-special permutations of a given size n = mk, when k 2. Starting from an (mk, m)-permutation σ, select an even nonzero number m − of its cycles, write γ for the maximum element of the selected cycles, and identify, among the selected cycles not containing γ, the one with the largest minimum element; call this element p.We obtain a quasi-special permutation by removing σ(p) from its cycle, and inserting it after γ, then merging the remaining selected cycles pairwise in increasing order of their minima.This is bijective; starting from the quasi-special permutation, one can easily recover γ (the maximum of the (k + 1)-cycle), remove its image and insert it after the minimum of the (k − 1)-cycle, and split all (2k)-cycles into k-cycles.
Hence, the number Q(mk) of quasi-special permutations of size mk is given by By the same reasoning, we obtain a formula for the number of quasi-special permutations of size n = mk with exactly k-cycles (m − < m even),

Some simple cycle manipulations
As a preliminary to defining the operators on permutations that we need in order to fully describe our generation tree, we now define some simple transformations in terms of cycles.
We have already described the insert operation that we use to add an element to a cycle.
We will have on occasion to remove an element from a permutation.This is a partial inverse to the insert operation.When we mention the permutation σ obtained by removing an element b from its cycle in a permutation σ ∈ S V , we mean that σ ∈ S V \{b} is such that σ = insert(σ , σ −1 (b), b).Equivalently, σ = remove(σ, b) is defined as follows: We still need two more operations on permutations that are defined in terms of their cycles: splitting a cycle into two cycles, and the opposite operation of connecting two different cycles.Both operations correspond to the same composition with the transposition τ a,b = (a b), and the effect (splitting a cycle or connecting cycles) depends only on whether a and b lie inside the same cycle in the original permutation.
If σ ∈ S V and a, b are two elements of V , then the permutation σ = τ a,b • σ is defined as: If a and b are in the same cycle in σ, then the above operation will result in splitting the cycle into two cycles, one containing a (and its iterated images under σ up to σ −1 (b)) and the electronic journal of combinatorics 23(4) (2016), #P4.22 one containing b (and its iterated images up to σ −1 (a)); to make it clear, we shall use split(σ, a, b) to denote the obtained permutation, with the convention that split(σ, a, b) = σ if a and b are already in different cycles.On the other hand, if a and b are in different cycles in σ, this composition results in merging the cycles of a and b into a single one; to make it clear, we will use connect(σ, a, b) in this case, and we set connect(σ, a, b) = σ when a and b are in the same cycle in σ.

Insertion into (k − 1)-cycles
We now define an operator pop which is the key ingredient of our generation tree.In our construction, it is used to define the i-th child of a permutation σ in most cases where i is in a k-or (k − 1)-cycle of σ.By itself, it would be a sufficient ingredient to define a generation tree with the "preservation of c k " property (conditions 1 and 2 of our tree); most of the added complexity is there because we want to ensure the "heredity" property (condition 3).
This operator can also be seen as providing a bijective proof of Proposition 2, as we shall see.

The pop operator
Let σ ∈ S V be some permutation, and i ∈ V , such that • σ(i) is the largest element of its cycle in σ, and σ(i) > γ(σ).
Under these conditions, we define σ = pop(σ, i) ∈ S V below.The important properties of pop are given by the following proposition.
Proposition 10. pop defines a bijection between, on the one hand, non-critical permutations σ with a marked element i such that σ(i) > γ(σ), σ(i) is the maximum of its cycle, and L σ (i) = k; and, on the other hand, permutations σ on the same set such that L σ (γ(σ )) = k + 1 and σ is not quasi-special.Moreover, whenever σ = pop(σ, i), then Note that the conditions on σ imply that it is not special: if k > 1, the existence of a (k + 1)-cycle is sufficient; if k = 1, quasi-special and special permutations are the same.
To define pop, we first need to define p(σ) for non critical permutation σ, and in some cases, we further define p (σ) and p (σ). Definition 11.For any non-critical permutation σ, p(σ) is the smallest element in a non-critical cycle.Furthermore, if L σ (p(σ)) > k, we define p (σ) as the smallest element in a non-critical cycle that is not in σ [0..k −2] (p(σ)) (excluding p(σ) in the case k = 1), and p (σ) as the second smallest such element.
The definition of the operator is given in the description pop-operator.All rules are presented in Figure 3.Note that some rules actually define σ in the same way, and are kept separated for later convenience: 1a is identical to rule 1b in that they define σ = insert(σ, γ, σ −1 (p)); rules 2a and 2b both define σ = split(σ 1 , p, y); 3(a)i and 3b both define σ = insert(σ 1 , y, y).Similarly, 3(a)ii and 3c correspond to the same action applied to p for the former, and p for the latter; this is also true of 3(a)iii and 3d.
Remark 12. Let us consider how this operator works when k = 1.In this case, the target set of the operator are non-special permutations σ where γ(σ ) is in a 2-cycle.
Moreover, we have x = p, y = σ(p) and i = γ(σ).Hence some rules are never applied: rule 1a because p cannot be a fixed point, rules 2a and 3a because x cannot be p , rule 3b because p cannot form a 2-cycle with p , and rule 3d because there are no 0-cycles.The three remaining rules (1b, 2b and 3c) are recalled in a simpler form with the description of the tree for k = 1 (in Section 4.2) and depicted in Figure 4.
Proof.We construct a preimage (σ, i) for any non-quasi-special permutation σ with We distinguish three cases, building in each case a permutation σ where i is a fixed point.In each case, the other fixed points of σ are exactly those of σ .
. In this situation, p is in a cycle of length at least 2 in σ , hence in a cycle of length at least 3 in σ (hence p = p(σ)) and σ(p) = p (σ). Hence rule 1b applies to (σ, i) (rule 2b does not apply) and one easily checks that σ = pop(σ, i).
Lemma 14.For k 2, pop is onto.
Proof.We construct a preimage (σ, i) for any non-quasi-special permutation σ with L σ (γ(σ )) = k + 1.More precisely, for each possible σ , we identify one of the ten rules of pop and describe a preimage (σ, i) to which said rule applies, and yields σ .In each case, σ has exactly one more k-cycle than σ .
In all the following cases (numbered by the corresponding rule of pop which yields σ ), it should be clear that the cycle containing i (and γ) in σ shall be of size k (hence critical), since the defined permutation σ will always remove a from its cycle (and leave other k-cycles untouched, resulting in σ having exactly one more k-cycle than σ ).
Furthermore, all other cycles with a minimum less than p shall not be modified in the construction of σ, hence these cycles shall remain critical in σ.Under these two conditions, we deduce directly that p = p(σ) if the cycle of p is not critical in σ.In the following, we will not recall these two "easy" properties of σ.
Let us first deal with two specific cases.
In these first two situations, p is in a cycle of length strictly less than k in σ: in the first case, it is a fixed point in σ (and we assumed k 2), and in the second case, it is in a cycle of length L σ (p) + 1 < k.Thus p is in a non critical cycle in σ, and therefore p = p(σ).
In the first case, rule number 1a applies on (σ, i) and yields σ .In the second case, rule 1b is the only applicable rule, and its application to (σ, i) results in the permutation σ .
We now move to the remaining cases.From now on, we assume a = p and L σ (p) k − 1.
Let us further define two distinguished elements in σ : p and p .We define p (resp.p ) as the smallest element (resp.second smallest element) in a non-critical cycle in σ that does not belong to σ [0,k−2] (p).Since σ contains a fixed point larger than p (namely, a), p is always well defined.Moreover, note that if p = a and no element p can be found in σ (that is, p is in the largest non critical cycle in σ ), then the permutation σ is quasi-special (and hence out of the scope of the lemma): indeed, in this situation, γ = γ(σ ) is in a (k + 1)-cycle, p is the minimum of a (k − 1)-cycle, p = σ (γ) is larger than p, and all other cycles are critical in σ .If p = a, at the very least, two elements larger than p are in non critical cycles in σ .Overall, p and p are always well-defined under our current assumptions.
In all remaining cases, we shall have σ (p), thus we get p = p (σ) and p = p (σ) whenever p (σ) and p (σ) are in non critical cycles of σ.
We shall see in each rule that p(σ) = p, thus, for elements larger than p (which includes p and p ), not being in critical cycles of σ reduces to not being in k-cycles; this is easily checked for the different rules.
Let us now consider all cases where L σ (p) > k.In this case, we increase the length of the cycle of p by one, and since by hypothesis it was different from k − 1, this cannot create a k-cycle.Moreover, we shall have p(σ) = p, as the only possibilities to create a critical cycle of length 2k are captured by the previous two cases.Indeed, since we insert a in the second part of the 2kcycle, the first part should already satisfy the critical condition in order for the condition to hold for the full cycle.However, this implies either p = σ k (p) or p = σ k−1 (p) and p = σ k (p); and both of these situations are already covered by the two previous cases.Now let us check that rule 1b is the rule that applies to (σ, i), i.e., that rule 2 does not preempt it.By definition of p, it is not in a critical 2k-cycle.Hence, if ), the cycle of p must be of size other than 2k.Increasing such a cycle cannot produce a (2k + 1)-cycle and thus rule 2 will never be used on σ.
We are now left with the only remaining case: In this part, we will often have to insert two elements, one after the other, after the same element in σ ; we use here the notation τ = insert(τ, i, a, b) as a short form for τ = insert(insert(τ, i, b), i, a).
The three next cases cover the case a = p .Finally, the last three cases cover the remaining situations.
Analysing the ten rules depicted by Figure 3, we observe that cycles of σ other than those containing i, p, and possibly p and p all appear identically in σ ; furthermore, the elements of the cycle containing i are absent from σ .Consequently, since p = p(σ) is the smallest element not in a critical cycle, p(σ ) is either equal to p (if its cycle in σ is not critical) or larger than p (if its cycle in σ is critical).To prove that we have p = p, we need to prove that the latter case is not possible.
Note that the cycle of p in σ cannot be of length k, and can be of length 2k only when rule 1b is applied: rules 3(a)iii and 3d place p in a (2k − 1)-cycle (and we have assumed k 2); rule 1a places it in a (k + 1)-cycle, and all other rules except 1b place it in a (k − 1)-cycle; and, since rule 1b reduces by 1 the length of the cycle containing p and only applies if this length is not k + 1, the length in σ cannot be k.Overall, only rule 1b could result in p being in a critical cycle (of length 2k) of σ .Now, in rule 1b, the cycle containing p in σ (hence in σ as well) is obtained by just removing σ −1 (p).For this cycle to become critical in σ , it would have to be of length 2k +1 in σ, with the extra condition that σ k (p) be smaller than all elements in non-critical cycles of σ except σ [0,k−1] (p); this condition reduces exactly to y = p or x = p , y = p , which are excluded from rule 1b.Thus, even when rule 1b is applied, the cycle containing p is not critical, and we have p = p.
The first part of our proof shows that no permutation σ can be obtained by applying two different rules, i.e., the images of the ten rules are pairwise disjoint.For each rule, we give a condition that can only be satisfied when applying this one rule, and leave it to the reader to check that it is indeed the case.Rule 1b is the most complex, since we have to include the condition that rule 2 does not apply.All that remains to do to prove the lemma is to prove that each rule of pop is oneto-one.Suppose now, two distinct pairs (σ 1 , i 1 ) and (σ 2 , i 2 ) have the same image σ by the same rule of pop.Necessarily, we must have i 1 = i 2 = σ −1 (γ), and by Lemma 15, p(σ 1 ) = p(σ 2 ).
Analysing each rule, one may note that all cycles of length 2k in σ 1 and σ 2 with a minimum less than p(σ 1 ) are critical and are present in σ ; these cycles must thus be identical in σ 1 and in σ 2 .Similarly, the k-cycles of σ (other than the one containing i) are also present in pop(σ, i), so that σ 1 and σ 2 have the same k-cycles.
Finally, if the permutations σ 1 and σ 2 differ on the cycle of p (or p , or p , depending on the rule), applying the same rule to both σ 1 and σ 2 results in different permutations; whereas if σ 1 and σ 2 differ in another place, the permutations obtained using the operator are again different as other cycles are not modified.
Hence σ 1 = σ 2 and pop is indeed an injective function.

A bijection for permutations with no k-cycles
Let D k n be the set of permutations of [n] with no k-cycles, and Q k n the set of quasi-special permutations of [n] with no k-cycles.Recall that we denote f k (n, 0) = |D k n |.Using only the operator just defined, we can easily describe a bijection where the excluded set SP k n−1 is the set of pairs (σ, i) in which σ is special and L σ (i) = k − 1.Note that for SP k n−1 to be nonempty, n must be a multiple of k (the existence of a (k − 1)-cycle in a special permutation implies that the size is −1 mod k).
This bijection χ n gives a combinatorial proof of the recurrence relation for f k (n, 0) given in Proposition 2 (which we already proved analytically, in the proof of Proposition 3, for all numbers of k-cycles).
This bijection can be seen as a generalization of a previous bijection τ n for derangements (permutations with no fixed points, that is, the case k = 1) due to Rakotondrajao [13].The bijection τ n is defined from , where ∆ n is the unique critical derangement of size n, for n even: it is the derangement (12)(34) . . .(n − 1 n).
The bijection of [13] gives a nice combinatorial proof of a well-known recurrence over the number of derangements, d n = |D n |: d n = nd n−1 + (−1) n .Proposition 2 gives a generalization of this recurrence for any k 1; note that by taking k = 1, we recover the original recurrence over derangements Let σ be a permutation of size n − 1 with no k-cycles, and i ∈ [n], such that σ is not special or L σ (i) = k − 1.We define σ = χ n (σ, i) as: Proof.The first case describes a bijection between the pairs (σ, i) where i is not in a (k − 1)-cycle and permutations with no k-cycles where n is not in a (k + 1)-cycle; the second case is a bijection between the remaining pairs and permutations with no k-cycles where n is in a (k + 1)-cycle.
The link with the case = 0 of Proposition 2 is as follows.When n is not a multiple of k, both SP k n−1 and Q k n are empty, and χ n constitutes a bijective proof of the recurrence When n = mk, one of the two sets is empty, depending on the parity of m: • For even m, SP k n−1 = ∅: special permutations of size n − 1 with no k-cycles must consist of one (k − 1)-cycle and a number of (2k)-cycles.In this case, χ n constitutes a bijective proof of the recurrence • For odd m, Q k n = ∅: quasi-special permutations of size n with no k-cycles consist of one (k − 1)-cycle, one (k + 1)-cycle and a number of (2k)-cycles.In this case, since each special permutation of size n − 1 has exactly one (k − 1)-cycle, it appears in exactly k − 1 pairs in SP k n−1 , and χ n constitutes a bijective proof of the recurrence the electronic journal of combinatorics 23(4) (2016), #P4.22

Some other operators for (special) permutations
We define here the three remaining operators that our tree construction relies on.These are necessary to preserve the special subtree, that is, the property that all special permutations are children of other special permutations in our generation tree.They all use the largest element of a permutation σ which is not in a k-cycle, denoted γ(σ).
3.6.1 Decreasing the number of k-cycles: the merge operator In our tree, this merge operator serves to define special children with one fewer k-cycles than their parent.Its direct effect on the cycle type is that two k-cycles are replaced by a (2k)-cycle; some care needs to be exercised to ensure that the result is a critical permutation.
Precisely the operator merge is defined over some acceptable pairs (σ, i) such that σ is a critical permutation over S [n] , n and i are in two different k-cycles, σ(i) is the maximum of its cycle and σ(i) > γ(σ).
This operator splits each (2k)-cycle of σ into two k-cycles, one for each critical element of the cycle, then reconstructs σ by including the cycles containing n and i in the new (2k)-cycles set, based on the simple bijection shortly outlined § 3.3.1.
Let us define properly this bijection first.For a permutation τ of size mk constituted only of k-cycles, of which are marked (with m − even), we call join(τ ) the critical permutation of size mk obtained as follows: • we order the unmarked cycles C 1 , C 2 , . . ., C m− of τ in increasing order of their minimal elements; • we join these cycles pairwise by connecting C i to C i−1 for even i, i.e., Note that this operation defines a bijection from its input set to critical permutations, as we can easily recover the permutation τ formed by m cycles of length k from any critical permutation τ of size mk by splitting the (2k)-cycles of τ ; the marked cycles of τ are exactly the k-cycles of τ .
Proposition 18. merge defines a bijection between its acceptable pairs and critical permutations where n is in a (2k)-cycle.The image has exactly two fewer k-cycles than the permutation in the pair.Proof.The first step in merge is a bijection between acceptable pairs and permutations with only k-cycles with an even number of unmarked cycles, with n belonging to an unmarked cycle; here, i can be recovered from the marked permuation by first recovering σ(i) as the maximum element among the unmarked cycles not containing n.
The second step is reduced to join, and is also bijective from marked permutations with the cycle of n unmarked, and critical permutations with n in a 2k-cycle.

Special children: the shift operator
We now define an operator shift that bijectively maps some valid non-special permutation τ to some special permutation σ on the same set, which contains at least one (2k)-cycle.The conditions on τ are as follows: • σ = remove(τ, γ(τ )) is a special permutation whose special cycle (if it exists) has length other than k − 1; , where δ(σ) is the minimum element of the special cycle of σ (0 if |σ| = 0 mod k).
The purpose of the shift operator in the construction of our generation tree is to ensure the heredity condition: that special permutations only appear as children of special permutations.When trying to define the i-th child of a special permutation σ, if i happens to be in a cycle of length k or 2k in σ, using cycle insertion would result in a permutation that has a (k+1)-or (2k+1)-cycle, thus a non special permutation; and in other situations, cycle insertion may result in special permutations being children of non special ones, which we want to avoid completely.The shift operator is used to "switch children" in the tree in order to maintain the hereditary property.
Informally, the way shift −1 acts is by "shifting up" the sequence of critical elements of a special permutation (obtaining a non special permutation as the result) in such a way that the operation can be reversed.It is slightly more natural to define the reverse operation (from non special to special permutation) as shift, illustrated by Figure 5.
• If i = p j for some j ∈ [2m], then let be the smallest integer larger than j, such that p > min(σ [k−1] (p −1 )) (if such an does not exist, we set = 2m + 1).Let a = min(σ [k−1] (p −1 )), and let σ be the permutation obtained after these − j + 2 insertions: In other words, each of the p h (for j h − 2) in τ is replaced by p h+1 in the cycle structure of τ , p −1 is replaced by a, a is replaced by γ, and i = p j is inserted after δ (or as a new fixed point if δ = i, that is, if τ is of size 1 mod k).Thus, most cycle lengths are the same in σ and τ ; the only ones that change are the (2k + 1)-cycle that becomes a (2k)-cycle, and the one cycle of length less than k (the special cycle in σ) that increases its size by one.The conditions on the choice of and a ensure that, even though the critical elements of σ are replaced by larger values, σ is indeed a special permutation.
Proposition 19.The shift operator defines a bijection between its valid inputs τ and special permutations σ on the same set with the same number of k-cycles, where γ(σ ) is in a (2k)-cycle.
Proof.We have already argued that σ is special.It has the same number of k-cycles as τ ; in fact, it has exactly the same k-cycles.In the definition, γ is placed in a (2k)-cycle; and, since the elements in k-cycles are the same in τ and in σ , we have γ(σ ) = γ.Thus, shift(τ ) is of the claimed type.Also, note that the validity conditions on τ (in particular, i > δ(τ )) ensures that δ(σ ) = δ.
To prove that shift is indeed bijective, we prove that for any permutation σ of the claimed type, there is only one possible preimage τ , and leave it to the reader to check that applying shift to this τ does yield σ .
Starting from σ , we already know that γ can be identified as γ(σ ); i can also be identified as σ (δ(σ )).The shifted critical elements can then be identified (in σ ) as the critical elements larger than i, up to and including the critical element p j such that γ ∈ σ [k−1] (p j ) (possibly none, if this p j is smaller than i).Then, τ can be recovered from σ by replacing each of these critical elements by the next (the smallest one is replaced by i, and the last replaces γ), then inserting γ after i.

Generating quasi-special permutations: the cut operator
Our last operator σ = cut(τ ) defines a bijection between critical permutations τ with at least one (2k)-cycle, and quasi-special permutations σ on the same set.Its direct effect on the cycle type is that a (2k)-cycle is replaced by a (k − 1)-cycle and a (k + 1)-cycle.
Recall the conditions on a quasi-special permutation σ : it has one (k + 1)-cycle, one (k − 1)-cycle, and any number of k-cycles and (2k)-cycles; when ignoring the two (k ± 1)cycles, it is special; the minimum element p in the (k − 1)-cycle is larger than all "critical" elements; the maximum element γ in the (k + 1)-cycle is larger than all elements not in k-cycles; and finally, its image p = σ (γ) is larger than p.Now let us start from a critical permutation τ with at least one (2k)-cycle.
Let us define how the permutation σ is obtained through this operator.Let m 1 be the number of (2k)-cycles in τ , γ = γ(τ ) and let p be the largest critical element of τ such that γ ∈ τ The permutation σ is obtained through the following process: 1. τ 1 , a permutation of k-cycles only with some cycles marked, is obtained by splitting all (2k)-cycles of τ at their critical elements, that is, τ 1 = join −1 (τ ); 2. mark two more cycles in τ 1 to get τ 2 : those containing γ and p (these two cycles are distinct from the definition of p); Proposition 20. cut defines a bijection between critical permutations with at least one (2k)-cycle, and quasi-special permutations on the same set.Furthermore, the numbers of k-cycles of τ and cut(τ ) are the same.
Proof.We start by checking that σ defined above is indeed a quasi-special permutation.Its cycle structure is appropriate: τ 3 has only k-and (2k)-cycles, and the last insertion operation removes an element from one of the k-cycles to insert it into another one.The fact that, when these two (k ± 1)-cycles are ignored, the rest is a critical permutation is guaranteed by the join operation.The minimum element p in the (k − 1)-cycle is larger than the largest critical element of τ 3 .Obviously, the elements not in k-cycles are the same in τ and σ , so that γ(σ ) is indeed γ, and is in the (k + 1)-cycle of σ (and σ and τ have the same number of k-cycles).Finally, p is the minimum of its cycle, so that p > p is also guaranteed.These are exactly the conditions of a quasi-special permutation.We now check that any quasi-special permutation σ can have only one preimage τ , and describe the inverse map; again, we leave it to the reader to check that this is indeed a preimage.

Proof of the main theorem
In this section, we prove the main result of the paper, namely, that our definition, given in page 6, does define a uniform generation tree with the desired properties.We first prove the general case k 2; the case k = 1, together with the somewhat simplified description of the tree, will be treated later.

Proof for k 2
Before going to the proof of the theorem, we make some comments on the definition, and derive some easy properties.
First note that the conditions on the use of rules II to VI are mutually exclusive, so that, by the fact that rule I covers exactly the cases not covered by the others, our description uses exactly one rule for each possible pair (σ, i) (we will check later that the rules are well defined, i.e., that the operations are always used with proper arguments).
The condition of rule I was not made explicit in the description, but it can be expressed easily.The rule is applied when one of the following statements holds: Now note that in the definition, is always either 0 or the length of a cycle in σ.This makes it clear that rule I is the only one which is applied both to special and non-special permutations: rules II, III, and IV are used only for non-special permutations (the latter two imply that σ contains a 2k − 1 cycle), and rules V and VI for special permutations.Another useful property that always holds is + 1 = L ζ (i), and ζ(i) γ(ζ) (just check the three cases of the definition of ( , ζ)).
For the remainder of the proof, we note γ = γ(σ) and L(j) for L σ (j).We now examine each individual rule and, for each one, we do three things.We check that the permutation σ is well defined (that is, the corresponding operator can be applied); we determine whether σ is special; and we determine the number j of k-cycles of σ , assuming its parent permutation σ has j cycles of length k.I.In this rule, either a fixed point is added, or the length of exactly one cycle containing i or γ increases by one: • if L(i) = k, ζ corresponds to cycle insertion after i; since the cycle of i cannot be of length k − 1 (captured by rules II and VI), σ has the same number of k-cycles as σ.
the electronic journal of combinatorics 23(4) (2016), #P4.22 • if L(i) = k and i < γ, ζ corresponds to the permutation where i is replaced by n, then i is inserted just before γ, thus increasing the length of γ's cycle by one in σ .Since L(γ) = k − 1 (captured again by rules II and VI), we get j = j again.• if L(i) = k and i > γ, ζ is the permutation obtained by replacing i with n, then inserting i as a fixed point, hence j = j in this case as well.
Moreover if σ is non special, σ is non special as well, because there are only three ways for this cycle insertion to create a special permutation, and each one is prevented in this situation: • inserting into a cycle of length strictly less than k − 1, but in this case σ would have been special; • inserting into a cycle of length k − 1, but rule I does not apply in this case; • inserting into a cycle of length 2k − 1, but rules III and IV exactly capture this case when ζ is special.
If σ is special, there is only one possibility for σ to be special as well, that is, if we insert into the special cycle, and it happens to be of length strictly less than k − 1.This corresponds to the case < k − 1 (note the case = k − 1 is captured by rule VI).In the only other possible situation where rule I applies to a special permutation (that is, = 2k but the condition of rule V fails), the permutation σ obtained after rule I is not special since it contains a cycle of length 2k + 1. IV.In this rule, ζ is critical and has a (2k)-cycle, hence the operator cut is defined on ζ; σ is quasi-special (hence not special), and its number of k-cycles is the same as that of ζ (and of σ).
V. (a) Since σ is special, i > δ(σ) and n is not a multiple of k, so that the special cycle in σ, whose length is n − 1 mod k, has length strictly less than k − 1.In this case, This case by case analysis shows that, provided our construction does define a generation tree (which we shall prove next), the tree does have all the claimed properties.We summarize them in the following lemma: Lemma 21.The parent of each special permutation is special.The number of k-cycles of a permutation is different from that of its parent if and only if both are special, and the former is critical; the difference in the number of k-cycles is ±1, depending on whether rule VIa or VIb is used to obtain the child from the parent.
We now turn to proving that our construction is indeed a generation tree, that is, we have defined, for each n, a bijection between S [n−1] × [n] and S [n] .Since both sets obviously have the same cardinality, all we need to do is prove that the transformation is one-to-one by exhibiting necessary conditions on a preimage for each permutation.
Let σ be any permutation of size n, γ = γ(σ ) and τ = remove(σ , γ) the permutation of size n − 1 where γ has been removed from its cycle.
We can now note that all other rules describe σ as the image of ζ or (ζ, i) by a bijective transform (shift, shift −1 , pop, cut, merge, and the identity restricted to the application cases of rules I and VIa).Thus, if we check that the images of these transforms are pairwise disjoint, then we know that some ζ or pair (ζ, i) can be recovered from σ .In those cases where only ζ is recovered this way, we also show how i can be independently recovered.Then, the proof is completed by checking that knowing ζ and i is enough to recover σ (that is, the mapping (σ, i) → (ζ, i) is injective).
The various images correspond to the following (pairwise incompatible) descriptions: I.
V. (a) σ is special, Let us give a few words of explanation as to why these rules cover all possible cases.The case γ = 0 is included in condition Vb (it corresponds to σ having only k-cycles).When γ = 0, we have a disjunction based on the value of L σ (γ): value k + 1 is covered exactly by rules II and IV; value 2k + 1, by rule III and the last case of rule I; value 2k is covered by the second case of rule I and rules V and VI; and all other values by the first case of rule I.
Since these conditions cover all possibilities, each permutation σ must fall in one condition, and we can deduce then a rule, the permutation ζ and the value of i = σ −1 (γ) for all cases (except the case of rule Vb which was treated above).
Once i and ζ are known, it is straightforward to reconstruct the permutation σ as σ = remove(insert(ζ, n, i), n).

Generation tree for k = 1
When k is 1 (that is, we are interested in the number of fixed points in permutations), the values 2k and k + 1 coincide, and though the general description of the generation tree is still valid, some of our arguments for the previous proof are not; and at the same time, some of the rules in the general description never apply.We now provide a more compact description of the same generation tree in this case; the reader should check that what follows is indeed equivalent, when k = 1, to what we gave earlier.
The authors gave in [6] a description of a generation tree with similar properties to the one described here for k = 1, but it should be stressed that the tree is not the same.The tree described here is almost identical to the one appearing in the second author's Ph.D. thesis [8], with slight changes introduced by taking images in place of preimages in rules (3.a) and (4.c), and reversing the 3-cycle of p in rule (4.b).
For the rest of this section, we assume k = 1.Recall that in this case, "special", "quasi-special" and "critical" permutations are the same.Special permutations of size n are made of an arbitrary set of fixed points such that n − is even, and the rest of the permutation forms the unique critical permutation over the remaining elements, that is, n i n (2) The remaining constructions are illustrated in Figure 6.It should be clear that this construction defines a uniform generation tree, since from any permutation σ we can identify which rule has been applied and easily reverse the operation: • rules 1 and 2 build special permutations with n either as a fixed point or in a 2-cycle, and i = σ −1 (n).

Probabilistic consequences
In this section, we describe a few applications of our tree construction in a probabilistic setting.

Stabilization time for the number of k-cycles
Special permutations make up a vanishing proportion of all permutations of a given size as size goes to infinity; thus, the probability that a random descent reaches a changing permutation at a given level goes to zero.Thanks to the heredity property of our generation tree, almost surely, the number of k-cycles in the permutations of a random descent is ultimately constant.More precisely, almost all descents will reach a non-special permutation, and all permutations reached from then on will have the same number of k-cycles.
Let T denote the size of the first non-special permutation in a random descent; T is obviously a stopping time 2 .If we define time T as the stabilization time for the number of k-cycles, that is, the first index n such that for all m n we have c k (σ m ) = c k (σ n ), T is not a stopping time; for instance, in the generation tree for k = 2 as shown in Figure 1, all sequences containing the permutation (1)(2) have T = 1 (and T = 2), but just looking at the first permutation (1) (which is a special permutation) does not let one know the value of T .But, because each permutation of size a multiple of k either is non-special or has a different number of k-cycles from its parent, T cannot be larger than T + k.
For the applications we wish to describe in the rest of this section, it is useful to compute the expected value of T .
Proposition 22.Let T denote the size of the first non-special permutation in a random descent into our tree.Then T has finite expectation where H n = n i=1 1/i denotes the n-th harmonic number.
Proof.The expected time can be expressed as E(T ) = n P(T n), and the probability that T is at least n is exactly the probability that the permutation reached at level n − 1 of the tree is special, i.e., S(n − 1)/(n − 1)!.
Thus, we have Using the counting formulae of Proposition 7, we get

Uniform random generation of permutations with a fixed number of kcycles
In this section, we show how our generation tree can be used for random generation.The fact that non-special permutations have the same number of k-cycles as each of their children, and by induction as any of their descendants, allows us to design algorithms that make use of this property for sampling a uniform permutation conditioned on having a prescribed number of k-cycles.The algorithm we get is efficient both in time/space complexity and in randomness complexity.The randomness cost can be estimated by two different parameters, and we analyze our sampling algorithm for both: the number of random bits used by the algorithm (which we call the random bit complexity), and the number of calls to a unit-cost Random(m) primitive that returns a uniform number in [m] (which we call the random integer complexity; all calls to such a Random primitive would be with parameters bounded by n).
In the discussion that follows, we consider both k and to be constants (the asymptotics is only for large n), though they may be large constants.
A very basic rejection algorithm to sample uniformly a (n, )-permutation, that is a permutation of size n with exactely k-cycles, is to generate uniform permutations of size n, until one is obtained that has exactly cycles of length k.Since the probability of success f k (n, )/n! converges (quickly, see [2]) to e −1/k /(k !) in the large n limit, this simple rejection method needs to generate, in expectation, e 1/k k !+O(1/n!) permutations of size n.Thus its expected random integer complexity is e 1/k k !n + O(1/(n − 1)!) when using standard methods for generating permutations, such as the Fisher-Yates shuffle, also known as Knuth shuffle (see [9,7,10]).
If is large, this cost is impractical.There is an easy trick to avoid this large multiplicative constant in front of n: we can generate separately the k-cycles and the rest of the permutation.To do so, we can sample k elements from [n] by k successive calls to a uniform sampler, the i-th call using Random(n − i + 1) in order to get one of the remaining elements -this can be done easily in O(1) per generation by just swapping some elements in a table, in a Fisher-Yates fashion.At the same time as selecting these elements, we can build k-cycles in the same order as their selection: each ( k, )-permutation of the selected elements is equally likely this way.Then the second part asks for a uniform (n − k, 0)permutation of the remaining elements.In order to generate such a permutation of size n − k, a naive rejection algorithm in the same spirit as in the previous paragraph needs in average e 1/k (n − k) + O(1/(n − k − 1)!) calls to a random sampler.Hence this method yields an algorithm with random integer complexity e 1/k n + k(1 − e 1/k ) + o(1).
For any value of n, and k the above method is satisfactory in a practical sense.However, we can improve the multiplicative constant and obtain, thanks to our generation tree, a new random generation algorithm with random integer cost n + O(1) calls to Random().This algorithm is a rejection algorithm heavily based on our generation tree.
Since e 1/k is rather close to 1 for values of k larger than a few units, the most interesting case in such a generation process remains the uniform generation of derangements (k = 1, = 0).
In the literature, [12] proposes an equivalent of the Fisher-Yates shuffle for derangements, resulting in a bounded time algorithm with an expected random integer complexity of 2n + o(n).In [1], experimental studies are performed comparing this method and the anticipated rejection method, resulting in comparable results; an extension to permutations having only cycles of length at least m 3 is also given.In [6,8], a generator using n + O(1) calls is given, matching the cost of an algorithm sketched at the end of [3], which is based on Lehmer encoding and a specific bijection of permutations, and not directly on derangements.
We propose the following natural algorithm UniformPerm0(n,k) in order to sample uniformly a permutation of size n with no k-cycles: 1. Perform a random descent in our generation tree until reaching a non-special permutation σ or level n, whichever comes first.
2. If the reached permutation has no k-cycles, continue the descent until reaching level n and return the permutation obtained at the end; otherwise, repeat Step 1.
Proposition 23.UniformPerm0(n,k) returns a uniform permutation of size n that does not have any k-cycles; it has expected random integer complexity n + O(1).
Proof.The algorithm works as an anticipated rejection method: it is equivalent to performing a uniform sampling of a permutation of size n, and as soon as the generated permutation is known to have cycles of length k, the algorithm aborts and retries; otherwise it returns the sampled permutation.Thus the returned permutations are uniform (n, 0)-permutations.The properties of the generation tree are used to make anticipated rejection efficient.Let A = A n be the random variable describing the number of calls to Random() used by the algorithm on input n; recall that k is assumed to be a constant.We separate the cost into two contributions corresponding to the two phases of the algorithm, such that A = C 1 + C 2 , where C 1 counts the calls to Random() made (including rejections) until a (n, 0)-permutation is obtained that either is non-special, or has size n; and C 2 counts only calls made by step 2 of the algorithm.
We have E(C 1 ) = E(C)/α, where C is the number of calls during one trial of the first phase, and α = q k (n, 0) the probability of success for each trial.
From the exponential generating function G k (x, 0) = exp(−x k /k)/(1 − x) counting the number of (n, 0)-permutations (see proof of Proposition 2), we get q k (n, 0) as the coefficient of x n in G k (x, 0): (−1) j k j j! .
the electronic journal of combinatorics 23(4) (2016), #P4.22 Algorithm 1 Poisson1 n ← 1, g ← 0, k ← 1 loop i ← Random(n + 1) As stated in the introduction, since we know that the limit distribution of the number of k-cycles of uniform permutations of size n is the Poisson distribution with expectation 1/k, we deduce the correctness of the algorithm from the fact that it returns precisely the limit of such a vector (σ n ) n 1 -recall that after reaching a non special permutation, further descents in the tree yield permutations with the same number of k-cycles.
For the case k = 1, special permutations have a particularly simple form, and the algorithm Poisson1 is even simpler.It only needs to keep track of 3 integers representing the size of the permutation, the largest non-fixed point and the current number of fixed points.
From a Poisson distributed variable X 1 of expectation 1, it is easy to deduce another random variable X 1/k , which follows this time the Poisson distribution with mean 1/k: X 1/k is the number of heads in X 1 biased coin flips with parameter 1/k.For any k, the number of times the Random() primitive has to be used in such an algorithm is given by 1 + (e 2 − 1)/2 = (e 2 + 1)/2 ≈ 4.20; comparing this with the expected random integer complexity of Poisson-1/k shows that the latter is more efficient for k 32.
We now turn to a short analysis of the random bit complexity of our Poisson1 algorithm.
Proposition 26.The Poisson1 algorithm uses, in expectation, between 6.89 and 6.9 random bits, assuming the Random primitive is optimal in terms of random bits used.
Proof.Let B be the number of random bits used by the algorithm and B n the number of random bits (if any) consumed at level n of the tree, so that C = ∞ n=2 C n .We have E(B n ) = 2 n−2 (n−1)!E(U n ), where U n is the number of bits used by an optimal uniform sampler Random(n) in the sense of [11]; the 2 n−2 /(n − 1)! factor is simply the probability of reaching level n of the tree.The inequality log 2 (n) E(U n ) log 2 (n) + 2 is valid for all n, but using it blindly to bound the complexity of our algorithm gives an upper bound of 9.59, significantly more bits than we want.k-cycles: for example, an even number.We expect our tree to make many rejection-based algorithms for this kind of task particularly efficient.More generally, we are eager to see if such a construction can be adapted to other families of combinatorial objects, keeping in mind the potential gain for new efficient generation algorithms for such objects.Indeed, the generation process described in Section 5.2 replaces a multiplicative constant by an additive constant, in the expected cost of the algorithm.For combinatorial objects representing an exponentially (in k) small part of an easy to sample set, using an adaptation of our method may lead to still generate those objects in time proportional to n + O(1) instead of the exponential multiplicative cost induced by a classic rejection algorithm.

Figure 2 :
Figure 2: Illustration of split and connect procedures.Dashed and dotted lines represent (potentially empty) portions of a cycle, i.e., iterated images under σ starting from the source of the edge until the target is met.

Figure 3 : 3 Figure 4 :
Figure 3: Illustration of the different rules of the pop operator for k 2. Plain lines indicate direct images under σ or σ , dashed and dotted lines indicate portions of cycles.Lengths of cycles are shown as integers inside or over cycles.All cycles are implicitly non critical and hence of length not k.Conditions are not shown (see text).

Figure 5 :
Figure 5: Illustration of the shift operator when i is a critical element: i = p j .Dotted arrows represent new positions of elements after the application of the operator.
II.Since σ is not special in this rule, ζ, which is obtained from σ by inserting some value into a (k − 1)-cycle, is not critical.Second, the newly created k-cycle in ζ contains i (just check the two first cases of the definition of ζ).Third, ζ(i) is either n or γ(σ); in both cases, ζ(i) is maximal in its cycle and larger than the maximum element of ζ not in a k-cycle.These three conditions show that pop(ζ, i) is well defined.By the properties of pop, σ is not special and j = j.III.Here ζ is special, γ(ζ) is either n or γ, and γ(ζ) is in a (2k)-cycle of ζ.Hence ζ lies in the image of shift, so that σ is well defined and non special, and j = j.
1)-cycle of ζ, and removing this value from ζ yields a special permutation (which may be σ, or another special permutation).Thus ζ matches the criteria to apply the shift operator, and we get a special σ with j = j.(b) In this situation, σ is obtained by replacing i by n (keeping the same number of k-cycles) and placing it after δ(σ) thus making σ special as well by only increasing the length of the special cycle; again, we have j = j.VI.(a) This rule (identical to rule I but kept separate because it plays a specific role in our proof) inserts n after i, thus creating a new k-cycle in σ .Since other elements are left undisturbed, σ is a special permutation with no special cycle (n is a multiple of k), and j = j + 1.(b) In this case, n and i are in different k-cycles in ζ, ζ is critical (the (k − 1)-cycle of γ has been replaced by a k-cycle), and ζ(i) is larger than any element of ζ outside k-cycles; hence merge can be applied to ζ.The operator produces a critical permutation σ with two k-cycles fewer than ζ, thus one fewer than σ (j = j − 1).

Figure 6 :
Figure 6: Illustration of our generation tree for k = 1 and σ ∈ S [n−1] ; dashed edges represent relations in σ, whereas thick edges represent relations in σ , the i-th child of σ in the tree.Only differences between σ and σ are shown.