Abstract
We show how to generate random derangements efficiently by two different techniques: random restricted transpositions and sequential importance sampling. The algorithm employing restricted transpositions can also be used to generate random fixed-point-free involutions only, a. k. a. random perfect matchings on the complete graph. Our data indicate that the algorithms generate random samples with the expected distribution of cycle lengths, which we derive, and for relatively small samples, which can actually be very large in absolute numbers, we argue that they generate samples indistinguishable from the uniform distribution. Both algorithms are simple to understand and implement and possess a performance comparable to or better than those of currently known methods. Simulations suggest that the mixing time of the algorithm based on random restricted transpositions (in the total variance distance with respect to the distribution of cycle lengths) is \(O(n^{a}\log {n}^{2})\) with \(a \simeq \frac{1}{2}\) and n the length of the derangement. We prove that the sequential importance sampling algorithm generates random derangements in O(n) time with probability O(1/n) of failing.
Similar content being viewed by others
References
Akl SG (1989) A new algorithm for generating derangements. BIT Numer Math 20(1):2–7
Aldous D, Diaconis P (1986) Shuffling cards and stopping times. Am Math Mon 93(5):333–348
Arratia R, Barbour AD, Tavaré S (2003) Logarithmic combinatorial structures: a probabilistic approach. EMS, Zürich
Bacher A, Bodini O, Hwang H-K, Tsai T-H (2017) Generating random permutations by coin tossing: classical algorithms, new analysis, and modern implementation. ACM Trans Algorithms 13(2):24
Baril JL, Vajnovszki V (2004) Gray code for derangements. Discret Appl Math 140(1–3):207–221
Beichl I, Sullivan F (1999) Approximating the permanent via importance sampling with application to the dimer covering problem. J Comput Phys 149(1):128–147
Blumberg O (2012) Cutoff for the transposition walk on permutations with one-sided restrictions. arXiv:1202.4797 [math.PR]
Brualdi RA, Ryser RJ (1991) Combinatorial matrix theory. Cambridge University Press, Cambridge
Charalambides CA (2002) Enumerative combinatorics. Chapman & Hall/CRC, Boca Raton
Chen Y, Diaconis P, Holmes SP, Liu JS (2005) Sequential Monte Carlo methods for statistical analysis of tables. J Am Stat Assoc 100(469):109–120
Chung F, Diaconis P, Graham R (2019) Permanental generating functions and sequential importance sampling. Adv Appl Math. https://doi.org/10.1016/j.aam.2019.05.004(in press)
Diaconis P (1988) Group representations in probability and statistics. IMS, Hayward
Diaconis PW, Holmes SP (1998) Matchings and phylogenetic trees. Proc Natl Acad Sci USA 95(25):14600–14602
Diaconis P, Holmes S (2002) Random walks on trees and matchings. Electron J Probab 7:6
Diaconis P, Kolesnik B (2019) Randomized sequential importance sampling for estimating the number of perfect matchings in bipartite graphs. arXiv:1907.02333 [math.PR]
Diaconis P, Shahshahani M (1981) Generating a random permutation by random transpositions. Z Wahrsch Verw Gebiete 57(2):159–179
Diaconis P, Graham RL, Holmes SP (2001) Statistical problems involving permutations with restricted positions. In: de Gunst M, Klaassen C, Van der Vaart A (eds) State of the art in probability and statistics: Festschrift for Willem R. van Zwet. IMS, Beachwood, pp 195–222
Dyer M, Müller H (2019) Counting perfect matchings and the switch chain. SIAM J Discret Math 33(3):1146–1174
Dyer M, Jerrum M, Müller H (2017) On the switch Markov chain for perfect matchings. J ACM 64(2):12
Flajolet P, Soria M (1990) Gaussian limiting distributions for the number of components in combinatorial structures. J Comb Theor Ser A 53(2):165–182
Gries D, Xue J (1988) Generating a random cyclic permutation. BIT Numer Math 28(3):569–572
Hanlon P (1996) A random walk on the rook placements on a Ferrer’s board. Electron J Comb 3(2):26
Korsh JF, LaFollette PS (2004) Constant time generation of derangements. Inf Process Lett 90(4):181–186
Kuznetsov NY (1996) Computing the permanent by importance sampling method. Cybern Syst Anal 32(6):749–755
Lovász L, Plummer MD (2009) Matching theory. Corrected reprint. AMS, Providence
Martínez C, Panholzer A, Prodinger H (2008) Generating random derangements. In: Sedgewick R, Szpankowski W (eds) Proceedings of the fifth workshop on analytic algorithmics and combinatorics—ANALCO. SIAM, Philadelphia, pp 234–240
Ozel E (2017) The number of \(k\)-cycles in a family of restricted permutations. arXiv:1710.07885 [math.PR]
Panholzer A, Prodinger H, Riedel M (2004) Measuring post–quickselect disorder. J Iran Stat Soc 3(2):219–249
Prodinger H (2002) On the analysis of an algorithm to generate a random cyclic permutation. Ars Comb 65:75–78
Rasmussen LE (1994) Approximating the permanent: a simple approach. Random Struct Algorithms 5(2):349–361
Sattolo S (1986) An algorithm to generate a random cyclic permutation. Inf Process Lett 22(6):315–317
Sedgewick R (1977) Permutation generation methods. Comput Surv 9(2):137–164
Smith A (2015) Comparison theory for Markov chains on different state spaces and application to random walk on derangements. J Theor Probab 28(4):1406–1430
Vigna S (2019) xoshiro/xoroshiro generators and the PRNG shootout. http://xoshiro.di.unimi.it/. Accessed 15 Dec 2019
Wilson MC (2009) Random and exhaustive generation of permutations and cycles. Ann Comb 12(4):509–520
Wolfram Research, Inc. (2018) Mathematica, Version 11.3. Champaign
Acknowledgements
The author thanks Aaron Smith (U. Ottawa) for useful correspondence and suggestions improving a previous version of the manuscript, the Laboratoire de Physique Théorique et Modèles Statistiques – LPTMS (CNRS UMR 8486) for kind hospitality during a sabbatical leave in France where part of this work was done, and FAPESP (Brazil) for partial support through Grants nos. 2017/22166-9 and 2020/04475-7.
Author information
Authors and Affiliations
Corresponding author
Additional information
Communicated by Eduardo Souza de Cursi.
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
About this article
Cite this article
Mendonça, J.R.G. Efficient generation of random derangements with the expected distribution of cycle lengths. Comp. Appl. Math. 39, 244 (2020). https://doi.org/10.1007/s40314-020-01295-4
Received:
Revised:
Accepted:
Published:
DOI: https://doi.org/10.1007/s40314-020-01295-4
Keywords
- Restricted permutation
- Random transposition walk
- Random perfect matching
- Switch Markov chain
- Mixing time