Catalan and Schröder permutations sortable by two restricted stacks
CCatalan and Schr¨oder permutations sortable by two restrictedstacks
J.-L. Baril, C. Khalil and V. VajnovszkiLIB, Universit´e de Bourgogne Franche-Comt´eB.P. 47 870, 21078 Dijon Cedex France { barjl,carine.khalil,vvajnov } @u-bourgogne.fr April 7, 2020
Abstract
We investigate the permutation sorting problem with two restricted stacks in series by applying aright greedy process. Instead of σ -machine introduced recently by Cerbai et al. , we focus our studyon ( σ, τ )-machine where the first stack avoids two patterns of length three, σ and τ , and the secondstack avoids the pattern 21. For ( σ, τ ) = (123 , σ, τ ) = (132 , For several decades, the problem of permutation sorting was widely studied in the literature. It consistsin rearranging an arbitrary permutation into the identity one using a sequence of specific transformations.One of the most relevant references is probably
Sorting and Searching [13], the third volume of Knuth’sseminal monograph TAOCP, where the author studies the complexity of several sorting algorithms. Inthis paper we consider stack sorting problems which have been initiated in [12], the first volume ofTAOCP. From an input permutation π = π π . . . π n , the process consists in reading π from left to right,and for each entry π i either push it onto the stack, or pop the top of the stack into the output. Knuth [12]proved that a permutation π is sortable ( i.e. there is a sequence of push and pop operations such thatthe output is the identity permutation) if and only if there do not exist i < j < k such that π k < π i < π j ,or equivalently π avoids the pattern 231; and sortable permutations are counted by Catalan numbers.This result is the birth of the theory of pattern containment, and it already led to many other variationsof the stack sorting problem, see [6] for an early survey and the references therein. For instance, somestudies consider relaxed rules for push and pop operations [1], whereas others deal with several stacks inseries [3, 14, 17] or parallel [2, 19]. Today, the characterization of sortable permutations using two stacksin series remains an open problem. However, Pierrot and Rossin [15] give a polynomial time algorithm todecide whether a permutation is sortable with two stacks in series. West [20] studies the restricted casewhere permutations are sorted by two passes through a stack and provides a characterization of sortablepermutations in terms of generalized patterns.Recently, motivated by a better understanding of permutations sortable using two stacks in series, Cerbai et al. [8] investigate the sorting σ - machine where at each step of the process it performs the rightmostpossible operation with respect to the following two conditions: ( a ) the first stack avoids the pattern σ ; ( b ) the second stack avoids the pattern 21 (which is a necessary condition for the machine to sortpermutations). The avoidance of a pattern in a stack means that the stack read from top to bottomavoids the pattern. Let Sort ( σ ) be the set of sortable permutations by the σ -machine. The authors of[8] prove that Sort (12) is equal to the set Av (213) of permutations avoiding the pattern 213. Also, they1 a r X i v : . [ c s . D M ] A p r haracterize and enumerate length n permutations in Sort ( k ( k − · · ·
21) and
Sort (123), and they leaveopen the characterisation for the remaining length three patterns. Some of these results were generalisedby Cerbai in [9], where permutations and patterns with repeated elements are allowed.In this paper, we consider the ( σ, τ )-machine as described above where condition ( a ) is replaced by: the first stack avoids σ and τ . See Figure 1 for a description of the ( σ, τ )-machine. For ( σ, τ ) =(123 , σ, τ ) = (132 , Output Input21 σ, τO O O P P Figure 1: The ( σ, τ )-machine consists of two stacks in series where the first stack P avoids (from top tobottom) σ and τ while the second P avoids the pattern 21. At each step of the process, we perform therightmost possible operation among O , O , O , where O pushes in P the current entry of the inputpermutation, O pops the top of P and pushes it in P , and O pops the top of P and pushes it inthe output permutation. For instance, if σ = 123, τ = 132 then π = 35124 is sortable by applying thefollowing operations: O , O , O , O , O , O , O , O , O , O , O , O , O , O , O . σ, τ OEIS Sequence | Sort n ( σ, τ ) | Avoided patterns123,132
A000108 , , , , , , , . . . (Catalan numbers) 3214, 2314, 4213, [24¯13132,231 A006318 , , , , , , , . . . (Schr¨oder numbers) 1324, 2314Table 1: Enumeration and characterization of sortable permutations with the ( σ, τ )-machine.To end this section, we present classical definitions about pattern avoidance in permutations (see [11] forinstance). For two permutations σ and π , we say that π avoids the pattern σ whenever there does notexist a subsequence of π order isomorphic to σ . Whenever the occurrence of the pattern σ is constrainedto start with the first entry of π we denote the vincular pattern by placing [ in front the pattern; forinstance an occurrence of [12 in π corresponds to π π i for some i > π i > π . A barred pattern σ is a one where some entries are barred. Let ˆ σ be the pattern obtained from σ by removing all barredentries and rescaling the rest to a permutation. A permutation π avoids σ if each occurrence of ˆ σ in π can be extended in an occurrence of σ (considered without bars). For instance, a permutation π avoidsthe pattern [24¯13 if any subsequence π π i π j , 1 < i < j , π < π j < π i , can be extended into an occurrenceof the pattern 2413. (123 , -machine In this section we characterize and enumerate length n sortable permutations with the (123 , σ, τ )-machine, which are direct consequences of the charac-terization of sortable permutations with an unrestricted stack obtained by Knuth [12]. Fact 1:
During the sorting process by the ( σ, τ )-machine,– if u is in the stack P , and v above w in P with w < u < v , i.e. uvw yields the pattern 231, then thepermutation is not sortable;– if u is above v which is in turn is above w in P with w < u < v , then the permutation is not sortable.2 heorem 1. A permutation π belongs to Sort (123 , if and only if π avoids , , and [24¯13 .Proof. First, let us prove that a sortable permutation π cannot contain an occurrence of one of thepatterns 3214, 2314 and 4213. For a contradiction, let us assume that π contains such a pattern, and foran occurrence θ of it we pick a particular one: θ = π i π j π k π (cid:96) , 1 ≤ i < j < k < (cid:96) ≤ n , where (cid:96) is chosenminimal, and k , j , and i are chosen maximal, in this order.– θ is an occurrence of 3214. Due to the choice of i, j, k, (cid:96) above, a simple observation shows that π i > π u > π j for k < u < (cid:96) ; and π u < π u +1 for k ≤ u ≤ (cid:96) −
1. Whenever the entry π k is pushed in P , since P avoids 123 it follows that at least one of the two entries π i and π j does not belong to P .Since π k +1 > π k , the next step pushes π k +1 in P . ( i ) Assume that π i and π j are both in P . Then π k is just below π k +1 in P and π k < π j < π k +1 . Fact 1 implies that π is not sortable, which is acontradiction. ( ii ) Assume that π j is in P and π i in P . Fact 1 implies that π is not sortable because π j π k +1 π k is an occurrence of 231, which is a contradiction. ( iii ) Assume that π i is in P and π j in P .Since π u < π u +1 for k ≤ u ≤ (cid:96) −
1, the next steps of the sorting process push successively in P all entries π k +1 , . . . , π (cid:96) . Fact 1 implies that π is not sortable because π i π (cid:96) π k is an occurrence of 231, which again isa contradiction. So, π cannot contain the pattern 3214.– If θ is an occurrence of 2314 or of 4231, the proof is similar, mutatis mutandis , to that when θ is anoccurrence of 3214.Now let us assume that π contains the pattern [24¯13. This means that π contains a subsequence θ = π π i π j , 1 < i < j , with π < π j < π i and such that there is not a k in the interval ( i, j ) with π k < π . Wechoose i and j by taking j minimal and i maximal, in this order. Due to this choice, a simple observationshows that j = i + 1. ( i ) Assume that π i and π j are both in P . In this case, P contains the pattern 231with π π j π i , and Fact 1 implies that π is not sortable, which is a contradiction. ( ii ) Assume that π i is in P and π j in P . Since j = i + 1 > i , the sorting process must push π i from P to P before π j is pushedinto P . Thus, pushing π j in P creates necessarily the pattern 123 or 132, which means that there are u < v ≤ i , such that either π j < π u < π v or π j < π v < π u , and π u and π v are in P . If π u is greaterthan π i , then the process has created a pattern 231 with π i π u π and Fact 1 contradicts the sortability.If there is π u such that π i > π u > π j , then the process has created a pattern 231 with π j π u π which alsois a contradiction. ( iii ) Assume that π i is in P and π j in P . At the step where π j is pushed in P , thepattern 231 is created in P with π j π i π and by Fact 1 we have again a contradiction.Conversely, we assume that π is not sortable, and we will prove that π contains the pattern 3214, 2314,4213 or [24¯13. Let us consider the moment where the process is stuck. Let π k (resp. π (cid:96) ) the top of thestack P (resp. P ), then we necessarily have π (cid:96) > π k . We distinguish two cases: ( i ) k < (cid:96) and ( ii )otherwise. In the case ( i ), there necessarily exists a previous step where there are i and j , i < k < j < (cid:96) ,such that π i and π k are in P and π j is the first entry of the input permutation, and such that θ = π i π k π j is an occurrence of 321 or of 231 (otherwise we cannot push π k in P ). If θ is an occurrence of 321 then,using π (cid:96) > π k , π i π k π j π (cid:96) is an occurrence of 3214 or of 4213. If θ is an occurrence of 231 then, using π (cid:96) > π k , π i π k π j π (cid:96) is an occurrence of 2314. In the case ( ii ), we have k > (cid:96) . In order to push π k in P ,we need to push firstly π k in P by keeping π (cid:96) in P . A necessarily condition is that π π (cid:96) π k does notform the pattern 231 nor 321, which implies that π k > min { π , π (cid:96) } . Since π (cid:96) > π k , this implies that π k > π . So π π (cid:96) π k is an occurrence of 132. With the same reasoning, all values between π (cid:96) and π k mustbe greater than π . Thus, there is a 132-pattern π π (cid:96) π k that cannot be extended into 24¯13 which impliesthat π does not avoid [24¯13. (cid:50) Corollary 1.
Permutations of length n in Sort (123 , are enumerated by the Catalan numbers (see A000108 in [18]).Proof.
Let A n ( k ) be the set of length n permutations starting with k in Sort (123 , A n ( k )be the subset of A n ( k ) consisting of permutations π = π π . . . π n where any occurrence π π k π (cid:96) , with1 < k < (cid:96) and π (cid:96) = π − π k > π , can be extended into an occurrence π π k π j π (cid:96) , with k < j < (cid:96) and π j < π (cid:96) . We set A n ( k ) = A n ( k ) \ A n ( k ).First we prove that there is a one-to-one correspondence α between A n ( k ) and A n ( k − α be themap from A n ( k ) to A n ( k −
1) where π (cid:48) = α ( π ) is obtained from π by swapping the two entries π and π − π . For instance, α (45123) = 35124. Since π ∈ A n ( k ), it is easy to see that π (cid:48) avoids the pattern[24¯13. In addition, swapping π and π − α ( π ) ∈ A n ( k − A n ( k −
1) is theimage by α of a unique element in A n ( k ). Thus, α is a bijection.Now, we prove that there is a one-to-one correspondence between A n ( k ) and A n − ( k ). Let β be the mapfrom A n ( k ) to A n − ( k ) where π (cid:48) = β ( π ) is obtained from π by deleting the entry (cid:96) just before k − π greater than (cid:96) . For instance, β (41532) = 4132. It is easy tosee that β ( π ) belongs to A n − ( k ). Conversely, we will prove that any π ∈ A n − ( k ) is the image by β of a permutation in A n ( k ). To do this, we insert just before π i = k − (cid:96) > π = k such that,after increasing by one all entries π j ≥ (cid:96) , the obtained permutation belongs to A n ( k ). The choice of (cid:96) isalways possible in a unique way. Indeed, it suffices to take (cid:96) as follows: ( i ) if there is no entry π u > π for1 < u < i , such that there is a π v < π with u < v < i , then we set (cid:96) = n ; ( ii ) otherwise, (cid:96) is the minimalentry π u > π , 1 < u < i , such that there is a π v < π i with u < v < i . For the two cases, inserting n justbefore k − i ), if we do not choose n then wecreate a pattern [132 that cannot be extended to a [2413 which is banned. For the case ( ii ), if we do notchoose π u minimal then a pattern 2314 is created, which is banned. Therefore, (cid:96) is unique which impliesthat β is a bijection.Finally, if we set a kn = | A n ( k ) | , then due to the bijections α and β we have a kn = a k − n + a kn − for2 ≤ k ≤ n . Since A n (1) = { · · · n } and A n ( n ) is the set of length n permutations avoiding 213 andstarting with n , the initial conditions are given by a n = 1 and a nn = c n − where c n is the n th Catalannumber c n = n +1 (cid:0) nn (cid:1) . Therefore, a kn generates the well known Catalan’s triangle (see Table 2 and[7, 10, 16]), which implies that a n = (cid:80) nk =1 a kn corresponds to the n th Catalan number c n (see A000108 and
A009766 in [18]). (cid:50)
It is worth to mention that the classical (one) stack sorting, the 12-machine [8] and the (123 , n they sort different but equinumerous sets of length n permutations. k \ n . . . . . . . . . (cid:80) a kn = | A n ( k ) | for 1 ≤ n ≤ ≤ k ≤
6. The five sortablepermutations of length four and starting with 3 are 3124 , , , , α of thefirst three permutations are respectively 2134, 2341, 2413. The image by β of the last two permutationsare 312 and 321. In this section we characterize and enumerate all sortable permutations using the (132 , P is not empty, then it contains an anti-unimodal sequence, i.e. a sequence a a . . . a i a i +1 . . . a j such that a > a > · · · > a i < a i +1 < · · · < a j ,for some i , 1 ≤ i ≤ j . Theorem 2.
A permutation π belongs to Sort (132 , if and only if π avoids and . roof. First, let us prove that a sortable permutation π contains neither the pattern 1324 nor 2314. Fora contradiction, let us assume that π contains one of these patterns, and for an occurrence θ of it we picka particular one: θ = π i π j π k π (cid:96) , 1 ≤ i < j < k < (cid:96) ≤ n , where (cid:96) is chosen minimal, k maximal and j, i minimal, in this order.– If θ is an occurrence of 1324, then due to the choice of i, j, k, (cid:96) above, a simple observation shows that π u > π j for any u < i . Whenever the entry π k is pushed in P and since P avoids 132 and 231, at leastone of the two entries π i and π j does not belong to P . ( i ) Assume that π i does not belong to P . In thiscase, there is a previous step of the sorting process where π i is the top of P , and the next step pushes π i in P because pushing the current entry of the input permutation creates a pattern 132 or 231. Thisnecessarily implies that there is a u < i , such that π u < π i and π u ∈ P , which gives a contradictionwith the above observation. ( ii ) Assume that π j is in P and π i in P ( π k has been pushed on the top of P ). Since π (cid:96) > π j , π (cid:96) cannot be pushed in P by keeping π i in P (otherwise this would create a nonsortable configuration 231 with π j π (cid:96) π i , and Fact 1 gives a contradiction). Then, we need to push π i in P before pushing π (cid:96) in P , which necessarily implies that there is a u , k < u ≤ (cid:96) , such that π u < π i .Then, π i π j π u π (cid:96) is an occurrence of pattern 2314 which is a contradiction with the maximality of k .– If θ is an occurrence of 2314, then the proof is similar, mutatis mutandis , to that of the previous case.Conversely, let assume that π is not sortable and let us prove that π contains an occurrence of the pattern1324 or 2314. Let us consider the step where the process is stuck. Let π k (resp. π (cid:96) ) be the top of thestack P (resp. P ), then we necessarily have π (cid:96) > π k . We distinguish two cases: ( i ) k < (cid:96) and ( ii )otherwise.In the case ( i ), there necessarily exists a previous step where there are i and j , i < k < j < (cid:96) such that π i and π k are in P and π j is the first entry of the input permutation, and such that θ = π i π k π j is anoccurrence of 132 or of 231 (otherwise we cannot push π k in P ). If θ is an occurrence of 132 then, since π (cid:96) > π k , the pattern of π i π k π j π (cid:96) is 1324. If θ is an occurrence of 231 then, since π (cid:96) > π k , the pattern of π i π k π j π (cid:96) is 2314.In the case ( ii ), we have k > (cid:96) . In order to push π k in P , there is a previous step where we push firstly π k in P by keeping π (cid:96) in P which implies that at this step all values below π (cid:96) in P are greater than π (cid:96) , and all values above π (cid:96) and below π k are lower than π (cid:96) . Then, in order to push π k into P , we needto have u and v , (cid:96) < u < k < v , such that π u π k π v is an occurrence of 132 or of 231, and π u ∈ P and π v is the first entry of the input. Therefore, each time we push in P the top x of the stack P , we need tohave a value y above π (cid:96) and below x in P . This means that π (cid:96) cannot be the top of the stack P , whichis a contradiction. (cid:50) Corollary 2.
Permutations of length n in Sort (132 , are enumerated by the large Schr¨oder numbers(see A006318 in [18]).Proof.
The enumeration of length n permutations avoiding 1324 and 2314 (or a symmetry of thesepatterns) can be found in [5, 21] for instance. Note that in [4], the authors provide a constructivebijection between these permutations and Schr¨oder paths. (cid:50) In Section 2, we have characterized and enumerated length n sortable permutations with the (123 , k generates the well known Catalan’s triangle, which in turn corresponds tothe number of Dyck paths of semilength n and having the first peak at height n − k + 1. As a futurework, it would be interesting to exhibit a constructive bijection between these sets.Also, experimental results suggest that three other ( σ, τ )-machines sort permutations counted by theCatalan numbers. We leave them as open problems. Problem 1.
A permutation π belongs to Sort (123 , if and only if π avoids [24¯13 , [4231 , [31425 , [421¯35 , and any occurrence of [2413 in π is contained in a occurrence of [31524 or [32514 . Moreover,permutations of length n in Sort (123 , are enumerated by the Catalan numbers. Problem 2.
Permutations of length n in Sort (132 , and in Sort (231 , are both enumerated bythe Catalan numbers. References [1] M.D. Atkinson. Generalized stack permutations.
Combinatorics, Probability and Computing , ,239-246, 1998.[2] M.D. Atkinson, and J.R. Sack. Pop-stacks in parallel. Information Processing Letters , (2), 63–67,1999.[3] M.D. Atkinson, M.M. Murphy, and N. Ruskuc. Sorting with two ordered stacks in series. Theoret.Comput. Sci. , (1), 205–223, 2002.[4] J. Bandlow, E.S. Egge, and K. Killpatrick. A weight-preserving bijection between Schr¨oder pathsand Schr¨oder permutations. Annals of Combinatorics , (3-4), 235–248, 2002.[5] E. Barcucci, A. Del Lungo, E. Pergola, and R. Pinzani. Some combinatorial interpretations of q -analogs of Schr¨oder numbers. Ann. Combin. , , 171–190, 1999.[6] M. B´ona. A survey of stack-sorting disciplines. The Electronic J. of Combinatorics , (2), Discrete Math. , (2), 529–539, 2019.[8] G. Cerbai, A. Claesson, and L. Ferrari. Stack sorting with restricted stacks. Journal of CombinatorialTheory, Series A , , 105230, 2020.[9] G. Cerbai. Sorting Cayley permutations with pattern-avoiding machines. arxiv.org/pdf/2003.02536 ,2020.[10] D. Desantis, R. Field, W. Hough, B. Jones, R. Meissen, and J. Ziefle. Permutation pattern avoidanceand the Catalan triangle. Missouri J. Math. Sci. , (1), 50–60, 2013.[11] S. Kitaev. Patterns in permutations and words. Springer, 2011.[12] D.E. Knuth. The art of computer programming, Volume 1. Fundamental Algorithms, Addison-Wesley, Reading, Massachussetts, 1973 [13] D.E. Knuth. The art of computer programming, Volume 3.
Sorting and Searching, Addison-Wesley,Reading, Massachussetts, 1973 [14] M.M. Murphy. Restricted permutations, antichains, atomic classes, and stack sorting.
PhD thesis ,Univ. of St Andrews, 2002.[15] A. Pierrot, and D. Rossin. 2-Stack sorting is polynomial.
Theory of Computing Systems, SpringerVerlag , (3), 552–579, 2017.[16] L.W. Shapiro. A Catalan triangle. Discrete Math. , , 83–90, 1976.[17] R. Smith. Two stacks in series: a decreasing stack followed by an increasing stack. Ann. Comb. , ,359-363, 2014.[18] N.J.A. Sloane. The On-Line Encyclopedia of Integer Sequences. Available electronically at http://oeis.org.[19] R. Tarjan. Sorting using networks of queues and stacks.
J. Assoc. Comput. Mach. , , 341–346,1972.[20] J. West. Permutations with forbidden subsequences and stack sortable permutations. PhD thesis,Massachusetts Institute of Technology, 1990. 621] J. West. Generating trees and the Catalan and Schr¨oder numbers. Discrete Math. ,146