More restrictive Gray codes for some classes of pattern avoiding permutations

  • Published on
    26-Jun-2016

  • View
    213

  • Download
    1

Embed Size (px)

Transcript

<ul><li><p>Information Processing Letters 109 (2009) 799804</p><p>Contents lists available at ScienceDirect</p><p>ce</p><p>com</p><p>M clap</p><p>Je</p><p>LE ce</p><p>a</p><p>ArReReAcAvCo</p><p>KeAlGrPaGeCaScCe</p><p>M.B.of pan, Mermuositio</p><p>construction in order to rene their results (or to nd other Gray codes). In particular,</p><p>1.</p><p>1)i1deifmMmpeinsicoquof25</p><p>00doywords:gorithmsay codettern avoiding permutationnerating algorithmtalan numbershrder numbersntral binomial coecients</p><p>we obtain more restrictive Gray codes for the two Wilf classes of Catalan permutationsof length n; two consecutive objects differ in at most two or three positions which isoptimal for n odd. Other renements have been found for permutation sets enumeratedby the numbers of Schrder, Pell, even index Fibonacci numbers and the central binomialcoecients. A general ecient generating algorithm is also given.</p><p> 2009 Elsevier B.V. All rights reserved.</p><p>Introduction</p><p>Let Sn be the set of all permutations of length n (n . We represent permutations in one-line notation, i.e. if, i2, . . . , in are n distinct values in [n] = {1,2, . . . ,n}, wenote the permutation Sn by the sequence i1i2 . . . in(k) = ik for 1 k n. For instance, the identity per-utation of length n, idn , will be written 12 . . . (n 1)n.oreover, if = (1) (2) . . . (n) is an n-length per-utation then the composition (or product) is thermutation ( (1)) ( (2)) . . . ( (n)). In Sn , a k-cycle= i1, i2, . . . , ik is an n-length permutation satisfy-g (i1) = i2, (i2) = i3, . . . , (ik1) = ik , (ik) = i1 and( j) = j for j [n]\{i1, . . . , ik}; in particular, a transpo-tion is a 2-cycle. A permutation = 12 . . . n Snntains the pattern Sk (k 2) if and only if a se-ence of indices 1 i1 &lt; i2 &lt; &lt; ik n exists such that</p><p>i1i2 . . . ik is ordered as . We denote by Sn( ) the setpermutations in Sn avoiding the pattern . For example,314 / S5(123) but 43152 S5(123).</p><p>E-mail address: barjl@u-bourgogne.fr.</p><p>Several algorithms for generating permutation classeshave been published (generated in lexicographic orderor in constant time per permutation, in the amortizedsense). For example, ecient algorithms are known forderangements [1], up-down permutations [7,19], permu-tations with a xed number of inversions [12] and forpermutations avoiding a pattern [9]. On the other hand, al-gorithms for generating permutation classes in Gray codeorder are given for permutations [14,22] and their restric-tions [17,19,20], derangements [3,16], with a xed numberof cycles [2], involutions and xed-point free involutions[25] or their generalizations (multiset permutations [24]).Juarna and Vajnovszki [15] presented Gray codes and gen-erating algorithms for two classes of pattern avoiding per-mutations: Sn(123,132), Sn(123,132, p(p1) . . .1(p+1)).In a recent paper, Dukes et al. [11] give Gray codes andgenerating algorithms for classes of pattern avoiding per-mutations enumerated by Catalan, Schrder, Pell, even in-dex Fibonacci numbers and the central binomial coe-cients: two consecutive elements in their codes differ inat most four or ve positions. Inspired by their article,we give here Gray codes for Catalan permutations and for</p><p>20-0190/$ see front matter 2009 Elsevier B.V. All rights reserved.i:10.1016/j.ipl.2009.03.025Information Pro</p><p>www.elsevier.</p><p>ore restrictive Gray codes for someermutations</p><p>an-Luc Baril</p><p>2I UMR-CNRS 5158, Universit de Bourgogne, B.P. 47 870, 21078 Dijon Cedex, Fran</p><p>r t i c l e i n f o a b s t r a c t</p><p>ticle history:ceived 8 July 2008ceived in revised form 26 January 2009cepted 22 March 2009ailable online 27 March 2009mmunicated by D. Pointcheval</p><p>In a recent article [W.Gray codes for classes3549], Dukes, Flanagof pattern avoiding pat most four or ve pssing Letters</p><p>/locate/ipl</p><p>sses of pattern avoiding</p><p>Dukes, M.F. Flanagan, T. Mansour, V. Vajnovszki, Combinatorialattern avoiding permutations, Theoret. Comput. Sci. 396 (2008)ansour and Vajnovszki present Gray codes for several familiestations. In their Gray codes two consecutive objects differ inns, which is not optimal. In this paper, we present a unied</p></li><li><p>800 J.-L. Baril / Information Processing Letters 109 (2009) 799804</p><p>somconfoprtaexco</p><p>thmouseblgeimpl</p><p>2.</p><p>pringitimItcothje</p><p>cotrtopeMteobtoantiv[1alsifo</p><p>Foseta</p><p>Ththof</p><p>siL(se</p><p>L</p><p>W</p><p>L</p><p>Lediemktqudefoac</p><p>ou</p><p>Sn</p><p>w</p><p>TaNofar</p><p>erGrdibyme other classes: two consecutive elements differ in atost three (or two) positions. This induces optimal Graydes for some of these classes: Sn(321) and Sn(312) forodd. Notice that in [8] or [23], Gray codes are givenr some classes previously mentioned, but they do notovide them in term of classes of pattern avoiding permu-tions. Despite the fact that some well-known bijectionsist between these classes they do not conserve the Grayde property.This paper is organized as follow. In Section 2, we give</p><p>e construction for our Gray codes based on the ECOethod [4]. We obtain sucient conditions showing thatr construction produces Gray codes. Thus we investigateveral classes of avoiding pattern permutation sets in Ta-e 2. In the third and last sections, we shortly explain ournerating algorithm to list our Gray codes. We present anplementation of our algorithm, and we discuss its com-exity.</p><p>Construction for our Gray codes</p><p>In this part, we develop a general construction thatovides Gray codes for several classes of pattern avoid-g permutations. This construction is a renement of thatven in [11] and, in some cases, yields codes that are op-al. The construction is based on the method ECO [4].consists in determining a recursive construction for thensidered class based on local expansion performed one objects. Each object is produced exactly once by an ob-ct of lower size.Let Sn; the sites of are the positions between twonsecutives entries, before the rst and after the last en-y. We suppose that the sites are numbered, from rightleft, from 1 to n + 1. For example, the 3rd site of thermutation = 463512 is between the entries 5 and 1.oreover, let Sn(T ), where T is a set of forbidden pat-rns, the ith site of is said active if the permutation tained from by inserting (n + 1) into this site belongsSn+1(T ). We will denote this permutation by (i, )d we will say that is a successor (or son) of . The ac-e sites of a permutation Sn(T ) are right-justied (see1]) if all sites to the right of the leftmost active site areso active. We denote by T (i, ) the number of activetes of (i, ). A set of patterns T is called regular [11] ifr any n 1 and Sn(T ),</p><p> has at least two active sites, and the active sites of are right-justied,</p><p> there exist Sn1(T ) and an integer i, 1 i n,such that = (i, ),</p><p> T (i, ) does not depend on but only on the num-ber k of active sites of ; in this case, we will denoteT (i, ) by T (i,k) if has k active sites.</p><p>r the remainder of this paper, we only consider regulart T of patterns. Now, for each n 1 and for any permu-tion Sn(T ), we associate:</p><p> a direction: up or down; a permutation with the di-rection up (down respectively) will be denoted by 1( 0 respectively). Such a permutation will be called adirected permutation,</p><p> a list of its sons considered with their directions, i.e.a list consisting of some (i, ) j where j {0,1} andi are the active sites of in an order that we willdescribe below.</p><p>e list of successors of 0 will be obtained by reversinge list of successors of 1 and by reversing the directioneach element of the list.Let 1 be a directed permutation in Sn(T ) with k active</p><p>tes and let L be a unimodal sequence of integers wherei) denotes the ith (1 i k) integer of the followingquence L:</p><p>=</p><p>3,5, . . . , (k 3), (k 1),k, (k 2),(k 4), . . . ,4,2,1 if k is even,</p><p>3,5, . . . , (k 4), (k 2),k, (k 1),(k 3), . . . ,4,2,1 if k is odd.</p><p>e also consider the sequence L dened as follows:</p><p>=</p><p>2,4, . . . , (k 4), (k 2),k, (k 1),(k 3), . . . ,5,3,1 if k is even,</p><p>2,4, . . . , (k 3), (k 1),k, (k 2),(k 4), . . . ,5,3,1 if k is odd.</p><p>t ( 1) be the list of successors of 1 consisting of krected permutations in Sn+1(T ) such that: the jth el-ent is (L( j), )(i1) mod 2 for 1 j k 1 and the</p><p>h element is (L(k), )1. Moreover, if we replace the se-ence L by L in this denition, we obtain a list that wenote ( 1). Figs. 1 and 2 illustrate the different casesr the lists () and ( ) for having k = 7 or k = 8tive sites.Now, we set dn = card(Sn(T )) and we recursively dener Gray code Sn(T ) for Sn(T ) as follows:</p><p>(T ) ={10 if n = 1,dn1</p><p>i=1 ( [i]) otherwise,here</p><p> [i] is the ith directed permutation of the list Sn1(T ), ( [i]) = ( [i]) if: the direction of [i] is 0 and</p><p>the direction of [i + 1] is 1; [i] and [i + 1] differin three positions and have respectively at least threesons and exactly two sons,</p><p> ( [i]) = ( [i]) if: the direction of [i] is 1 andthe direction of [i 1] is 0; [i] and [i 1] differin three positions and have respectively at least threesons and exactly two sons,</p><p> ( [i]) = ( [i]) otherwise.</p><p>ble 1 illustrates our construction for S5(321) and S5(312).otice that the lists and appear in the constructionthe Gray code S5(321); but only the lists of the form e used for S5(312).For the remainder of this paper, we study several prop-</p><p>ties that allow us to prove this denition gives almost allay codes such that two consecutive elements in the listffer in at most three positions. If L is a list, we denoterst(L) and last(L) the rst and last element of L.</p></li><li><p>J.-L. Baril / Information Processing Letters 109 (2009) 799804 801</p><p>Fi (4, ( int) n</p><p>Fi (5, ( int) n</p><p>TaThel</p><p>1212121212141415141313131313</p><p>Prcoem21</p><p>Pranthusrlafaexde</p><p>Lemsutio</p><p>Pr</p><p>ex</p><p>L</p><p>fej</p><p>Letwd(</p><p>Pr</p><p>d(</p><p>Letwpeha</p><p>PrsoTh</p><p>d(= d L(1), , L(1), st(Sn(T )) = (1, last(Sn1(T ))) = 2134 . . . (n 1)n. Thect that the list Sn(T ) contains each of the permutationsactly once is deduced directly from the above recursivenition of Sn(T ). mma 2. Let T be a regular set of patterns. Let be a per-utation in Sn(T ), and let r {0,1} be its direction, then twoccessive permutations in ( r) differ in at most three posi-ns.</p><p>oof. Let and the two successive permutations in( r). Thus if k is the number of active sites of , thereists i and j, i = j, 1 i, j k, such that = (i, ) and= ( j, ). Considering the denitions of the sequencesor L , we distinguish two cases: (a) if i = j 1 then= i, j which induces the result; (b) if i = j 2 then</p><p>= d((3, ),(3, ))= d( , ). Lemma 5. Let T be a regular set of patterns. Let 0 and 1</p><p>be two consecutive directed permutations in the list Sn(T ). Ifboth permutations and have two successors then we have:d( , ) = d(last(( 0)),rst(( 1))).</p><p>Proof. Since each permutation and has two sons,their corresponding sequences L verify L(1) = 2. Thus, wehave:</p><p>d(last(( 0))</p><p>,rst(( 1)))</p><p>= d((L(1), ), (L(1), ))= d((2, ),(2, ))= d( , ). g. 1. If k = 7 then ( 1) is the list (3, )0, (5, )1, (7, )0, (6, )1,8, )1, (6, )0, (4, )1, (2, )0, (1, )1. Each point (resp. encircled po</p><p>g. 2. If k = 7 then ( 1) is the list (2, )0, (4, )1, (6, )0, (7, )1,8, )1, (7, )0, (5, )1, (3, )0, (1, )1. Each point (resp. encircled po</p><p>ble 1e optimal cyclic Gray codes for S5(312) and S5(321). Two consecutiveements differ in at most three positions.</p><p>S5(312) S5(321)345 32145 24315 12345 13245 23145354 32154 24351 12354 13254 23154543 32541 25431 15234 13524 23514453 32451 24531 51234 13452 23451435 32415 23541 12534 13425 23415325 43215 23451 12453 34125 24135352 43251 23415 12435 34152 24153432 45321 23154 41235 34512 24513532 54321 23145 41253 31452 21453542 43521 21435 45123 31425 21435452 34521 21453 41523 31524 21534425 35421 21543 14523 35124 25134254 34251 21354 14253 31254 21354245 34215 21345 14235 31245 21345</p><p>oposition 1. Let T be a regular set of patterns. The list Sn(T )ntains exactly once all permutations in Sn(T ). The rst el-ent of the list is 123 . . . (n 1)n and the last element is34 . . . (n 1)n.</p><p>oof. This holds for n = 1 and n = 2 since S1(T ) = {1}d S2(T ) = {12,21} where T is a regular pattern setat does not contain the pattern 21. By induction, letsuppose that this is true for all k, 2 k &lt; n. Then,</p><p>st(Sn(T )) = (1,rst(Sn1(T ))) = 1234 . . . (n 1)n, and)0, (2, )1, (1, )1; if k = 8, ( 1) is (3, )0, (5, )1, (7, )0,umbered by [1..k] represents (, )1 (resp. (, )0).</p><p>)0, (3, )1, (1, )1; if k = 8, ( 1) is (2, )0, (4, )1, (6, )0,umbered by [1..k] represents (, )1 (resp. (, )0).</p><p>= i, j, i + 1 and the two permutations and dif-r in three positions. The other cases (i.e. j = i 1 and= i 2), are similar. mma 3. Let T be a regular set of patterns. Let 1 and 0 beo consecutive directed permutations in the list Sn(T ). Then , ) = d(last(( 1)),rst(( 0))).</p><p>oof. Indeed, let us assume that has k sons and hassons. Then we have:</p><p>last(( 1))</p><p>,rst(( 0)))</p><p>= d((L(k), ), (L(), ))= d((1, ),(1, ))= d( , ). mma 4. Let T be a regular set of patterns. Let 0 and 1 beo consecutive directed permutations in the list Sn(T ). If bothrmutations and have at least three successors then weve: d( , ) = d(last(( 0)),rst(( 1))).</p><p>oof. Since each permutation and has at least threens, their corresponding sequences L satisfy L(1) = 3.us, we have:</p><p>last(( 0))</p><p>,rst(( 1)))</p><p>( ( ) ( ))</p></li><li><p>802 J.-L. Baril / Information Processing Letters 109 (2009) 799804</p><p>Lebethtw</p><p>PrhahaL(</p><p>d(</p><p>Lebethattw</p><p>PrreleL</p><p>d(</p><p>Lebethd(tw</p><p>PrThLein</p><p>d(</p><p>Th</p><p>wGrloS2beS2afenuS2ouclanan</p><p>3.</p><p>fothtiaprdoinincoseofduusceeawthmthnucothinbo</p><p>prdrifelmma 6. Let T be a regular set of patterns. Let 0 and 1</p><p>two consecutive directed permutations in the list Sn(T ) suchat = n 1,n. If has at least three sons and haso sons then we have: d(last(( 0)),rst(( 1))) = 3.</p><p>oof. Since the permutation has at least three sons, its a corresponding sequence L such that L(1) = 3; as s two sons its corresponding sequence L is such that1) = 2. Thus, we have:last(( 0))</p><p>,rst(( 1)))</p><p>= d((L(1), ), (L(1), ))= d((3, ),(2, ))= d((3, n 1,n), (2, ))= d((2, n 1,n) n 1,n, (2, ))= d((2, ) n 1,n,n + 1, (2, ))= 3. mma 7. Let T be a regular set of patterns. Let 0 and 1</p><p>two consecutive directed permutations in the list Sn(T ) suchat and differ in three positions. If has two sons (resp.least three sons) and has at least three sons (resp. exactlyo sons), then we have: d(last(( 0)),rst(( 1))) = 3.</p><p>oof. Since the permutation has two sons, it has a cor-sponding sequence L such that L(1) = 2; as has atast three sons its corresponding sequence L is such that(1) = 2. Thus, we have:last(( 0))</p><p>,rst(( 1)))</p><p>= d((L(1), ), (L(1), ))= d((2, ),(2, ))= 3. mma 8. Let T be a regular set of patterns. Let 1 and 1</p><p>two consecutive directed permutations in the list Sn(T ) suchat = n1,n. If has at least three sons, thenwe have:last(( 1)),rst(( 1))) = 2. On the other hand if haso sons then we have: d(last(( 1)),rst(( 1))) = 3.</p><p>oof. Let us assume that the permutation has k sons.us its corresponding sequence L is such that L(k) = 1.t us assume that has at least three sons. It correspond-g sequence L is such that L(1) = 3. Thus, we have:last(( 1))</p><p>,rst(( 1)))</p><p>= d((L(k), ), (L(1), ))= d((1, ),(3, ))= d((1, n 1,n), (3, ))= d((1, ) n 1,n, (3,...</p></li></ul>