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 rt i c l e i nf o a b s t ra 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.Theyconsistoftwore- strictedstacksinseries,equippedwitharight-greedypro- 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 Catalannum- bers.Forspecificpatterns,suchas123 andthedecreasing patternofanylength,ageometricaldescriptionofsortable
*
Correspondingauthor.E-mailaddresses:[email protected](J.-L. Baril),
giulio.cerbai@unifi.it(G. Cerbai),[email protected](C. Khalil), [email protected](V. Vajnovszki).
1 G.C. is member of the INdAM Research group GNCS; he is par- tiallysupportedbyINdAM-GNCS2020project“Combinatoriadelleper- mutazioni,delleparolee deigrafi:algoritmie applicazioni”.
permutationsis also obtained. The pattern132 has been solvedlaterin [8].Someoftheseresultshavebeenfurther generalizedto Cayley permutations in [9]. More recently, Berlow [5] exploresasinglestackversionofpatternavoid- 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.1061380020-0190/©2021PublishedbyElsevierB.V.
lannumbers.Thisresultwasconjecturedin [3] andsettled independently in [4,5]. Forthe pair
(
123,
132)
, we prove thatsortablepermutationsarethoseavoidingthepatterns 2314, 3214,4213 and the generalizedpattern[
2413.¯
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 resultsprevi- 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 ofpermuta- tions oflengthn andlet S
= ∪
n≥0Sn.Giventwopermu- tationsσ
oflengthkandπ = π
1· · · π
n,wesaythatπ
con- tainsthepatternσ
ifπ
containsasubsequenceπ
i1· · · π
ik, withi1<
i2< · · · <
ik,whichisorderisomorphictoσ
.In thiscase,wesaythatπ
i1· · · π
ikisanoccurrenceofthepat- 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 pattern wheresomeentriesarebarred.Letσ
betheclassicalpat- 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[
2413 if¯
foranysubse- 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 Avn
(
T)
the setofpermutationsin Sn avoiding eachpat- terninT.Similarly,letAv(T) = ∪
n≥0Avn(
T)
.IfT= { σ }
is asingleton,wewriteAvn( σ )
andAv(σ )
.Inhiscelebrated book [13], Knuth gave the following characterization of stacksortablepermutations,whichisoftenconsideredthe starting point of stack sorting and permutation patterns disciplines.Proposition1([13]).Apermutation
π
issortableusingaclas- 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 npermutationsthat 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-sortable permutationsofanylength.As aconse- 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 whichis12- sortable,thenout12( π )
isthedecreasingrearrangementofthe symbolsofπ
.Moreover,π
is12-sortableifandonlyifitavoids 213.An entry
π
i ofa permutationπ
isa left-to-rightmin- imum ifπ
i< π
j, for each j<
i. The left-to-rightminima decomposition (briefly ltr-mindecomposition) ofπ
isπ =
m1B1m2B2
· · ·
mtBt,wherem1>
m2> · · · >
mt aretheltr- 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-maxdecompositionofπ
isπ =
M1B1M2B2· · ·
MtBt,where M1<
M2< · · · <
Mt are theltr-maximaofπ
.In thiscase Mt=
n, wheren is thelengthofπ
.Finally,thesequence
(
cn)
n≥0,pervasiveinthispaper,is thesequenceofCatalannumberscn=
n+112nn
(A000108 in [15]).
3. Pair(132,231)
Thissectionisdevotedtotheanalysisofthe
(
123,
231)
- machine.Theorem1.Considerthe
(
132, σ )
-machine,whereσ = σ
1· · · σ
k−1σ
k∈
Sk,withk≥
3andσ
k−1> σ
k.Givenapermutationπ
oflengthn,letm1B1· · ·
mtBt= π
beitsltr-mindecomposi- tion.Then:1. Everytimealtr-minimummiispushedintothe
(
132, σ )
- stack,the(
132, σ )
-stackcontainstheelementsmi−1, . . . ,
m2,
m1,readingfromtoptobottom.Moreover,wehave out132,σ( π ) = ˜
B1· · · ˜
Btmt· · ·
m1,
whereB
˜
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 until theendofthe process.Now,if B1 is notempty then foreach x∈
B1,the elements m2xm1 form an occur- rence of132.Therefore theblock B1 is extractedbe- forem2 entersthe(
132, σ )
-stack.After m2 ispushed, the(
132, σ )
-stackcontainsm2m1,readingfromtopto bottom. Sincem2<
m1,butσ
k−1> σ
k by hypothesis, m2 cannot play the role of eitherσ
k−1 in an occur- rence ofσ
orof 3 in anoccurrenceof 132.Thusm2 remains atthebottomofthe(
132, σ )
-stack untilthe endofthesortingprocedure.Thethesisfollowsbyit- 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) B˜
i=
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 from top 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 isthe 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 theele- mentx∈
Bi.Thismeansthatthe(
132,
231)
-stackcontains two elements z,
w,withz above w,such that yzw is an occurrence of either 132 or231. Note that, since z>
w, z isnot a ltr-minimum. Therefore yz isan 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-mindecomposi- tionofapermutationπ
.Thenthefollowingareequivalent.1. Biavoids213andBi
>
Bi+1,foreachi.2.
π
is(
132,
231)
-sortable.3.
π ∈
Av(1324,
2314)
.Proof. Combining the firstpoint in Theorem 1andLem- 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 anoccurrencebcaof231.Notethat,since c>
a, while mt< · · · <
m1, c is not a ltr-minimum ofπ
(and thusneitherisb).Now,ifbandcareinthesameblockBj, 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,
darenotltr-minimaofπ
.Now, ifbanddareinthesameblock Bj ofπ
,forsome j,then Bj containsanoccurrencecbdof213.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π
containstwoel- 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],theauthorsprovideaconstructivebijectionbe- 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( σ , τ )
-stackasanopera- 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 on S if andonly ifτ = ˆ σ
. More generally, Berlow [5] showed that foraset T ofpatterns, outT isalengthpreservingbijectiononSifandonlyifT isclosed under the
ˆ
operator. In order for the paper to be self- contained,weshallgivethefollowingresult,whichiseas- ier to prove (although weaker): outσ,σˆ is a bijection for any patternσ
. An immediateconsequence will be Theo- rem2below.LetN∗bethesetoffinitelengthintegersequences.The actionofthe
( σ , τ )
-stackoninputπ
canbenaturallyrep- resentedasasequenceoftriples(
r;
s;
t) ∈ (
N∗)
3,wherer isthecurrentcontentoftheoutput,s isthecurrentcon- tent of the( σ , τ )
-stack (read fromtop to bottom) andt is the current content of the input. The triple(
r;
s;
t)
is saidtobea stateofpassingofπ
throughthe( σ , τ )
-stack.Clearly,risaprefixofoutσ,τ
( π )
,tisasuffixofπ
,theini- 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∈
Nn, we denote by pr the reverse of p, that is pr=
pn· · ·
p1. We wish to show that the behavior of the( σ , σ ˆ )
-stack onπ
is strictly related to its behavior on
outσ,σˆ
( π )
r.More precisely, ifo1
· · ·
o2n is the sequence ofpush/pop operationsperformed whenπ
is passed through a( σ , σ ˆ )
-stack, then o2n· · ·
o1 is the sequence of push/pop operations performed whenoutσ,σˆ
( π )
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)
(andthusapushopera- 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 isthe content ofthe
( σ , σ ˆ )
-stack in the state(
p,
xs,
t)
, we have that xs avoidsσ
andσ ˆ
. Thusapushoperationisperformedifsisthecontent of the( σ , σ ˆ )
-stack and x isthe next element of the input.2. If pisempty,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 the followingfourcaseshold.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σ ˆ
andthereforeapopoperationisper- formed when pa is the next element of the input andxsisthecontentofthe( σ , σ ˆ )
-stack,asdesired.•
spasi3· · ·
siz is an occurrenceofσ ˆ
,forsome≥
1 and<
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 anypermuta- tionπ
,wehave
outσ,σˆ−1
( π ) =
outσ,σˆ
( π
r)
r.Since
π
is
( σ , σ ˆ )
-sortableifandonlyifoutσ,σˆ( π )
avoids231 (and thereversemapisbijective),wehavethatSort( σ , σ ˆ )
isin bijectionwithAv(231)
.Thenexttheoremfollows.Theorem2.Foranypattern
σ
,outσ,σˆn 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)
-sortablepermu- tationsareenumeratedbytheCatalannumbersbyexhibit- ingalinkwiththeverywellstudiedCatalantriangle.Theorem3.Apermutation
π
is(
123,
132)
-sortableifandonly ifπ
avoids2314,3214,4213and[
2413.¯
Proof. Supposethat
π
is(
123,
132)
-sortable.Foracontra- diction, suppose thatπ
containsτ ∈ {
2314,
3214,
4213}
. Pick an occurrenceπ
iπ
jπ
kπ
ofτ
, with i<
j<
k<
, whereischosenminimal,andk, j,andi arechosenmax- 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)
-stackwouldcon- 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 in the(
123,
132)
-stack. (i) Assumethatπ
i andπ
j bothhad left the(
123,
132)
-stack. Thenπ
k is just belowπ
k+1 in the(
123,
132)
-stack,andπ
k< π
j< π
k+1.Thisimpliesthatπ
jπ
k+1π
k isanoccurrenceof231 in out123,132( π )
,acon- tradiction. (ii) Assume thatπ
i is still in the(
123,
132)
- stackandπ
jhadleftthisstack.Again,π
jπ
k+1π
kisanoc- currence of231 inout123,132( π )
,a contradiction.(iii) As- sumethatπ
jisstillinthe(
123,
132)
-stackandπ
ihadleft thisstack.Sinceπ
u< π
u+1fork≤
u≤ −
1,thenextsteps oftheprocesspushsuccessivelyallentriesπ
k+1, . . . , π
in the(
123,
132)
-stack.Asabove,π
iπ
π
k isanoccurrenceof 231 inout123,132( π )
,againacontradiction.Thecase
τ =
4213 canbetreatedsimilarly.Finally, suppose that
π
contains[
2413.¯
Equivalently, thereare twoindicesi<
j such thatπ
1π
iπ
j isan occur- renceof132 andπ
k> π
1foreachi<
k<
j.Observethat, by choosing j minimal andi maximal(in thisorder), we canassume j=
i+
1.Now,ifπ
i isstillinthe(
123,
132)
- stack whenπ
i+1 enters, then out123,132( π )
contains an occurrenceπ
i+1π
iπ
1 of 231,which is impossibledue to thesortability ofπ
.Thereforeπ
i isextractedbeforeπ
i+1 enters. Thismeansthat thereare twoelementsπ
u, π
v in the(
123,
132)
-stack, withu<
v (andthusπ
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π
1is anoccurrenceof231 inout123,132( π )
,acontradiction.Conversely, suppose that
π
is not(
123,
132)
-sortable.Weshallprovethat
π
containsatleastoneofthepatterns 3214, 2314, 4213 or[
2413.¯
By hypothesis out123,132( π )
contains anoccurrencebcaof231.Letb= π
j andc= π
k, forsomeindices j,
k.Wedistinguishtwo cases,according whether j<
kor j>
k.•
Supposethat j<
k andthusπ
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 occurrenceoftheforbidden 132 insidethe(
123,
132)
-stack.Moreover,foreachen- 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[
2413.¯
Thiscompletestheproof.Proposition3.ThedistributionofthefirstelementinSort
(
123,
132)
is given by the Catalan triangle (sequence A009766 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 does notaffecttheavoidanceofthethreepatterns3214,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)
.Letusnow sketchtheproofthatβ
isbijective,leavingsometechnical detailstothereader.Weshallexplicitlydefinetheinverse map ofβ
. Givenπ ∈
An−1(
k)
,choose anintegerasfol- 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
π
isobtainedbyinsertingimmediatelybe- fore
π
i=
k−
1 andthen increasingbyone alltheentriesπ
j ofπ
withπ
j≥
.Finally,settingakn