Contents lists available atScienceDirect
Information
Processing
Letters
www.elsevier.com/locate/ipl
Catalan
and
Schröder
permutations
sortable
by
two
restricted
stacks
Jean-Luc Baril
a,
Giulio Cerbai
b,
1,
Carine Khalil
a,
Vincent Vajnovszki
a,
∗
aLIB,UniversitédeBourgogneFranche-Comté,B.P.47870,21078DijonCedex,France bDipartimentodiMatematicaeInformatica“U.Dini”,UniversityofFirenze,Firenze,Italy
a
r
t
i
c
l
e
i
n
f
o
a
b
s
t
r
a
c
t
Articlehistory:
Received14September2020
Receivedinrevisedform15February2021 Accepted2May2021
Availableonline19May2021 CommunicatedbyAmitChakrabarti
Keywords:
Stacksorting/twostacksinseries Patternavoidingpermutations/machines CatalanandtheSchrödernumbers Combinatorialproblems
Pattern avoiding machines were introduced recently by Claesson, Cerbai and Ferrari as a particular case of the two-stacks in series sorting device. They consist of two restrictedstacks inseries,ruledby aright-greedy procedure andthe stacksavoidsome specified patterns.Someoftheobtainedresultshave beenfurthergeneralizedto Cayley permutations by Cerbai, specialized to particular patterns by Defant and Zheng, or consideredinthecontextoffunctionsoverthesymmetricgroupbyBerlow.Inthiswork we study pattern avoiding machines where the first stack avoidsa pairof patterns of length3and investigatethosepairs forwhichsortablepermutationsarecountedbythe (binomialtransformofthe)CatalannumbersandtheSchrödernumbers.
©2021PublishedbyElsevierB.V.
1. Introduction
Pattern avoiding machines were recently introduced in [7] inattempttogainabetterunderstandingofsortable permutationsusingstacksinseries.Theyconsistoftwo re-strictedstacksinseries,equippedwitharight-greedy pro-cedure,wherethefirststackavoidsafixedpattern,reading the elements from top to bottom; and the second stack avoids thepattern21 (whichis anecessarycondition for themachinetosortpermutations).Theauthorsof [7] pro-vide a characterization of theavoided patterns forwhich sortable permutationsdonotformaclass,andthey show that those patterns are enumerated by the Catalan num-bers.Forspecificpatterns,suchas123 andthedecreasing patternofanylength,ageometricaldescriptionofsortable
*
Correspondingauthor.E-mailaddresses:barjl@u-bourgogne.fr(J.-L. Baril),
giulio.cerbai@unifi.it(G. Cerbai),carine.khalil@u-bourgogne.fr(C. Khalil), vvajnov@u-bourgogne.fr(V. Vajnovszki).
1 G.C. is member of the INdAM Research group GNCS; he is par-tiallysupportedbyINdAM-GNCS2020project“Combinatoriadelle per-mutazioni,delleparolee deigrafi:algoritmie applicazioni”.
permutationsis also obtained. The pattern132 has been solvedlaterin [8].Someoftheseresultshavebeenfurther generalizedto Cayley permutations in [9]. More recently, Berlow [5] exploresasinglestackversionofpattern avoid-ingmachines,wherethestackavoidsasetofpatternsand the sorting process is regarded as a function. Analogous machines,butbasedonthenotionofconsecutivepatterns, havebeenintroducedanddiscussedin [10].
In this work we study a variant of pattern-avoiding machines where the first stack avoids
(
σ
,
τ
)
, a pair of patterns oflength three.Following [7], we call it(
σ
,
τ
)
-machine. More specifically, we restrict ourselves to those pairs of patterns for which sortable permutations are counted by either the Catalan numbers or two of their close relatives: the binomial transform of Catalan num-bers and the Schröder numbers. For the pair(
132,
231)
we show that sortable permutations are those avoiding 1324 and2314,a setwhoseenumerationis givenbythe large Schröder numbers. Under certain conditions on the avoided patterns, the output of the first stack is bijec-tively related to its input (see [5,9]): it follows that for threepairsofpatterns,namely(
123,
213)
,(
132,
312)
and(
231,
321)
,sortablepermutationsarecountedbytheCata-https://doi.org/10.1016/j.ipl.2021.106138 0020-0190/©2021PublishedbyElsevierB.V.
lannumbers.Thisresultwasconjecturedin [3] andsettled independently in [4,5]. Forthe pair
(
123,
132)
, we prove thatsortablepermutationsarethoseavoidingthepatterns 2314, 3214,4213 and the generalizedpattern[24¯
13. We prove that sortable permutations are enumerated by the Catalan numbers by showing that the distribution of the firstelement isgivenbythe well-knownCatalantriangle. Finally, we show that for the pair(
123,
312)
the corre-sponding countingsequence isthe binomial transformof Catalannumbers.This paper is the extended version of the conference presentation[4] andsome ofthepresented results previ-ouslyappearin [3].
2. Notationsandsomepreliminaryresults
We start by recalling some classical definitions about pattern avoidance on permutations (see [12] for a more detailedintroduction). Denote by
Sn
the set of permuta-tions oflengthn andletS
= ∪n
≥0Sn.
Giventwopermu-tations
σ
oflengthk andπ
=
π
1· · ·
π
n,wesaythatπ
con-tains thepatternσ
ifπ
containsasubsequenceπ
i1· · ·
π
ik, withi1<
i2<
· · · <
ik,whichisorderisomorphictoσ
.In thiscase,wesaythatπ
i1· · ·
π
ikisanoccurrence ofthe pat-ternσ
inπ
.Otherwise,wesaythatπ
avoidsσ
.We say that
π
contains an occurrence ofthe (gener-alized) pattern[
σ
ifπ
contains an occurrenceofσ
that involvesthefirstelementπ
1 ofπ
.Forinstance,anoccur-renceof
[
12 inπ
correspondstoapairofelementsπ
1π
i,with i
>
1 andπ
i>
π
1. A barredpatternσ
˜
is a patternwheresomeentriesarebarred.Let
σ
betheclassical pat-tern obtainedby removing all the bars fromσ
˜
.Letτ
be the pattern whichis order isomorphic to the non-barred entries ofσ
˜
(i.e. obtained fromσ
˜
by removing all the barred entries and suitably rescaling the remaining ele-ments).Apermutationπ
avoidsσ
˜
ifeachoccurrenceofτ
in
π
canbeextendedtoan occurrenceofσ
.Forinstance, apermutationπ
avoidsthepattern[
24¯13 ifforany subse-quenceπ
1π
iπ
j,with1<
i<
j andπ
1<
π
j<
π
i,thereis an indext,i<
t<
j,suchthatπ
1π
iπ
tπ
j isanoccurrence of2413.Given a set of (generalized) patterns T , denote by
Av
n(
T)
the setofpermutationsinSn
avoiding each pat-terninT .Similarly,letAv
(
T)
= ∪n
≥0Av
n(
T)
.IfT= {
σ
}
is asingleton,wewriteAv
n(
σ
)
andAv
(
σ
)
.Inhiscelebrated book [13], Knuth gave the following characterization of stacksortablepermutations,whichisoftenconsideredthe starting point of stack sorting and permutation patterns disciplines.Proposition1([13]).Apermutation
π
issortableusinga clas-sicalstack(thatis,a21-avoidingstack)ifandonlyifπ
avoids thepattern231.Let T be a set of patterns. A T -stack is a stack that isnot allowed tocontain anoccurrenceofanypatternin T ,readingits elements fromtop tobottom. Givena per-mutation
π
,denotebyoutT(
π
)
thepermutationobtained after passingπ
through the T -avoiding stack by apply-ing a greedy procedure, i.e. by always pushing the next element of the input, unless it creates an occurrence ofa forbidden pattern inside the stack. Denote by Sortn
(
T)
theset oflength n permutationsthat are sortable by the T -machine, that is, by passingπ
through the T -avoiding stack and then through the 21-avoiding stack. Permuta-tions inSortn(
T)
arecalled T -sortable, andSort(
T)
is the setof T -sortablepermutationsofanylength.As a conse-quenceofProposition1,Sort(
T)
consistspreciselyofthose permutationsπ
for which outT(
π
)
avoids 231. To ease notations,if T is either a singleton T= {
σ
}
or a pair of patterns T= {
σ
,
τ
}
,wewill omitthecurlybracketsfrom theabovenotations.Forinstance,wewillwriteSort(
σ
,
τ
)
insteadofSort(
{
σ
,
τ
})
.The authors of [7] showed that if
π
is a 12-sortable permutation of length n, then out12(
π
)
=
n(
n−
1)
· · ·
1. Moreover,by Proposition1 andapplyingthecomplement operation on the processed permutation, we have that Sort(
12)
= Av(
213)
. In order to refer to thisresult later, we state itbelowina slightlymoregeneral form.A par-tial permutation of n is an injectionπ
: {
1,
2,
. . . ,
k}
→
{
1,
2,
. . . ,
n}
,forsome 0≤
k≤
n,andtheintegerk issaid tobe the length ofπ
. Welet a 12-stackact on apartial permutationπ
ofn in the naturalway by identifyingπ
withthelistofitsimages.
Proposition2.If
π
isapartialpermutationofn whichis 12-sortable,thenout12(
π
)
isthedecreasingrearrangementofthe symbolsofπ
.Moreover,π
is12-sortableifandonlyifitavoids 213.An entry
π
i ofa permutationπ
isa left-to-right min-imum ifπ
i<
π
j, for each j<
i. The left-to-rightminima decomposition (briefly ltr-mindecomposition) ofπ
isπ
=
m1B1m2B2· · ·
mtBt,wherem1>
m2>
· · · >
mt arethe ltr-minimaofπ
andtheblock Bicontains theelements ofπ
betweenmi andmi+1,for i=
1,
. . . ,
t−
1. The last block Bt contains the elements that followmt inπ
.Note that mt=
1. The notion of left-to-rightmaximum of a permu-tationπ
isdefinedsimilarly. Theltr-maxdecomposition ofπ
isπ
=
M1B1M2B2· · ·
MtBt,where M1<
M2<
· · · <
Mt are theltr-maximaofπ
.In thiscase Mt=
n, wheren is thelengthofπ
.Finally,thesequence
(
cn)
n≥0,pervasiveinthispaper,isthesequenceofCatalannumberscn
=
n+11 2n n (A000108 in [15]). 3. Pair(
132,
231)
Thissectionisdevotedtotheanalysisofthe
(
123,
231)
-machine.Theorem1.Considerthe
(
132,
σ
)
-machine,whereσ
=
σ
1· · ·
σ
k−1σ
k∈ Sk
,withk≥
3 andσ
k−1>
σ
k.Givenapermutationπ
oflengthn,letm1B1· · ·
mtBt=
π
beitsltr-min decomposi-tion.Then:1. Everytimealtr-minimummiispushedintothe
(
132,
σ
)
-stack,the(
132,
σ
)
-stackcontainstheelementsmi−1,
. . . ,
m2,
m1,readingfromtoptobottom.Moreover,wehavewhereB
˜
iisarearrangementofBi.2. If
π
is(
132,
σ
)
-sortable,thenB˜
iisdecreasingforeachi. Moreover,foreachi≤
t−
1,wehaveBi>
Bi+1(i.e.x>
y foreachx∈
Bi,
y∈
Bi+1).Proof. 1. Let usconsider theevolution of the
(
132,
σ
)
-stackon input
π
.Notethat, sincek≥
3,the element m1 remains atthebottom ofthe(
132,
σ
)
-stack untiltheendofthe process.Now,if B1 is notempty then
foreach x
∈
B1,the elements m2xm1 form anoccur-rence of132.Therefore theblock B1 is extracted
be-forem2 entersthe
(
132,
σ
)
-stack.After m2 ispushed,the
(
132,
σ
)
-stackcontainsm2m1,readingfromtoptobottom. Sincem2
<
m1,butσ
k−1>
σ
k by hypothesis, m2 cannot play the role of eitherσ
k−1 in anoccur-rence of
σ
orof 3 in anoccurrenceof 132.Thusm2remains atthebottomofthe
(
132,
σ
)
-stack untilthe endofthesortingprocedure.Thethesisfollowsby it-eratingthesameargumentoneachblockBi,fori≥
2. 2. Suppose thatπ
is(
132,
σ
)
-sortable. Assume, for a contradiction, that B˜
i is not decreasing, for some i. Then therearetwoconsecutiveelements x<
y inB˜
i. Therefore,bywhatprovedabove,out132,σ(
π
)
contains an occurrence xymt of 231, which is impossibledue toProposition1.Finally,supposethatx<
y,forx∈
Bi and y∈
Bi+1. Then xymt is an occurrenceof 231 in out132,σ(
π
)
,acontradiction.Theorem 1 and Proposition 2 guarantee that if
π
=
m1B1· · ·
mtBt isthe ltr-mindecompositionofa(
132,
231)
-sortable permutationπ
, then (with the notation above)˜
Bi
=
out12(
Bi)
,foreachi.However,thisistrueevenwhen thesortabilityrequirementisrelaxed.Lemma1.Let
π
=
m1B1· · ·
mtBtbetheltr-mindecomposition ofapermutationπ
.Writeout132,231(
π
)
= ˜
B1
· · · ˜
Btmt· · ·
m1 asinTheorem1.ThenB˜
i=
out12(
Bi)
,foreachi.Proof. Considertheinstantimmediatelyaftermiispushed
intothe
(
132,
231)
-stackandthenon-empty block Bi has tobeprocessed,forsomei.ByTheorem1,atthispointthe(
132,
231)
-stack contains mi,
mi−1,
. . . ,
m1, reading fromtop tobottom.Wewanttoshowthat thebehaviorofthe
(
132,
231)
-stackon Bi isequivalent tothebehavior ofan empty12-stackoninput Bi.Weprovethatthe(
132,
231)
-stack performs the pop operation of some x∈
Bi if and only ifthe 12-stackdoes thesame. Ifeitherthe next el-ement ofthe input ismi+1 orx is the last elementofπ
to be processed, then both the
(
132,
231)
-stack and the 12-stack perform a pop operation, as desired. Otherwise, supposethenextelementoftheinputis y,forsome y in thesameblock Bi,andthe(
132,
231)
-stackpops the ele-mentx∈
Bi.Thismeansthatthe(
132,
231)
-stackcontains two elements z,
w,withz above w,such that yzw isan occurrence of either 132 or231. Note that, since z>
w, z isnot a ltr-minimum. Therefore yz is an occurrenceof 12 andthe12-stackperformsapopoperation,asdesired. Conversely,supposethatthe12-stackpopstheelementx, with y∈
Bi the next element of the input. This implies that the 12-stack contains an element z such that z>
y.Thereforeyzmiisanoccurrenceof231 andthe
(
132,
231)
-stackperformsapopoperation,asdesired.Corollary1.Let
π
=
m1B1· · ·
mtBtbetheltr-min decomposi-tionofapermutationπ
.Thenthefollowingareequivalent.1. Biavoids213 andBi
>
Bi+1,foreachi. 2.π
is(
132,
231)
-sortable.3.
π
∈ Av(
1324,
2314)
.Proof. Combiningthe firstpoint in Theorem 1and
Lem-ma1wehave:
out132,231
(
π
)
=
out12(
B1)
· · ·
out12(
Bt)
mt· · ·
m1.
We will use this decomposition of out132,231
(
π
)
throughouttherestoftheproof.
[1
⇒
2] Suppose, for a contradiction, that out132,231(
π
)
contains anoccurrencebca of231.Notethat,since c
>
a, while mt<
· · · <
m1, c is not a ltr-minimum ofπ
(andthusneitherisb).Now,ifb andc areinthesameblockBj, thenout12
(
Bj
)
isnotdecreasing.Thus,byProposition2,Bj contains213,whichisacontradiction.Otherwise,ifb∈
Bj andc∈
Bk,with j<
k,then wehavea contradictionwith thehypothesis Bi>
Bi+1 foreachi.[2
⇒
3] Suppose, for a contradiction, thatπ
∈ Av(
/
1324,
2314)
.First, suppose thatπ
contains an occurrenceacbd of1324.Observethatb,
c,
d arenotltr-minimaofπ
.Now, ifb andd areinthesameblock Bj ofπ
,forsome j,then Bj containsanoccurrencecbd of213.Thereforeout12(
Bj)
containsanoccurrenceof231 duetoProposition2,which contradictsthehypothesis.Otherwise,ifb∈
Bjandd∈
Bk, forsome j<
k, thenout132,231(
π
)
contains anoccurrence bdmk of231,againa contradiction. Thepattern2314 can beaddressedanalogously,soweleaveittothereader. [3⇒
1] Letπ
∈ Av(
1324,
2314)
.If Bi contains an occur-rencebac of213,thenπ
containsan occurrencemibac of 1324,whichisimpossible.Otherwise,ifπ
containstwo el-ementsx∈
Bj, y∈
Bk,withx<
y and j<
k,thenmjxmky isanoccurrenceof2314,contradictingthehypothesis. TheenumerationofAv
(
1324,
2314)
(or asymmetryof thesepatterns) can be found for instance in [2,16]. Note thatin [1],theauthorsprovideaconstructivebijection be-tweenthesepermutationsandSchröderpaths.Corollary2.Permutations oflengthn in Sort
(
132,
231)
are enumeratedbythelargeSchrödernumbers(sequenceA006318
in [15]).4. The
(
σ
,
σ
ˆ
)
-machineForapermutation
σ
oflengthtwoormore,denotebyˆ
σ
thepermutation obtained fromσ
by interchanging its firsttwoentries.Letusregard a(
σ
,
τ
)
-stackasan opera-tor outσ,τ: S
→ S
.By convenientlymodifying the proof of Corollary 4.5 in [9] (stated in the context of Cayley permutations), we have that outσ,τ is a length preserv-ing bijection onS
if andonly ifτ
= ˆ
σ
. More generally, Berlow [5] showed that foraset T ofpatterns, outT isalengthpreservingbijectionon
S
ifandonlyifT isclosed under theˆ
operator. In order for the paper to be self-contained,weshallgivethefollowingresult,whichis eas-ier to prove (although weaker): outσ,σ isˆ a bijection forany pattern
σ
. An immediateconsequence will be Theo-rem2below.LetN∗bethesetoffinitelengthintegersequences.The actionofthe
(
σ
,
τ
)
-stackoninputπ
canbenaturally rep-resentedasasequenceoftriples(
r;
s;
t)
∈ (
N∗)
3,wherer isthecurrentcontentoftheoutput,s is thecurrent con-tent of the(
σ
,
τ
)
-stack (read fromtop to bottom) andt is the current content of the input. The triple(
r;
s;
t)
is saidtobea stateofpassing ofπ
throughthe(
σ
,
τ
)
-stack. Clearly,r isaprefixofoutσ,τ(
π
)
,t isasuffixofπ
,the ini-tialstateis(λ
;
λ
;
π
)
andthefinaloneis(
outσ,τ(
π
)
;
λ
;
λ)
, whereλ
istheemptysequence.Moreoveranon-finalstate(
p1p2· · ·
pa;s1s2· · ·
sb;t1t2· · ·
tc)
isfollowedby eitherthe state(
p1p2· · ·
pas1;
s2· · ·
sb;
t1t2· · ·
tc),
ifapopoperationisperformednext,or(
p1p2· · ·
pa;
t1s1s2· · ·
sb;
t2· · ·
tc),
ifapushoperationisperformednext.For p
=
p1· · ·
pn∈ N
n, we denote by pr the reverse of p, that is pr=
pn· · ·
p1. We wish to show that thebehavior of the
(
σ
,
σ
ˆ
)
-stack onπ
is strictly related to its behavior onoutσ,σˆ
(
π
)
r.More precisely, ifo1
· · ·
o2nis the sequence ofpush/pop operationsperformed when
π
is passed through a(
σ
,
σ
ˆ
)
-stack, then o 2n· · ·
o 1 isthe sequence of push/pop operations performed when
outσ,σˆ
(
π
)
rispassedthroughthe(
σ
,
σ
ˆ
)
-stack,whereoi isa push(resp.pop) operation ifoi isapop (resp.push) operation. This can be equivalently expressed by saying that thestate
(
p;
s;
t)
isfollowedby(
u;
v;
w)
ifandonly ifthestate(
wr;
v;
ur)
isfollowedby(
tr;
s;
pr)
.Lemma2.Considertheactionofthe
(
σ
,
σ
ˆ
)
-stack.Letp,
s,
t∈
N
∗andx∈ N
.1. Ifthestate
(
p,
xs,
t)
isfollowedbythestate(
px,
s,
t)
(and thusapopoperationisperformed)thenthestate(
tr,
s,
xpr)
isfollowedbythestate(
tr,
xs,
pr)
(andthusapush opera-tionisperformed).2. If the state
(
p,
s,
xt)
is followed by the state(
p,
xs,
t)
(andthusapushoperationis performed),thenthestate(
tr,
xs,
pr)
isfollowedbythestate(
trx,
s,
pr)
(andthusa popoperationisperformed).Proof. 1. Since xs is the content ofthe
(
σ
,
σ
ˆ
)
-stack in the state(
p,
xs,
t)
, we have that xs avoidsσ
andσ
ˆ
. Thusapushoperationisperformedifs isthecontent of the(
σ
,
σ
ˆ
)
-stack and x isthe next element of the input.2. If p isempty,thestatementholds.Otherwise,let p
=
p1· · ·
pa and s=
s1· · ·
sb.Observe that pa is the last elementthathasbeenextractedfromthe(
σ
,
σ
ˆ
)
-stackbefore x enters. Therefore, when pa is extracted, pa playstheroleofeither
σ
2inanoccurrenceofσ
orofˆ
σ
2 in an occurrenceofσ
ˆ
. More precisely,one of thefollowingfourcaseshold.Weshowthedetailsforthe first caseonly, the othersbeing similar. Let z be the lengthof
σ
.•
spasi3· · ·
siz is an occurrenceofσ
,forsome≥
1 and<
i3<
· · · <
iz. Then passi3· · ·
siz is an oc-currenceofσ
ˆ
andthereforeapopoperationis per-formed when pa is the next element of the input andxs isthecontentofthe(
σ
,
σ
ˆ
)
-stack,asdesired.•
spasi3· · ·
siz is an occurrenceofσ
ˆ
,forsome≥
1and
<
i3<
· · · <
iz.•
xpasi3· · ·
siz is an occurrence ofσ
, for some i3<
· · · <
iz.•
xpasi3· · ·
siz is an occurrence ofσ
ˆ
, for some i3<
· · · <
iz.Astraightforward consequence ofthe previous lemma is that the map
outσ,σˆ
r: S
→ S
is its own inverse, and thus a bijection. More specifically, for any permuta-tionπ
,wehave outσ,σˆ −1(
π
)
=
outσ,σˆ(
π
r)
r.Sinceπ
is
(
σ
,
σ
ˆ
)
-sortableifandonlyifoutσ,σˆ(
π
)
avoids231 (and thereversemapisbijective),wehavethatSort(
σ
,
σ
ˆ
)
isin bijectionwithAv
(
231)
.Thenexttheoremfollows.Theorem2.Foranypattern
σ
,outnσ,σˆ isabijection onSn
. Moreover,wehave|
Sortn(
123,
213)
| = |
Sortn(
132,
312)
|
= |
Sortn(
231,
321)
| =
cn,
thenthCatalannumber.5. Pair
(
123,
132)
We characterize Sort
(
123,
132)
in terms of pattern avoidance.Thenweshow that(
123,
132)
-sortable permu-tationsareenumeratedbytheCatalannumbersby exhibit-ingalinkwiththeverywellstudiedCatalantriangle.Theorem3.Apermutation
π
is(
123,
132)
-sortableifandonly ifπ
avoids2314,3214,4213 and[
24¯13.Proof. Supposethat
π
is(
123,
132)
-sortable.Fora contra-diction, suppose thatπ
containsτ
∈ {
2314,
3214,
4213}
. Pick an occurrenceπ
iπ
jπ
kπ
ofτ
, with i<
j<
k<
,where
ischosenminimal,andk, j,andi arechosen max-imal,inthisorder.
If
τ
=
2314,due to our choice ofi,
j,
k,
,we have
π
i<
π
u<
π
j, for k<
u<
. Now, whenπ
k is pushed in the(
123,
132)
-stack, at least one ofπ
i andπ
j has already beenextracted:otherwisethe(
123,
132)
-stackwould con-tainanoccurrenceof132,whichisforbidden.Foreachu, k+
1≤
u≤
,wehaveπ
k<
π
u andwhenπ
u ispushedin the(
123,
132)
-stack,π
kisstillinthe(
123,
132)
-stack. In-deed,π
uπ
xπ
y cannotbean occurrenceof123 norof132 withπ
x aboveπ
y,bothinthetailofthe(
123,
132)
-stackbeginningby
π
k.Ifπ
i(resp.π
j)isextractedbeforeπ
k en-tersinthe(
123,
132)
-stack,thenπ
iπ
k+1π
k (resp.π
jπ
π
k) createsapattern231 inout123,132(
π
)
,acontradiction.If
τ
=
3214, dueto our choice of i,
j,
k,
, we have
π
i>
π
u>
π
j, for k<
u<
; andπ
u<
π
u+1, for k≤
u<
.As above, when
π
k is pushed in the(
123,
132)
-stack, at least one ofπ
i andπ
j has already been extracted: oth-erwise the(
123,
132)
-stack would contain an occurrence of 123. Sinceπ
k+1>
π
k, the next step pushesπ
k+1 inthe
(
123,
132)
-stack. (i)Assumethatπ
i andπ
j bothhad left the(
123,
132)
-stack. Thenπ
k is just belowπ
k+1 inthe
(
123,
132)
-stack,andπ
k<
π
j<
π
k+1.Thisimpliesthatπ
jπ
k+1π
k isanoccurrenceof231 in out123,132(
π
)
,a con-tradiction. (ii) Assume thatπ
i is still in the(
123,
132)
-stackandπ
jhadleftthisstack.Again,π
jπ
k+1π
kisan oc-currence of231 inout123,132(
π
)
,a contradiction.(iii)As-sumethat
π
jisstillinthe(
123,
132)
-stackandπ
ihadleft thisstack.Sinceπ
u<
π
u+1fork≤
u≤
−
1,thenextstepsoftheprocesspushsuccessivelyallentries
π
k+1,
. . . ,
π
inthe
(
123,
132)
-stack.Asabove,π
iπ
π
k isanoccurrenceof 231 inout123,132(
π
)
,againacontradiction.Thecase
τ
=
4213 canbetreatedsimilarly.Finally, suppose that
π
contains[
24¯13. Equivalently, thereare twoindicesi<
j suchthatπ
1π
iπ
j isan occur-renceof132 andπ
k>
π
1foreachi<
k<
j.Observethat,by choosing j minimalandi maximal(in thisorder), we canassume j
=
i+
1.Now,ifπ
i isstillinthe(
123,
132)
-stack whenπ
i+1 enters, then out123,132(
π
)
contains anoccurrence
π
i+1π
iπ
1 of 231,which is impossibledue tothesortability of
π
.Thereforeπ
i isextractedbeforeπ
i+1enters. Thismeansthat thereare twoelements
π
u,
π
v in the(
123,
132)
-stack, withu<
v (and thusπ
v aboveπ
u), suchthatπ
i+1π
vπ
u isanoccurrenceofeither123 or132. Chooseu,
v minimalamongstthoseindices,2 sothatπ
u is still inthe
(
123,
132)
-stackwhenπ
i+1 enters.Notice thatπ
i+1<
π
u (andthusu=
1).Moreover,itmustbeπ
u<
π
i, otherwiseπ
iπ
uπ
1 wouldbe an occurrenceof 231 in the(
123,
132)
-stack,whichisforbidden.Butthenπ
i+1π
uπ
1isanoccurrenceof231 inout123,132
(
π
)
,acontradiction.Conversely, suppose that
π
is not(
123,
132)
-sortable. Weshallprovethatπ
containsatleastoneofthepatterns 3214, 2314, 4213 or[
24¯13. By hypothesis out123,132(
π
)
contains anoccurrencebca of231.Letb
=
π
j andc=
π
k, forsomeindices j,
k.Wedistinguishtwo cases,according whether j<
k or j>
k.•
Supposethat j<
k and thusπ
j isextractedfromthe(
123,
132)
-stackbeforeπ
k enters.Thenthereare two elementsπ
u,
π
v in the(
123,
132)
-stack, with u<
v (and thusπ
v aboveπ
u), such thatπ
zπ
vπ
u is an oc-currence of either 123 or 132, whereπ
z is the next element of the input. Notice thatπ
j≥
min{
π
u,
π
v}, since otherwiseπ
jπ
vπ
u would be an occurrence of either 123 or 132 in the(
123,
132)
-stack, which is impossible. Thusπ
k>
π
j>
π
z. Ifπ
zπ
vπ
u is an oc-currence of 123, thenπ
uπ
vπ
zπ
k isan occurrenceof2 In other words, pick the deepest such elements πu,πv in the
(123,132)-stack.
either4213,if
π
u>
π
k,or3214,ifπ
u<
π
k.Finally,ifπ
zπ
vπ
u isanoccurrenceof132,thenπ
uπ
jπ
zπ
kisan occurrenceof2314.•
Suppose instead that j>
k and thusπ
k is still in the(
123,
132)
-stack whenπ
j enters. Observe that k=
1, sinceπ
1 is the last element of out123,132(
π
)
.Therefore, when
π
j enters the(
123,
132)
-stack, the(
123,
132)
-stackcontains theelementsπ
jπ
kπ
1,read-ingfromtoptobottom.Noticethat
π
j>
π
1,otherwiseπ
jπ
kπ
1 wouldrealizean occurrenceoftheforbidden132 insidethe
(
123,
132)
-stack.Moreover,foreach en-tryπ
t, with k<
t<
j, we haveπ
t>
π
1. Otherwiseπ
tπ
kπ
1 wouldbeanoccurrenceof132 andπ
k would beextractedbeforeπ
j,whichisimpossibleduetoour assumptions.Thusπ
1π
kπ
j isanoccurrenceof[
24¯13. Thiscompletestheproof.Proposition3.ThedistributionofthefirstelementinSort
(
123,
132)
is given by the Catalan triangle (sequenceA009766
in [15]).Proof. Let An
(
k)
be the set of(
123,
132)
-sortable per-mutations of length n and starting with k. Let A1n
(
k)
be thesubset of An(
k)
consistingofthosepermutationsπ
=
π
1π
2. . .
π
n where any occurrenceπ
1π
iπ
of[
231 withπ
=
π
1−
1 canbeextendedintoanoccurrenceπ
1π
iπ
jπ
of
[
3412.Set A2n
(
k)
=
An(
k)
\
An1(
k)
andletk≥
2.We shall providebijectionsα
:
A1n
(
k)
→
An(
k−
1)
andβ
:
An2(
k)
→
An−1(
k)
.Define
α
:
An1(
k)
→
An(
k−
1)
byα
(
π
)
=
π
, whereπ
is obtainedfromπ
by swapping thetwo entriesπ
1 andπ
1−
1 inπ
.Sinceπ
∈
A1n(
k)
, itis easyto check thatπ
avoids[
2413.¯
In addition, swappingπ
1 andπ
1−
1 doesnotaffecttheavoidanceofthethreepatterns3214,2314, 4213,whichimplies(see Theorem 3) that
α
(
π
)
∈
An(
k−
1)
.Nextdefine
β
:
A2n
(
k)
→
An−1(
k)
byβ(
π
)
=
π
,whereπ
isobtainedfromπ
by deletingtheentryπ
immedi-atelybeforek
−
1 andby decreasingby oneall entriesofπ
greaterthanπ
.Noticethatβ(
π
)
∈
An−1(
k)
.Letusnowsketchtheproofthat
β
isbijective,leavingsometechnical detailstothereader.Weshallexplicitlydefinetheinverse map ofβ
. Givenπ
∈
An−1(
k)
,choose anintegeras
fol-lows:
•
is the minimal entryl=
π
u>
π
1, with 1<
u<
i,such that there isan index v with
π
v<
π
i andu<
v<
i,ifsuchentryexists.•
Otherwise,set=
n.Thepreimage
π
isobtainedbyinsertingimmediately be-fore
π
i=
k−
1 andthen increasingbyone alltheentriesπ
j ofπ
withπ
j≥
.Finally,settingakn
= |
An(
k)
|
,we have that akn=
akn−1+
akn−1,for2
≤
k≤
n.Since An(
1)
= {
123· · ·
n}
and An(
n)
isthe setof length n permutationsavoiding 213 and start-ing withn, theinitial conditionsare givenbya1n
=
1 and ann=
cn−1,wherecn isthenthCatalannumber.Therefore, akn generatesthewell-knownCatalantriangle(see Table1 and [6,11,14]).
Table 1
TheCatalantriangleak
n= |An(k)|,with1≤n≤8 and1≤k≤6. k\n 1 2 3 4 5 6 7 8 1 1 1 1 1 1 1 1 1 2 1 2 3 4 5 6 7 3 2 5 9 14 20 27 4 5 14 28 48 75 5 14 42 90 165 6 42 132 297 . . . . . . . . . 1 2 5 14 42 132 429 1430
Corollary 3.Permutations oflengthn in Sort
(
123,
132)
are enumeratedbytheCatalannumbers.Proof. With the previous notations we have
|
Sortn(
123,
132
)
|
=
n
k=1ank=
cn, thenthCatalan number(see again [6,11,14]).6. Pair
(
123,
312)
Westartbygivingaltr-maxcounterpartofTheorem1.
Theorem4.Considerthe
(
312,
σ
)
-machine,whereσ
=
σ
1· · ·
σ
k−1σ
k∈ Sk
,withk≥
3 andσ
k−1<
σ
k.Givenapermutationπ
oflengthn,letπ
=
M1B1· · ·
MtBt beitsltr-max decompo-sition.Then:1. Everytimealtr-maximumMiispushedintothe
(
312,
σ
)
-stack,the(
312,
σ
)
-stackcontainstheelementsMi,
Mi−1,
. . . ,
M2,
M1,reading from top to bottom.Moreover, we haveout312,σ
(
π
)
= ˜
B1· · · ˜
BtMt· · ·
M1,
whereB˜
iisarearrangementofBi.2. If
π
is(
312,
σ
)
-sortable,thenM1,
M2,
. . . ,
Mt=
n−
t+
1,
n−
t+
2,
. . . ,
n.Proof. 1. Theproof isidenticaltothat ofthefirstpartof
Theorem1.
2.If
π
is(
312,
σ
)
-sortable,thenout312,σ(
π
)
avoids231 by Proposition 1. Suppose, fora contradiction, that there is an element j∈ {
n−
t+
1,
. . . ,
n}
which is not a ltr-maximum.Note that j=
π
1=
M1 and j=
n=
Mt. Then,out312,σ
(
π
)
containsanoccurrence jnM1 of231,whichis
acontradiction.
Instantiating
σ
by123 intheprevioustheoremwehave thenextresult.Theorem5.Let
π
bea(
123,
312)
-sortablepermutationand letπ
=
M1B1· · ·
MtBtbeitsltr-maxdecomposition.Then:1. Biavoids213 foreachi. 2. B
˜
i=
out12(
Bi)
,foreachi.Proof. Let i
≥
2. Notice that, as a consequence ofThe-orem 4, immediately after Mi has been pushed in the
(
123,
312)
-stack, this stack contains the elements Mi· · ·
M2M1,reading fromtop to bottom. Moreover, theseele-ments remainatthe bottomof the
(
123,
312)
-stackuntil theendofthesortingprocedure,sincetheyarethelast el-ementsofout123,312(
π
)
.Thisfactwillbeusedfortherestoftheproof.
1.Suppose,foracontradiction, that Bi contains an oc-currence of 213, for some i, andlet bac be such an oc-currence with a ‘minimal’, in the sense that there is no a
<
a whereba c isanoccurrenceof213 in Bi.Therefore, sinceabMiisanoccurrenceof123,b isextractedfromthe(
123,
312)
-stackbeforea enters.Inaddition,whenc enters intothe(
123,
312)
-stack,a isstillinthisstack.Indeed,no entryin Bi betweena and c together witha producesa forbidden pattern in the(
123,
312)
-stack. It follows that out123,312(
π
)
contains bca whichisanoccurrenceof231, yieldingacontradictionwiththesortabilityofπ
.2.Letusconsidertheactionofthe
(
123,
312)
-stackon the block Bi. We wish to show that the behavior of the(
123,
312)
-stack when processing Bi is equivalent to the behaviorofanempty12-stackoninputBi.Inotherwords, weprovethattherestrictionofthe(
123,
312)
-stackis trig-gered ifandonly ifthe next element of theinput forms an occurrence of 12 together with some other element in the(
123,
312)
-stack. Immediately after Mi has been pushed (i.e. before the first element of Bi is processed), the(
123,
312)
-stack contains the elements Mi· · ·
M2M1,reading fromtop to bottom. Observe that Bi avoids 213 bywhatprovedabove,thereforethe
(
123,
312)
-stack can-notbetriggeredbyanoccurrenceof312 whenprocessing Bi. Suppose that the next element of the input x forms an occurrence xy of 12 with some y∈
Bi. Then xyMi is an occurrence of 123 in the(
123,
312)
-stack, and so thisstackbehavesasa12-stack.Conversely, supposethat the(
123,
312)
-stackis triggered by an occurrenceof xyz of 123, where x is the next element of the input. Since Mi>
Mi−1>
· · · >
M1, necessarily y∈
Bi. Thus xy is an occurrenceof12 thattriggersthe12-stack,aswanted. Asaconsequenceofwhatprovedsofarinthissection, forany(
123,
312)
-sortablepermutationπ
=
M1B1· · ·
MtBt of length n, we have Bi∈ Av(
213)
and M1,
. . . ,
Mt=
n−
t+
1,
. . . ,
n. Moreover, by Proposition 2, each B˜
i in out123,312(
π
)
= ˜
B1
· · · ˜
BtMt· · ·
M1 isdecreasing.Therefore,for any three elements x
,
y,
z, with x∈
Bi, y∈
Bj and z∈
Bk, with i<
j≤
k, xyz is not an occurrence of 231. Otherwise xyz would still be an occurrence of 231 in out123,312(
π
)
,contradicting the factthatπ
is(
123,
312)
-sortable. From nowon, we saythat xyz is an occurrence of2
−
3−
1 if z<
x<
y, withx∈
Bi, y∈
Bj andz∈
Bk, withi<
j<
k.Similarly,when j=
k,wesaythatxyz isan occurrenceof2−
31.Theorem6.Let
π
=
M1B1· · ·
MtBtbetheltr-max decompo-sitionofapermutationπ
oflengthn.Writeout123,312(
π
)
=
˜
B1
· · · ˜
BtMt· · ·
M1 as in Theorem4. Thenπ
is(
123,
312)
-sortableifandonlyifthefollowingconditionsaresatisfied:1. Mj
=
n−
t+
j,foreachj=
1,
. . . ,
t.2. Biavoids213 foreachi (andthusB
˜
iisdecreasingforeach i).3. out123,312
(
π
)
avoids2−
3−
1. 4. out123,312(
π
)
avoids2−
31.Proof. If
π
is(
123,
312)
-sortable,thenπ
satisfiesall the above conditionsasaconsequenceofwhatproved before inthissection.Conversely,itiseasytocheckthatifπ
sat-isfiestheaboveconditions,thenout123,312(
π
)
avoids231.Thus
π
is(
123,
312)
-sortable.ReformulatingthethirdconditionofTheorem6we ob-tainthefollowinglemma,whoseeasyproofisomitted.
Lemma3.Let
π
=
M1B1· · ·
MtBt betheltr-max decomposi-tion of the(
123,
312)
-sortable permutationπ
. Write out123,312(
π
)
= ˜
B1
· · · ˜
BtMt· · ·
M1 as in Theorem 4. Thenout123,312
(
π
)
avoids 2−
31 ifand onlyif foreach x∈
Bi, y
∈
Bj,withi<
j,wehave:•
ify>
x,thenBj>
x.•
Ify<
x,thenBj<
x.In other words, Lemma 3 says that each block Bj of a
(
123,
312)
-sortable permutationπ
isboundedbetween two previous elements ofπ
. The following result is ob-tainedbyrestatingthislemmaandTheorem6intermsof patternavoidance.Theorem7.Apermutation
π
is(
123,
312)
-sortableifandonly ifπ
avoids thethree generalizedpatterns[
132,[
42531 and[
42153.Next we prove that
(
123,
312)
-sortable permutations areenumeratedbythebinomialtransformofCatalan num-bers. Weshallexploittheabove characterizationinterms of patternsin orderto provide a bijectionwith acertain setofpartialpermutations,whoseenumerationis straight-forward.Recall from Section 2 that a partial permutation of n is an injection
π
: {
1,
2,
. . . ,
k}
→ {
1,
2,
. . . ,
n}
, for some 0≤
k≤
n.The partial permutation of lengthzero will be denoted byλ
. Denote byA
n the set of all partial per-mutations of n. For instance, we haveA
3= {λ,
1,
2,
3,
12
,
21,
13,
31,
23,
32,
123,
132, 213,
231,
312,
321}
. There is a naturalbijection betweenthe setof permutationsinSn
avoiding the pattern[
132 andA
n−1. Indeed, from alength n permutation
π
avoiding[
132, we associate the unique partial permutationα
(
π
)
∈
A
n−1 defined asfol-lows:
α
(
π
)
πi=
i−
1,
forπ
i<
π
1.
In other words,
α
(
π
)
isobtained byrecording the in-dices(minusone)oftheelementsπ
i<
π
1,fromthesmall-esttothelargestone.Forinstance,if
π
=
52461783,thenα
(
π
)
=
4172.Notice thatα
(
π
)
= λ
ifandonlyifπ
1=
1.Let us now define two pattern containments on
A
n. Let a=
a1a2· · ·
am bea partialpermutation ofn, withm≤
n, andleti<
j<
k.Thenaiajak isanoccurrenceofthe pat-tern31|
2 ifitisanoccurrenceof312 suchthatatleastonevalue ofthe interval
[
aj,
ak] does not appearin a. More-over, we say that aiajak is an occurrence of the pattern 213 ifitisanoccurrenceof213 suchthatai=
ak−
1.3 By interpreting Theorem 7 in terms of partial permutations, weobtaineasily:Theorem8.Apermutation
π
is(
123,
312)
-sortableifandonly ifα
(
π
)
avoids31|
2 and213.Let
A
n(
31|
2,
213)
bethesetofpartialpermutationsof n avoidingthetwopatterns31|
2 and213,andA
n(
213)
be theset ofpartialpermutationsofn avoidingtheclassical pattern213.Theorem 9.For any n
≥
1, there is a bijectionφ
betweenA
n(
31|
2,
213)
andA
n(
213)
.Proof. Letusdefinerecursivelythemap
φ
fromA
n(
31|
2,
213
)
toA
n(
213)
. Ifπ
= λ
, then we setφ (
π
)
= λ
. Oth-erwise,π
has a unique decomposition of the formπ
=
Amin(
π
)
B where A and B are disjoint partial permuta-tionsofn.Wedistinguishthreecases:(i) IfatleastoneofA orB isempty,thenweset
φ (
π
)
=
φ (
A)
min(
π
)φ (
B)
;(ii) Ifboth A andB arenotemptyandmin
(
A)
>
max(
B)
, then we setφ (
π
)
= φ(
A)
min(
π
)φ (
B)
. It is worth notingthatthehypothesisthatπ
avoids31|
2 implies thatanyvaluex∈ [
min(
π
),
max(
B)
]
occursin B.(iii) Suppose that both A and B are not empty and
min
(
A)
<
max(
B)
. Sinceπ
avoids 213, there exists x∈ [
min(
A),
max(
B)
]
such that x does not occur inπ
. We choose the smallest x with this property, so thatanyvalueoftheinterval[
min(
A),
x]
occursin A. Moreover, sinceπ
avoids31|
2,itmustbe max(
A)
=
x−
1.AnillustrationofthiscaseisdepictedinFig.1. Letr bethemaximumvalue of B thatislowerthan min(
A)
andconsider the string B obtained from B by decreasingby x−
r−
1 allentriesgreater than x. Similarly,let A beobtainedfrom A by increasingby max(
B)
−
x+
1 allits entries. Obviously, A and B belong toA
n(
31|
2,
213)
, whereasπ
=
A min(
π
)
B contains31|
2.Thenwesetφ (
π
)
= φ(
A)
min(
π
)φ (
B)
(see againFig. 1foran illustrationofthismapping). Itisworthnotingthatthevaluer+
1 doesnotoccur in both A and B , which implies that there exists y∈ [
min(
π
),
r+
1]
such that y does not occur inφ (
B)
.Next we prove that
φ
is an injective map. We pro-ceedby induction on the length of partial permutations. Letπ
be a partial permutation. Due to the remarks at the end of (ii) and (iii), the image ofπ
underφ
satis-fying(ii) is apartial permutationπ
such that anyvalue x∈ [
min(
π
),
max(φ (
B))
]
occursinφ (
B)
,whichisnottrue for a permutationπ
satisfying (iii). Then, for two non-empty partial permutationsπ
andσ
inA
n(
31|
2,
213)
,3 Thisisanalogoustothenotionofbivincularpatternonclassical per-mutations.