A Loopless Algorithm for Generating the Permutations of a Multiset

A Loopless Algorithm for Generating the Permutations of a Multiset

View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Elsevier - Publisher Connector Theoretical Computer Science 307 (2003) 415–431 www.elsevier.com/locate/tcs Aloopless algorithm for generating the permutations of a multiset Vincent Vajnovszki LE2I-CNRS FRE 2309, Universiteà de Bourgogne, B.P. 47 870, Dijon 21078, Cedex, France Abstract Many combinatorial structures can be constructed from simpler components. For example, a permutation can be constructed from cycles, or a Motzkin word from a Dyck word and a combination. In this paper we present a constructor for combinatorial structures, called shu)e on trajectories (deÿned previously in a non-combinatorial context), and we show how this constructor enables us to obtain a new loopless generating algorithm for multiset permutations from similar results for simpler objects. c 2003 Elsevier B.V. All rights reserved. Keywords: Gray codes; Loopless generating algorithms; Multiset permutations; Shu7e combinatorial objects 1. Introduction Let n0;n1;:::;nk be k + 1 integers. The set of multiset permutations (permutations with repetitions) of type n0n1 :::nk , denoted by S(n0;n1;:::;nk ), is the set of integer sequences in which there are ni occurrences of i,06i6k, and multiset permutations simultaneously generalize permutations and combinations. A Gray code for a class of combinatorial objects is a list for the class so that successive objects di:er in some pre- speciÿed small way [14]. In particular, a Gray code for the set S(n0;n1;:::;nk ) is a list for this set where successive sequences di:er by a transposition of two items. Agen- erating algorithm is loopless if after the initial sequence is generated, each succeeding sequence may be obtained by at most a ÿxed number of operations. Many algorithms for generating Gray codes for multiset permutations, looplessly [2,8,15] or otherwise [3,7,13], have been published. We present here a new loopless E-mail address: [email protected] (V. Vajnovszki). 0304-3975/03/$ - see front matter c 2003 Elsevier B.V. All rights reserved. doi:10.1016/S0304-3975(03)00228-7 416 V. Vajnovszki / Theoretical Computer Science 307(2003) 415–431 generating algorithm for this combinatorial class. Our approach is the following: we express multiset permutations in terms of shu)e on trajectories (shu)e for short, in this paper), then we apply it to redeÿne a known Gray code (implemented, but not looplessly at [12]) and to obtain a new loopless generating algorithm for multiset permutations. The remainder of this paper is organized as follows. At the end of the present section we introduce the notations we adopt throughout this paper. In Section 2 we recall basic results and present the shu7e on trajectories constructor for combinatorial objects. The Gray code for multiset permutations based on this constructor and some of its properties are presented in Section 3. In Section 4 we discuss two known loopless generating algorithms for product set and combinations, and a loopless algorithm for multiset permutations is developed. Some concluding remarks are o:ered in the ÿnal section. If L is an (ordered) list for a set of integer sequences then ÿrst(L) is the ÿrst element and last(L) the last element on the list L; LE is the list obtained by reversing L, and obviously ÿrst(L)=last(LE ) and ÿrst(LE )=last(L); L(i) is the list L if i is E m even, and L if i is odd; if L1; L2;:::;Lm are m lists then L1◦L2◦···◦Lm = i=1 Li denotes the concatenation of these lists; if x is an integer or an integer sequence then xn is the sequence which consists of n copies of x; and L · x (x · L, respectively) is the list obtained by appending x to each sequence of L (each sequence of L to x, respectively). The rank of a sequence x in a list L, denoted rankL(x) (or rank(x) for short, if the list L is understood), is the number of sequences preceding x in L. 2. Preliminaries k For k integers r1;r2;:::;rk let V (r1;r2;:::;rk ) be the Cartesian product set i=1 {0; 1; :::;ri − 1}. The natural extension of the binary reGected Gray code to the set V (r1;r2; :::;rk ) was proposed in [6,20] and elsewhere, and it is given by the lemma below. Lemma 1. The list deÿned recursively by ∅ if k =0; V(r1;r2;:::;rk )= r1−1 (1) (i) i · V (r2;:::;rk ) if k¿0 i=0 is a Gray code for V (r1;r2;:::;rk ) where two consecutive sequences di?er in a single position and by +1 or −1 in this position. For k + 1 integers, n0;n1;:::;nk , the set S(n0;n1;:::;nk ) of multiset permutations of type n0n1;:::nk is the set of integer sequences in which there are ni occurrences of i,06i6k. The cardinality of the set S(n0;n1;:::;nk )isthemultinomial coe@cient, given in (2), and we denote it by c(n0;n1;:::;nk ). V. Vajnovszki / Theoretical Computer Science 307(2003) 415–431 417 For k = 1, the sequences in S(n0;n1) are a common representation of the combina- n0+n1 tions of n1 objects chosen from n0 + n1, and c(n0;n1)=( ). In general, n1 (n0 + n1 + ···+ nk )! c(n0;c1;:::;nk )= ; (2) n0! × n1! ×···×nk ! or recursively, if k = 0 then c(n0) = 1 and for k¿0 n0 + n1 + ···+ nk c(n0;c1;:::;nk )=c(n0;n1;:::;nk−1) × (3) nk n0 + n1 n0 + n1 + n2 n0 + n1 + ···+ nk = × ::: : (4) n1 n2 nk A1- homogeneous Gray code for S(n0;n1), is a list for S(n0;n1), where successive sequences di:er by a transposition of two bits and the bits between those transposed are ones. The Gray code deÿned in the lemma below is a slight variation of Eades’ and McKay’s code deÿned in [4]. Lemma 2 (Ruskey [11]). The list deÿned recursively by E(n0;n1) 0n0 if n =0; 1 n1 1 if n0 =0; = 01n1 ◦ 101n1−1 ◦ ··· ◦1n1 0 if n =1and n ¿ 0; (5) 0 1 E 00 · E(n0 − 2;n1) ◦ 01 · E(n0 − 1;n1 − 1) ◦1 · E(n0;n1 − 1) if n0 ¿ 1 and n1 ¿ 0 satisÿes the following properties: n n (1) ÿrst(E(n0;n1))=0 0 1 1 , n n (2) last(E(n0;n1))=1 1 0 0 , (3) E(n0;n1) is a 1-homogeneous Gray code list for S(n0;n1). It is easy to see that E(n0;n1) and V(r1;r2;:::;rk ) are preÿx-partitioned lists, i.e. all the sequences with a given preÿx form a contiguous sublist; in [18] Walsh presents a very general technique for looplessly generating lists with this property. In Section 4 we present two generating algorithms for the lists deÿned by relations (1) and (5) based on this technique. Note also that the Gray code for multiset permutations described in the next section is not preÿx partitioned. The following deÿnition was initially given in [10], in a very di:erent, non-combin- atorial context. 418 V. Vajnovszki / Theoretical Computer Science 307(2003) 415–431 Deÿnition 3. For two integers n0 and n1, the shu)e of the sequence v = v1v2 :::vn0 by the sequence w = w1w2 :::wn1 on the binary sequence t = t1t2 :::tn0+n1 ∈ S(n0;n1)is the n + n length sequence u = u u :::u , denoted by v w, where for each i, 0 1 1 2 n0+n1 t 16i6n0 + n1, ui is deÿned as v if t =0; u = t[i]0 i i w if t =1 t[i]1 i with t[i]0 and t[i]1 being the number of occurrences of 0’s and 1’s, respectively, in the length-i preÿx of the binary sequence t, and t is called the trajectory of the shu7e. For example, if v = aab, w = 1234 and the trajectory t = 0101011 then v t w = a1a 2b34; and if v = 001, w = 22 and t = 10100 then v t w = 20201. We extend the shu7e operation in a natural way to sets and lists of trajectories. Deÿnition 4. Let v and w be two sequences as above. (1) If L = {t;s;:::}⊂S(n0;n1) is a set of binary sequences, then v L w is the set of sequences {v t w; v s w;:::}. (2) If L =(t;s;:::) is a list of sequences in S(n0;n1), then v L w is the list of sequences (v t w; v s w;:::). Remark 5. With the notations above: (1) If v is another length-n0 sequence which di:ers from v by the transposition of two items, then v t w di:ers from v t w by the transposition of two items. (2) If x is an item not belonging to v, then two consecutive sequences in the lists n n v x 1 and v E x 1 di:er by the transposition of an x with an element E(n0;n1) E(n0;n1) in v, and all items between the transposed ones are x’s. (3) v L w, the reverse of v L w, is equal to v LE w. (4) {0n0 } if k =0; S(n0;n1;:::;nk )= nk (6) {v S k } if k¿0 v∈S(n0;n1;:::;nk−1) with S being the set of binary sequences S(n0 + n1 + ··· + nk−1;nk ). (5) For any list L of binary sequences in S(n0;n1) we have the obvious relation n0 n1 L =0 L 1 : 3.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    17 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us