8,368 research outputs found

    Random and exhaustive generation of permutations and cycles

    Full text link
    In 1986 S. Sattolo introduced a simple algorithm for uniform random generation of cyclic permutations on a fixed number of symbols. This algorithm is very similar to the standard method for generating a random permutation, but is less well known. We consider both methods in a unified way, and discuss their relation with exhaustive generation methods. We analyse several random variables associated with the algorithms and find their grand probability generating functions, which gives easy access to moments and limit laws.Comment: 9 page

    Efficient generation of random derangements with the expected distribution of cycle lengths

    Full text link
    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(nalogn2)O(n^{a}\log{n}^{2}) with a12a \simeq \frac{1}{2} and nn the length of the derangement. We prove that the sequential importance sampling algorithm generates random derangements in O(n)O(n) time with probability O(1/n)O(1/n) of failing.Comment: This version corrected and updated; 14 pages, 2 algorithms, 2 tables, 4 figure

    Constructions of Snake-in-the-Box Codes for Rank Modulation

    Full text link
    Snake-in-the-box code is a Gray code which is capable of detecting a single error. Gray codes are important in the context of the rank modulation scheme which was suggested recently for representing information in flash memories. For a Gray code in this scheme the codewords are permutations, two consecutive codewords are obtained by using the "push-to-the-top" operation, and the distance measure is defined on permutations. In this paper the Kendall's τ\tau-metric is used as the distance measure. We present a general method for constructing such Gray codes. We apply the method recursively to obtain a snake of length M2n+1=((2n+1)(2n)1)M2n1M_{2n+1}=((2n+1)(2n)-1)M_{2n-1} for permutations of S2n+1S_{2n+1}, from a snake of length M2n1M_{2n-1} for permutations of~S2n1S_{2n-1}. Thus, we have limnM2n+1S2n+10.4338\lim\limits_{n\to \infty} \frac{M_{2n+1}}{S_{2n+1}}\approx 0.4338, improving on the previous known ratio of limn1πn\lim\limits_{n\to \infty} \frac{1}{\sqrt{\pi n}}. By using the general method we also present a direct construction. This direct construction is based on necklaces and it might yield snakes of length (2n+1)!22n+1\frac{(2n+1)!}{2} -2n+1 for permutations of S2n+1S_{2n+1}. The direct construction was applied successfully for S7S_7 and S9S_9, and hence limnM2n+1S2n+10.4743\lim\limits_{n\to \infty} \frac{M_{2n+1}}{S_{2n+1}}\approx 0.4743.Comment: IEEE Transactions on Information Theor

    A constant-time algorithm for middle levels Gray codes

    Get PDF
    For any integer n1n\geq 1 a middle levels Gray code is a cyclic listing of all nn-element and (n+1)(n+1)-element subsets of {1,2,,2n+1}\{1,2,\ldots,2n+1\} such that any two consecutive subsets differ in adding or removing a single element. The question whether such a Gray code exists for any n1n\geq 1 has been the subject of intensive research during the last 30 years, and has been answered affirmatively only recently [T. M\"utze. Proof of the middle levels conjecture. Proc. London Math. Soc., 112(4):677--713, 2016]. In a follow-up paper [T. M\"utze and J. Nummenpalo. An efficient algorithm for computing a middle levels Gray code. To appear in ACM Transactions on Algorithms, 2018] this existence proof was turned into an algorithm that computes each new set in the Gray code in time O(n)\mathcal{O}(n) on average. In this work we present an algorithm for computing a middle levels Gray code in optimal time and space: each new set is generated in time O(1)\mathcal{O}(1) on average, and the required space is O(n)\mathcal{O}(n)

    Subset-lex: did we miss an order?

    Full text link
    We generalize a well-known algorithm for the generation of all subsets of a set in lexicographic order with respect to the sets as lists of elements (subset-lex order). We obtain algorithms for various combinatorial objects such as the subsets of a multiset, compositions and partitions represented as lists of parts, and for certain restricted growth strings. The algorithms are often loopless and require at most one extra variable for the computation of the next object. The performance of the algorithms is very competitive even when not loopless. A Gray code corresponding to the subset-lex order and a Gray code for compositions that was found during this work are described.Comment: Two obvious errors corrected (indicated by "Correction:" in the LaTeX source

    Efficient computation of middle levels Gray codes

    Get PDF
    For any integer n1n\geq 1 a middle levels Gray code is a cyclic listing of all bitstrings of length 2n+12n+1 that have either nn or n+1n+1 entries equal to 1 such that any two consecutive bitstrings in the list differ in exactly one bit. The question whether such a Gray code exists for every n1n\geq 1 has been the subject of intensive research during the last 30 years, and has been answered affirmatively only recently [T. M\"utze. Proof of the middle levels conjecture. Proc. London Math. Soc., 112(4):677--713, 2016]. In this work we provide the first efficient algorithm to compute a middle levels Gray code. For a given bitstring, our algorithm computes the next \ell bitstrings in the Gray code in time O(n(1+n))\mathcal{O}(n\ell(1+\frac{n}{\ell})), which is O(n)\mathcal{O}(n) on average per bitstring provided that =Ω(n)\ell=\Omega(n)
    corecore