Flip-sort and combinatorial aspects of pop-stack sorting

Flip-sort is a natural sorting procedure which raises fascinating combinatorial questions. It finds its roots in the seminal work of Knuth on stack-based sorting algorithms and leads to many links with permutation patterns. We present several structural, enumerative, and algorithmic results on permutations that need few (resp. many) iterations of this procedure to be sorted. In particular, we give the shape of the permutations after one iteration, and characterize several families of permutations related to the best and worst cases of flip-sort. En passant, we also give some links between pop-stack sorting, automata, and lattice paths, and introduce several tactics of bijective proofs which have their own interest.


Flip-sort and pop-stack sorting
Sorting algorithms are addressing one of the most fundamental tasks in computer science, and, accordingly, have been intensively studied. This is well illustrated by the third volume of Knuth's Art of Computer Programming [24], which tackles many questions related to the worst/best/average case behaviour of sorting algorithms, and gives many examples of links between these questions and the combinatorial structures hidden behind permutations (see also [12,Chapter 8.2] and [29]). For example, in [23,Sec. 2.2.1], Knuth considers the model of permutations sortable by one stack (neatly illustrated by a sequence of n wagons on a railway line, with a side track that can be used for permuting wagons) and show that they are characterized as 231-avoiding permutations: this result is a cornerstone of the field of permutation patterns. Since that time, many results were also obtained e.g. on permutations sortable with 2 stacks, which offer many nice links with the world of planar maps [17,33]. The analysis of sorting with 3 stacks remains an open problem (see [16] for some recent investigations). Numerous variants were considered (stacks in series, in parallel, etc.). Our article pursues this tradition by dealing with the combinatorial aspects of the flip-sort algorithm, a procedure for sorting permutations via a pop-stack (as considered in [7,8]), which we now detail. We use the following notation. Permutations will be written in one-line notation, π = a 1 a 2 . . . a n . An ascent (resp. descent) is a gap between two neighbouring positions, i and i + 1, such that a i < a i+1 (resp. a i > a i+1 ). Descents of π split it into runs (maximal ascending strings), and ascents split it into falls (maximal descending strings). For example, the permutation 3276145 splits into runs as 3|27|6|145, and into falls as 32|761|4|5.
Flip-sort consists of iterating flips on the input permutation, where flip is the transformation T that reverses all the falls of a permutation. For example, T(3276145) = 2316745. If one applies T repeatedly (thus obtaining T(π), T 2 (π), . . .), then one eventually obtains the identity permutation id. For example: 3276145 → 2316745 → 2136475 → 1234657 → 1234567; see Figure 1 for a visualization of this example by means of permutation diagrams. Nota bene: if one does not impose the stack to contain increasing values, then the process can be related to the famous pancake sorting problem (see [20]).

Summary of our results
The article is organized as follows.
In Section 2, we study the permutations that belong to Im(T), the image of the flip transformation. We find a structural characterization of such permutations, and we prove that the generating function of these permutations is rational when the number of runs is fixed. We then use a generating tree approach to design some efficient algorithms enumerating such permutations. We also show that their generating function satisfies a curious functional equation, and we give an asymptotic bound. Section 3 is dedicated to permutations with low cost. A permutation π is k-pop-stack-sortable if cost(π) ≤ k, or, equivalently, T k (π) = id. Avis and Newborn showed that 1-pop-stacksortable are precisely the layered permutations [8], while k-pop-stack-sortable permutations are recognizable by an automaton (see Claesson and Guðmundsson [14]). For k = 2, Pudwell and Smith [28] listed some conjectures that we prove via a bijection between 2-pop-stack-sortable permutations to a family of lattice paths.
In contrast, in Section 4, we deal with permutations with high cost, and with Im(T m ) for arbitrary m. Our main result is a (tight) bound on bandwidth of τ ∈ Im(T m ), which provides a partial explanation of the phenomena that we observe in Figure 3. Additionally, we find a full characterization of Im(T n−2 ), and some conditions for cost(τ) = n − 1. We conclude with a conjecture concerning the cost of skew-layered permutations. The pop-stack-sorting tree for n = 5. Flipping the falls in each permutation leads to its successor until one reaches the identity permutation. The leftmost column thus corresponds to the worst cases of this procedure. In this figure, we also mark three sets considered in this article: 1-and 2-pop-stack-sortable permutations, and Im(T n−2 ). Additionally, Im(T ) consists of all internal nodes.
Flip-sort and combinatorial aspects of pop-stack sorting 5 Fig. 3: The evolution of the flip-sort algorithm on a sample permutation of size n = 1200. In this article, we show that for any input permutation there are two areas (the grey areas in the above plots, which are proportional to the number m of iterations) without any dots inside. This entails that the permutations "shrink" (in the white area) until they finally get fully sorted (after ≤ n − 1 iterations). We also show that, for all m, for any coordinates in the white area, there exists an input permutation which will have a dot at these coordinates. (See lipn.fr/~cb/Papers/popstack.html for some animations of this flip-sort process.) 2 Results concerning one iteration of the flip-sort algorithm

Structural characterization of pop-stacked permutations
We start this section with a characterization of the image of T, i.e. the internal nodes in the pop-stack tree from Figure 2.

Definition 1.
A permutation τ is pop-stacked if it belongs to Im(T), that is, if there is a permutation π such that we have τ = T(π).
We begin our investigations of the image of T by giving a characterization of the permutations in Im(T) in terms of overlapping runs. In fact, in the following theorem we prove that a permutation is pop-stacked if and only if all pairs of adjacent runs are overlapping. See Figure 4 for a schematic drawing that represents the structure of permutations with overlapping adjacent runs, and an example. Despite its very natural definition, this family of permutations was, to the best of our knowledge, never studied before our initial conference contributions [4,5].

Proof:
[First part of the proof: pop-stacked ⇒ overlapping runs.] Let τ = b 1 b 2 . . . b n be a permutation with min(R i ) > max(R i+1 ) for some pair (R i , R i+1 ) of its adjacent runs. Let b α be the last letter in R i and b α+1 be the first letter in R i+1 (that is, Assume for contradiction that we have τ = T(π) for some permutation π = a 1 a 2 . . . a n . In π, we have a α < a α+1 because otherwise the string [a α a α+1 ] is a part of a fall in π, and upon applying T we have b α < b α+1 , which is impossible, because b α and b α+1 lie in different runs of τ. Therefore, if we consider the partition of π into falls, then a α is the last letter of some fall F j , and a α+1 is the first letter of the next fall F j+1 . However, the values of F j are a subset of those of R i , and the values of F j+1 are a subset of those of R i+1 . Therefore we have a α > a α+1 , which is a contradiction to a α < a α+1 observed above.
[Second part of the proof: overlapping runs ⇒ pop-stacked.] Consider a permutation τ with min(R i ) < max(R i+1 ) for all pairs (R i , R i+1 ) of adjacent runs. Let π be the permutation obtained from τ by reversal of all its runs. Then the partition of π into falls is the same as the partition of τ into runs, and, therefore, π is a (not necessarily unique) pre-image of τ. to the On-Line Encyclopedia of Integer Sequences. While it is hard to compute more terms directly, the introduction of additional parameters provides further insights. Specifically, in this section we consider the number of runs in pop-stacked permutations. In particular, we show that for each fixed k, the generating function for pop-stacked permutations of size n with exactly k runs is rational.
Let p n,k denote the number of pop-stacked permutations of size n with exactly k runs. The case k = 1 is trivial: for any size, the only permutation with only one run is the identity permutation, and it is pop-stacked as it is e.g. the image of itself. Thus, we have p n,1 = 1 for each n ≥ 1. Note that, for k > 1, p n,k is always an even number (indeed, listing the runs from the last one to the first one gives an involution without fixed points among pop-stacked permutations), therefore p n is always an odd number.
One key ingredient of our further results is the following encoding of permutations, which we call scanline mapping. Let π be a permutation with k runs. Let r i be the index of the run in which the letter i lies. Consider the word w(π) = r π −1 (1) r π −1 (2) . . . r π −1 (n) ∈ {1, . . . , k} n . Visually, we scan the graph of π from the bottom to the top, and for each point that we encounter in this order, we record to which run it belongs; see Figure 5.  1. The positions of i (1 ≤ i ≤ k) in w(π) are the values in the ith run of π. Thus, π is reconstructed from w(π) uniquely.
2. If (and only if) for some j, all the occurrences of j in w(π) are before the occurrences of j + 1, then the corresponding positions of π do not form two distinct runs and thus we do not get a permutation with k runs.
3. If (and only if) for some j, all the occurrences of j + 1 in w(π) are before the occurrences of j, then all the values in the jth run of π are larger than all the values in the (j + 1)st run, and thus these runs are not overlapping.
Proposition 4 can be used to obtain a formula for the case of two runs directly: Proposition 5. For n ≥ 1, the number of pop-stacked permutations of size n with exactly two runs, is p n,2 = 2 n − 2n. Proof: By Proposition 4, p n,2 is the number of words in {1, 2} n with an occurrence of 1 before an occurrence of 2, and also an occurrence of 2 before an occurrence of 1. There are 2n words that violate this condition (including the "all-1" and the "all-2" words).
It is pleasant to have a combinatorial explanation for the number of pop-stacked permutations with two runs, and this game could be pursued (algorithmically) for a fixed number of runs k, but to get a closed-form formula holding for any arbitrary number of runs is still open. While the following theorem does not give an explicit formula for all of those cases immediately, it proves that the counting sequence for pop-stacked permutations with precisely k runs is nice and simple from a structural point of view. Theorem 6. Let k ≥ 1 be fixed. Then P k (z) := ∑ n≥1 p n,k z n , the generating function for the number of pop-stacked permutations with exactly k runs, is rational.

Proof:
It is well known that the generating function of words recognized by an automaton is rational (see e.g. [18,Sec. I.4.2]). We use Proposition 4 to construct a deterministic automaton A k over the alphabet {1, . . . , k} that precisely recognizes the words w(π) that correspond to the pop-stacked permutations. The states of A k are labelled by pairs (L, C), where • L ⊆ {1, . . . , k} indicates the already visited letters, and • C ⊆ k−1 j=1 {(j, j + 1), (j + 1, j)} indicates the already fulfilled conditions "there is an occurrence of j before an occurrence of j + 1" resp. "there is an occurrence of j + 1 before an occurrence of j", such that • if j, j + 1 ∈ L, then at least one of (j, j + 1) and (j + 1, j) belongs to C.
It is then straightforward to see that A k precisely recognizes those words in {1, 2, . . . , k} n that correspond bijectively to the pop-stacked permutations of size n with k runs by Proposition 4. Figure 6 shows such an automaton for k = 3.
Flip-sort and combinatorial aspects of pop-stack sorting   In the next theorem, we address the complexity of A k : its number of states grows roughly as 3.41 k . This exponential growth of the number of states also gives an insight on the complexity of the generating functions associated to these automata.

Proof:
We proceed by induction on k (starting at k ≥ 3). Denote by Q k the set of states of the automaton A k defined in the proof of Theorem 6. Recall that the states are labelled by (L, C), where L is the set of already encountered letters, and C is the list of already fulfilled conditions of the kind (j, j + 1) or (j + 1, j). We partition the states of A k into three parts as follows.
1. The states of A k whose letters do not contain k: they are precisely all the states of A k−1 .
2. The states of A k whose letters contain k but do not contain k − 1. They correspond bijectively to the states of A k−1 whose letters do not contain k − 1, and thus to all the states of A k−2 : where k − 1 ∈ L.
3. Finally, the states of A k whose letters contain both k and k − 1. They correspond (3 : 1)bijectively to the states of A k−1 whose letters contain k − 1: where k − 1 ∈ L.
Therefore, summing over these three cases, we have which completes the proof.
Remark: Upon performing minimization on A k , we obtain automata with the number of states given by (b k ) k≥1 = (2, 6, 16, 40, 98, . . . ). This leads us to conjecture that this sequence satisfies the linear recurrence b k = 3b k−1 − b k−2 − b k−3 , and that it is in fact A293004 (iii) . Possibly, this could be proved by following the impact of each step of Brzozowski's algorithm for minimizing an automaton, see [13]. It is interesting to notice that the exponential growth of the number of states would then drop from a k = Θ((2 + Before we continue with our investigations towards efficient computation of the numbers p n,k , we want to make some observations concerning the particular shape of the rational generating functions P k (z). Recall that Theorem 6 provides a construction for a deterministic finite automaton that recognizes pop-stacked permutations of length n. Given such an automaton, the associated generating function can be extracted in a straightforward way. Doing so for 1 ≤ k ≤ 5 yields the rational functions , , Some further functions can still be computed in reasonable time. However, as the number of states in the automaton grows exponentially in k, this approach is not feasible for large values of k.
(iii) The goddess of combinatorics is thumbing her nose at us, as this sequence is also related to permutation patterns in many ways: it counts permutations related to the elevator problem [24, 5.4 Note that the lowest degree in the numerator is 3k/2 . This is because the smallest possible permutation size for a pop-stacked permutation with k runs can only be obtained by alternating runs of lengths 1 and 2. It is even possible to (experimentally) observe further structure in these P k , for example they have the following partial fraction decomposition: where N k,j is a polynomial of degree j in z and 2j in k: We listed the first few values of these polynomial N k,j in case that some clever mind could find the general pattern for any j. We failed to find a generic closed-form formula, but it is noteworthy that the decomposition of Formula (4) has some similarities with the partial fraction decomposition of Eulerian numbers. Proposition 8. Consider the Eulerian numbers n k , defined as the number of permutations of size n that have precisely k runs (iv) . The generating functions E k (z) for the columns of the Eulerian number triangle have the following partial fraction decomposition (iv) Sometimes, Eulerian numbers are defined such that n k enumerates all permutations of size n that have k descents. Both cases (counting with respect to runs vs. counting with respect to descents) can be obtained from each other by shifting k by one.

Proof:
We were surprised to find no trace of this nice formula in the literature, so we now give a short proof of it. First, inserting n + 1 into a permutation of size n with k runs either enlarges one of the runs if n + 1 is inserted at its end, or it creates a new run in all other cases; this gives the classical recurrence From it, it is easy to get by induction that We refer to [19,26] for possible alternative proofs and thorough surveys on Eulerian numbers. Then, rewriting the Eulerian numbers in E k (z) by means of this formula and carrying out some algebraic manipulations yields This proves the partial fraction decomposition.
The partial fraction decomposition (5) allows us to make statements about the structure of E k (z). We now list several of these properties, comparing them with our observations for the generating functions P k (z).
• The degree of the numerator of E k (z) is ( k+1 2 ) − 1, and for P k (z) we conjecture it to be ( k+1 2 ). • The leading coefficient in the numerator of E k (z) is ± 1 k ∏ k m=1 m! (only the first summand in (5) contributes towards the maximum degree), and for P k (z) we conjecture it to be ± ∏ k m=1 m!.
• For E k (z), summing the coefficients in the numerator yields ± ∏ k−1 m=1 m! (setting z = 1 in the numerator of E k (z) only collects contributions from the last summand in (5)), for P k (z) we conjecture that it is ±2 ∏ k−1 m=1 m!. While we think that it is unlikely that the sequence p n,k satisfies a simple linear recurrence relation as in (6), we derive in the next section a useful, but more complex, recurrence scheme that depends on some additional parameters.
Flip-sort and combinatorial aspects of pop-stack sorting 13

A functional equation for pop-stacked permutations and the corresponding polynomial-time algorithm for the enumeration
As noted above, the counting sequence (p n ) n≥0 is hard to compute directly without introducing additional parameters. In [5], we mentioned that a generating tree approach leads to an efficient enumeration algorithm for pop-stacked permutations; it relies on an additional parameter which is either the number of runs, or the final value of the permutation. Such generating tree approaches lead to polynomial time algorithms for computing p n (see [9] for further examples of enumerations via generating tree approaches). When the additional parameter is the number of runs, this gives a recurrence which encodes the addition of a new run of length k to the end of a given permutation of size n (and relabels this concatenation to get a permutation of size n + k). The cost of this approach is analysed in [15], and was implemented with care on a computer cluster, allowing the computation of the number of pop-stacked permutations of size n, for all n ≤ 1000.
When the additional parameter is the final value of the permutation, this gives an approach that we now detail in this section. Based on a generation strategy where either one or two elements are added to a given permutation, we consider the corresponding generating tree. With this strategy, we can derive an appropriate recurrence which also allows us to compute the sequence in polynomial time, and also offers a functional equation for the corresponding multivariate generating function.
For this generation strategy, we need to keep track of a few additional parameters in popstacked permutations. Let n, k, a, b, c be non-negative integers such that k ≤ n and 1 ≤ a ≤ b ≤ c ≤ n. Let the set P n,k;a,b,c denote all pop-stacked permutations where • n denotes the length of the permutation, • k denotes the number of runs, • a and c denote the smallest and largest element of the last run, respectively, • if a < c, then b denotes the second-largest element of the last run; else, if a = c, then also b := a = c.
(Rule 1) A new run consisting of a single element is added to the end of all generated permutations. For all integers i with a + 1 ≤ i ≤ c, this operation corresponds to an injection P n,k;a,b,c → P n+1,k+1;i,i,i . (Rule 2) A new run consisting of two elements is added to the end of all generated permutations.
For all integers i < j with 1 ≤ i ≤ c and a + 2 ≤ j ≤ n + 2, this corresponds to an injection P n,k;a,b,c → P n+2,k+1;i,i,j . (Rule 3) Insert a new second-largest element into the last run of all generated permutations.
For all integers i with b + 1 ≤ i ≤ c, this corresponds to the injection P n,k;a,b,c → P n+1,k;a,i,c+1 .
Proof: In order to see that all permutations are generated by this strategy we study the corresponding inverse operation. Given a pop-stacked permutation σ of length n that is different from 1 or 12, we consider its last run. Then we carry out the following operations, based on the length of the final run: • If the last run is of length 1 or 2, then one deletes it. This reverses (Rule 1) and (Rule 2).
• Otherwise, if the run is of length at least 3, the second-largest (and therefore penultimate) element is deleted. This is the reversal of (Rule 3).
After proper relabelling, this results in a shorter permutationσ that is still pop-stacked. Applying the appropriate expansion rule toσ constructs a set of "successors" also containing σ. Observe that by the nature of the expansion rules, only pop-stacked permutations can be generated (as long as we start with a pop-stacked permutation) as it is made sure that the last and the penultimate run always overlap. This proves that for every permutation (apart from 1 and 12) a unique predecessor in the generating tree can be found. The permutations 1 and 12 are special in the sense that they are the only permutations for which the above strategy does not yield a well-defined result. At the same time, this implies that when starting at any other permutation σ and iterating the procedure of finding the predecessor eventually leads to either 1 or 12. This proves that when starting with these permutations (in our notation, this corresponds to the sets P 1,1;1,1,1 and P 2,1;1,1,2 ), all other pop-stacked permutations can be generated by applying (Rule 1), (Rule 2), and (Rule 3) iteratively. Now, let us turn our focus from generating these permutations to their enumeration. Let p n,k;a,b,c := |P n,k;a,b,c |, the number of pop-stacked permutations in P n,k;a,b,c . With the notation from Section 2.2, we have p n,k = ∑ a,b,c≥0 p n,k;a,b,c and The generating tree approach can be utilized to derive a functional equation for the associated multivariate generating function as well as a recurrence scheme the numbers p n,k;a,b,c . We begin with the functional equation for P(z, u, v 1 , v 2 , v 3 ), which is proved by translating the expansion rules from above to the level of algebraic operations on generating functions. Theorem 10. The multivariate generating function P(z, u, v 1 , v 2 , v 3 ) as given in (7) satisfies the functional equation Proof: This functional equation is just the reflection of the fact that any pop-stacked permutation is either empty, or one of the two roots of the generating tree, namely 1 (encoded in (8) , or a permutation obtained by applying one the three expansions rules to a smaller pop-stacked permutation. Now, each of the four remaining summands in the right-hand side of (8) can be explained by considering that each of the expansion rules acts as a linear operator on the monomials z n u k v a 1 v b 2 v c 3 of the generating function P. While the corresponding calculations are not too difficult, they can be a bit tedious -which is why we choose to illustrate it for one of the rules, and give only the results for the remaining ones.
Let us first consider (Rule 3), which describes the injection P n,k;a,b,c → P n+1,k;a,i,c+1 for b + 1 ≤ i ≤ c. Starting from a given permutation whose associated monomial is z n u k v a 1 v b 2 v c 3 , this rule generates longer permutations by inserting a new second-largest element into the last run. On the level of monomials, this corresponds to the map As this operator is linear, its application to the generating function P (seen as sum of monomials) leads to a sum which can itself also be written in terms of P; this yields a total contribution of Similarly, (Rule 1) yields a total contribution corresponding to the summand and (Rule 2) yields the two remaining summands on the right-hand side of (8). 16

Andrei Asinowski, Cyril Banderier, Benjamin Hackl
This allows us to obtain a recurrence relation for p n,k;a,b,c as given in the following theorem. Therein, for the sake of simplicity, we make use of the Iverson bracket [expr], a notation popularized in [22], which evaluates to 1 if expr is a true expression, and 0 otherwise.
The number of pop-stacked permutations of length n with k runs is thus and the number of pop-stacked permutations of length n is thus p n = ∑ n k=1 p n,k , which can be computed with ∼ n 4 /8 time-complexity and ∼ n 3 /3 memory-complexity.

Proof:
We can either go back to the combinatorial description of the generation of permutations via the generating tree approach, or consider the functional equation (8) and extract the coefficient of the monomial z N u K v A 1 v B 2 v C 3 on both sides in order to obtain the recurrence relation (9) for p n,k;a,b,c . Now, for the complexity analysis, observe that the triple sums appearing in the first and second branch of (9) can be computed more efficiently by defining the auxiliary sequence Furthermore, observe that we can actually rewrite the third branch of the recurrence (9) (for A < B − 1 and B < C) as We are now able to rewrite the recurrence in the form This approach allows us to compute p n,k for 1 ≤ k ≤ n ≤ N in O(N 5 ) arithmetic operations. Furthermore, observe that the number of runs is actually not relevant in the recurrence. If we were only interested in p n , the number of pop-stacked permutations of length n, then we could drop this additional parameter: this allows us to compute p n for 1 ≤ n ≤ N in O(N 4 ) arithmetic operations, with O(N 3 ) simultaneous allocations in memory. Actually, we can be even more precise and obtain the main asymptotic term of the number of operations: In the computation of p n for 1 ≤ n ≤ N, the branches of the recurrence (12) are visited for all 1 ≤ A ≤ B ≤ C ≤ N. Investigating these branches more closely reveals that while the case of A = B = C is asymptotically negligible for the main term, both the case of A = B < C as well as A < B < C contribute ∼ N 4 /24 to the total number of additions required. Finally, adding all p n;A,B,C for 1 ≤ A ≤ B ≤ C and 1 ≤ n ≤ N, one gets ∼ N 4 /24 more additions -which means that in total the number of additions behaves like N 4 /8. Similar considerations show that this approach requires ∼ N 3 /3 simultaneous memory allocations.
A straightforward implementation of the optimized recurrence (12) in SageMath [31] that stores relevant intermediate results in cache memory makes it possible to compute the first 100 terms of the sequence p n on a standard desktop PC in less than 3 minutes. Figure 7 illustrates the number of additions carried out by our strategy and confirms our assertion regarding the main asymptotic term. However, unfortunately, neither the recurrence scheme nor the functional equation for the generating function yield sufficient leverage to carry out an exact analysis of the asymptotic behaviour of the sequence p n . In the following section, we provide a lower bound for the growth of p n and give pointers to experimental observations.

Asymptotics of pop-stacked permutations
In many cases, the growth of restricted families of permutations is much less than n!, and is just exponential: for example, by the Stanley-Wilf conjecture (proved by Marcus and Tardos [25]), this always holds for permutation classes defined by classical forbidden patterns. It is natural to ask whether this is the case for pop-stacked permutations. We now prove that they in fact grow much faster.
Theorem 12 (Superexponential growth of pop-stacked permutations). The asymptotic growth of the number of pop-stacked permutations is at least exp(n ln(n) − n ln(2) − n + o(n)).
Proof: We achieve this by constructing an explicit class of permutations, as follows. Assume that n is even, and consider any pair of permutations, π and τ, each of size n/2. Intertwine them as shown in Figure 8, i.e. consider the permutation σ of size n defined by It is easy to see that such σ is necessarily pop-stacked (it clearly satisfies the overlapping run condition from Theorem 3). Since the mapping (π, τ) → σ is injective, we conclude that we have at least ((n/2)!) 2 pop-stacked permutations of size n. Then, Stirling's approximation for the factorial leads to the theorem. Note that the fact that the above argument holds for even n only is not a restriction: by inserting n + 1 at the end of any pop-stacked permutation of length n, one obtains a new pop-stacked permutation of size n + 1; therefore the sequence p n is strictly increasing, and thus the Stirling bound given in the claim remains valid for odd n.
Due to the nature of the counting sequence and the fact that we have no appropriate representation of the associated generating function, an exact asymptotic analysis of the growth behaviour of the sequence remains a challenge. The above theorem gives a lower bound of .5 n n!, it is also possible to compare with André's alternating permutations to get a lower bound of .63 n n! (see e.g. [18, p. 5]). Note that the authors of [15] carried out an experimental analysis using automated fitting and differential approximation. Their analysis of the counting sequence led them to conjecture that the corresponding exponential generating function possesses an infinite number of singularities, thus implying non-D-finiteness. Ultimately, they conjecture that the asymptotic growth of the sequence p n counting pop-stacked permutations of size n is Flip-sort and combinatorial aspects of pop-stack sorting 19 3 Best cases of flip-sort: permutations with low cost

Notation and earlier work
Some of the earlier work on pop-stack sorting dealt with permutation with low cost. The following notation was introduced there.
1-and 2-pop-stack-sortable permutations are shown by the red and the blue frames in the pop-stack-sorting tree in Figure 2.
Several results concerning k-pop-stack-sortability are known: • Avis and Newborn [8] proved that a permutation is 1-pop-stack-sortable if and only if it is layered (v) .
• Pudwell and Smith [28] found a structural characterization of 2-pop-stack-sortable permutations, as well as a bijection between such permutations and polyominoes on a twisted cylinder of width 3 (see [3]). Moreover, they proved that the generating function for 2-pop-stack-sortable permutations is rational (we shall reprove their result below).
• Claesson and Guðmundsson [14] generalized the latter result showing that for each fixed k, the generating function for k-pop-stack-sortable permutations is rational.

The pre-images of 1-pop-stack-sortable permutations
We begin with a nice enumerative result in which the notion of 1-and 2-pop-stack-sortable permutations is combined with our notion of pop-stacked permutations. Specifically, it concerns those 1-pop-stack-sortable permutations that belong to the image of T (thus, corresponding to internal nodes in the right column before the identity in the pop-stack tree from Figure 2).

Theorem 14.
Pop-stack layered permutations have the following properties: 1. Let LI n be the set of pop-stacked layered permutations (or, equivalently, of 1-pop-stack-sortable permutations that belong to Im(T)) of size n. The generating function for (|LI n |) n≥1 is Consequently, this family is enumerated by "tribonacci numbers" (A000213).
2. Let τ ∈ LI n . All the permutations π such that T(π) = τ can be constructed by the following procedure: • Put primary bars at all descents of τ.
• Optionally, put secondary bars at some descents so that each primary bar has at least one neighbouring position without any bar. • Reverse all the blocks determined by the bars.
(v) A layered permutation is a direct sum of its falls, for example 321|654|87. See also Definition 16 below.

Proof:
1. Let τ be a layered permutation of size n. Partition it into falls. Refer to the first and the last falls as outer falls, to all other falls as inner falls. For n ≥ 3 it is easy to see that we have non-overlapping adjacent runs if and only if there is an outer fall of size ≥ 3 or an inner fall of size ≥ 4. For n = 2 the permutation 12 is pop-stacked, and the permutation 21 is not. It follows that for n ≥ 2 we have τ ∈ LI n if and only if it has at least two falls, the outer falls being of size 1 or 2, the inner falls of size 1 or 2 or 3. This implies the generating function (14). 2. As τ is obtained from π by reversing all its falls, π is obtained from τ by reversing its runs -possibly, further partitioned. That is, we must first partition τ into runs (by primary bars), then optionally further partition the runs (by secondary bars), then reverse all the blocks.
We need to prove the condition on secondary bars. Suppose a primary bar separates a descent b i |b i+1 (we have b i > b i+1 ). If we put bars at both adjacent gaps, |b i |b i+1 |, then we have the same values in positions i and i + 1 in π. However, this would be a descent, that is, a part of a fall in π, and it should be reversed when we apply T. Otherwise, both sub-runs (that from the left and that from the right of the primary bar) will yield, upon reversal, two distinct falls in π, that will recover these sub-runs when we apply T.

2-pop-stack-sortable permutations and lattice paths
In this section we extend some of the results by Pudwell and Smith [28]. Namely, we reprove one of their theorems and prove (a generalization of) one of their conjectures. All this is done via the uniform framework of lattice paths. By doing this, we not only construct a bijection between 2-pop-stack sortable permutations and lattice paths, but also benefit from the fact that the theory of lattice paths is well developed (see e.g. [10]), thus offering additional structural insight.
First, we reprove the theorem by Pudwell and Smith in a more combinatorial way. Then we construct a bijection between 2-pop-stack-sortable permutations and a certain family of lattice paths, which enables us to prove two of their conjectures.
Theorem 15. For n ≥ 1, 0 ≤ k ≤ n − 1, let a n,k be the number of 2-pop-stack-sortable permutations of size n with exactly k ascents.

(Pudwell and Smith [28], Thm. 2.5) Let A(x, y) be the bivariate generating function A(x, y) =
∑ a n,k x n y k . Then we have

Proof:
1. It is shown in [28, Lemma 2.1] that a permutation π is 2-pop-stack-sortable if and only if for each pair of its adjacent falls, F i and F i+1 , one has max(F i ) ≤ min(F i+1 ) + 1. (vi) Consider an ascent that separates two adjacent falls F i and F i+1 . We say that this ascent is regular if max(F i ) < min(F i+1 ), and twisted if max(F i ) = min(F i+1 ) + 1. An ascent can be twisted only when at least one of the falls F i or F i+1 is of size > 1 (equivalently, when at least one of the adjacent gaps is a descent).
As Pudwell and Smith show, 2-pop-stack-sortable permutations are bijectively encoded by sequences of their ascents and descents (we use a for ascents, d for descents), where for each a that has an adjacent d it is indicated whether this a is regular or twisted. We find it (vi) Notice that layered permutations are similarly characterized by max(F i ) = min(F i+1 ) − 1.
convenient to use instead lattice paths: we replace each a by the up-step U = (1, 1), d by the down-step D = (1, −1), and corner-adjacent U-steps (that is, U-steps which have at least one adjacent D-step) will be bicoloured: U-steps that correspond to a regular ascent will be coloured black, U-steps that correspond to a twisted ascent will be coloured red. In this way, we obtain a certain family of Dyck walks. The length of a walk is smaller by 1 than the size of the corresponding permutation, and the final altitude is #(a) − #(d). See Figure 10 for illustration. To enumerate such walks, we make use of the symbolic method (see [18, Chapter I]) to find a combinatorial specification for (non-coloured) Dyck walks in which corner-adjacent U-steps are marked by y: This leads to the following functional equation for the trivariate generating function W(t, u, y), where t is the variable for length, u for final altitude, y for occurrences of corner-adjacent U-steps: This yields the generating function and the bivariate generating function for those walks in which corner-adjacent U-steps are bicoloured, is Upon performing the transformation that corresponds to the way in which we rearranged the array of the coefficients, we obtain xW(x √ y, √ y, 2) = A(x, y). This completes the proof of part 1.
2. First, we find the generating function E(t, y) for excursions -that is, those walks that stay (weakly) above and terminate at the t-axis -in our model of Dyck walks with marked corner-adjacent U-steps. The functional equation for E(t, y) is which yields Therefore, the generating function for Dyck excursions with bicoloured corner-adjacent U-steps is (In fact, we have E(t, y) = 1 + t 2 y 1−t 2 M The "diagonal coefficients" a 2n+1,n = [x 2n+1 y n ] of A(x, y) correspond to coefficients [t 2n u 0 ] of W(t, u, 2). Therefore we look for the generating function B(t, y) for bridges -that is, those walks that terminate at the t-axis -in our model. It can be routinely found by residue analysis (extracting [u 0 ] in W(t, u, y)). However, we give a more structural proof. We decompose a bridge into an alternating sequence of excursions and anti-excursions (= rotated by 180 • excursions that stay weakly below the x-axis). Since we use only U and D steps, such a decomposition is unambiguous. Moreover, the generating function for anti-excursions is the same as for excursions. When we join excursions and anti-excursions, new corner-adjacent U-steps are never created. Therefore we have 24 Andrei Asinowski, Cyril Banderier, Benjamin Hackl and finally Notice that we can rewrite this as and the coefficients of 1/ √ 1 − 4x are well known to be central binomial coefficients. This directly leads to the first closed-form formula of Equation (17) for a 2n+1,n . The second equivalent closed-form formula is proved easily via closure properties from holonomy theory; see [27].
Finally, we consider generating functions W k (t, 2) for walks that terminate at fixed altitude k. For unmarked paths we have the classical decomposition W k (t) = B(t)(tE(t)) k . Taking care of corner-adjacent U-steps, we obtain, for k ≥ 0, which, upon due modification, yields (16).
These paths can also be used to obtain formulas (16) for diagonal-parallel arrays, and the computations are even easier because the bicolouration of some steps does not require considering their adjacent steps. This claim by Aigner and Ziegler is concerning an extremal problem in geometry which is in fact solved by understanding the worst cases of flip-sort! We refer to [1,Chapter 12] and [32] for more details on this geometric problem. In this section, we strongly extend these studies by proving structural and enumerative results concerning the evolution of permutations during the flip-sort process, focussing on permutations with worst costs. We start with some definitions, notation, and basic observations.

Definitions and notation
By id n we denote the identity permutation of size n, and by −id n we denote its reversal: id n = 12 . . . n, and −id n = n . . . 21. Definition 17 (k-shadows). Let π be a permutation of size n, and let k be a fixed number, 1 ≤ k ≤ n − 1. Let S := {1, . . . , k}, L := {k + 1, . . . , n} (S for small, L for large). The k-shadow of π is defined to be the {S, L}-word shadow k (π) obtained from π by replacing all the numbers from S by S, and all the numbers from L by L. When k is fixed, we shall usually omit the subscript and write just shadow(π). Example: for π = 6317524 we have shadow 3 (π) = LSSLLSL.
Remark: Since we show below that after the (n − 1)st row the paths stay in the same position (namely, the S j (π) in the position j, and the L j (π)-path in the position n + 1 − j), we draw k-wiring diagrams with only n rows, from the one corresponding to π to the one corresponding to T n−1 (π).
(vii) We refer to Permutation patterns: basic definitions and notation by David Bevan [11] for the definitions of direct sum and of skew sum. Fig. 11: The k-wiring diagram for π = 86231745 and k = 5.
In the following considerations, the k-wiring diagram of the permutation ρ k := (n − k, k) will play an important role. When k is fixed, we shall usually omit the subscript and write just ρ. It is easy to verify that shadow(ρ) = L n−k S k , and that for each m ≥ 0 the word shadow(T m+1 (ρ)) is obtained from shadow(T m (ρ)) by replacing each consecutive occurrence of LS by SL. This yields Accordingly, the k-wiring diagram of ρ has a very distinctive shape, with Sand L-paths typically consisting of three segments. This is illustrated in Figure 12 (since we later combine the k-wiring diagram of the fixed permutation ρ with that of an arbitrary permutation π, the Sand L-paths of ρ will be shown by thick pink and light-blue lines). Finally, we notice that, since the sets S and L are already sorted in ρ, all the values along S j (ρ) are j, and all the values along L j (ρ) are n + 1 − j, so that for ρ = (n − k, k) the k-wiring diagram coincides with the usual wiring diagram where paths connect occurrences of the same value.
Definition 19 (Poset of words). Assume 1 ≤ k ≤ n − 1. Let SL(k, n − k) be the set of words of length n with k occurrences of S and n − k occurrences of L. For λ, µ ∈ SL(k, n − k) we write λ µ if for each j, 1 ≤ j ≤ k, the position of the jth S in λ is weakly to the left from the position of the jth S in µ. Equivalently, λ µ if for each j, 1 ≤ j ≤ n − k, the position of the jth L in λ is weakly to the right from the position of the jth L in µ (viii) . For example, SSSLL SLSLS LSLSS. It is easy to verify that is a partial order relation, and that these two definitions are indeed equivalent.
In fact, is the transitive closure of the relation "u is obtained from v by replacing some consecutive occurrence of LS by SL". In particular, it follows that L n−k S k -the maximum element of SL(k, n − k) -covers just one element: L n−k−1 SLS k−1 , and that S k L n−k -the minimum element of SL(k, n − k) -is covered by just one element: S k−1 LSL n−k−1 .
See Figure 13 for the Hasse diagram of SL(k, n − k) with the partial order , for n = 6, k = 3 (the words marked by blue colour are the 3-shadows of ρ, T(ρ), . . .).
Definition 20 (Bandwidth). The bandwidth (also called maximum displacement) of a permutation π = a 1 a 2 . . . a n is d(π) := max The inequality d(π) ≤ r corresponds to the diagram of π being (2r + 1)-diagonal. This means that it is entirely contained in the main diagonal and its r shifts to either side. Obviously, for each permutation π of size n, we have d(π) ≤ n − 1, and d(π) = 0 if and only if π = id. 4.2 The worst case: n − 1 iterations, and a key statistic: bandwidth of permutations The main result of this section is the following theorem about the bandwidth of a permutation in Im(T m ). In terms of permutation diagrams, this theorem says that grey areas as in Figure 3 do not contain any points of respective diagrams.
Notice that for m = n − 1 we obtain that a permutation in Im(T n−1 ) has d = 0, and thus we recover Ungar's result mentioned above, Im(T n−1 ) = {id}. The proof that we give is also a generalization of Ungar's proof of this special case (ix) . The proof of Theorem 21 will follow from the following propositions.

Proposition 22.
Let σ be a permutation of size n. Let 1 ≤ k ≤ n − 1. Let λ ∈ SL(k, n − k) (the poset defined in Definition 19) such that λ = S k L n−k . Let λ be the word obtained from λ by replacing each consecutive occurrence of LS by SL. Then we have: If shadow(σ) λ then shadow(T(σ)) λ .

Proof:
The word shadow(T(σ)) is obtained from shadow(σ) by flips of the form L a S b → S b L a (for some a, b ≥ 0), induced by flips in σ. It follows that for each j (1 ≤ j ≤ k) we have s j (shadow(T(σ))) ≤ s j (shadow(σ)). Moreover, if s j (shadow(σ)) = α and the (α − 1)st position in shadow(σ)) is L, then we have s j (shadow(T(σ))) < s j (shadow(σ)). As for λ: since all the flips in λ are of the form LS → SL, we always have s j (λ ) = s j (λ) or s j (λ ) = s j (λ) − 1.
In terms of k-wiring diagram, this means that S-paths are monotone in the sense that, as we scan them from the top to the bottom, they move weakly to the left at each step. Moreover, if there is L before S, then the path that goes through this S will move strongly to the left at the next step.
In terms of k-wiring diagrams, Proposition 23 says that the paths in the k-wiring diagram of ρ majorize the paths in the k-wiring diagram of π in the following sense: for each j (1 ≤ j ≤ k), the path S j (π) is weakly to the left of the path S j (ρ); and similarly, for each j (1 ≤ j ≤ n − k), the path L j (π) is weakly to the right of the path L j (ρ). For illustration, see Figure 15 in which Sand L-paths of π (thin red and blue lines) are shown together with Sand L-paths of ρ (thick pink and light-blue lines). ) shadow(T m (ρ)). Right part: The wiring diagrams for π and for ρ shown superimposed. For each j, the red path S j (π) is weakly to the left of the pink path S j (ρ); for each j, the blue path L j (π) is weakly to the right of the light-blue path L j (ρ). The triangular areas (indicated by a yellow colour) only contain S for the left triangle and L for the right triangle.
We now can complete the proof of Theorem 21 on the bandwidth of permutations in Im(T m ).

Proof of Theorem 21:
We notice that, along the last (vertical) segment of any path of ρ, the corresponding path of π coincides with it (these areas are marked by yellow triangles in Figure 15). More formally, it follows from Proposition 23 and from Equations (26) (which describe the shape of the Sand L-paths of ρ) that Now, we fix m (0 ≤ m ≤ n − 1), and let τ = T m (π) = b 1 b 2 . . . b n . Since s j (shadow(τ)) = α for some j implies b α ≤ k, and since j (shadow(τ)) = β for some j implies b β ≥ k + 1, equations (28) and (29) translate to Now we make the final step. Let 1 ≤ i ≤ n. Equations (30) and (31) hold for any k, 1 ≤ k ≤ n − 1, and we choose two specific values. First, we take k = i + n − 1 − m. Now we have i ≤ k + m + 1 − n, and therefore (30) In terms of permutation diagrams, Equations (30) and (31) (for fixed m) mean that for each k some rectangular areas in the diagram of τ ∈ Im(T m ) are forbidden. Taking the union of these areas for 1 ≤ k ≤ n − 1, we obtain forbidden corners, which yield the bound on the bandwidth. See Figure 16 for illustration (the forbidden areas are indicated by grey colour). In Figure 17 we show the forbidden corners for n = 5 and 0 ≤ m ≤ 4. Now, if we compare this to Figure 3 (where grey areas are precisely those forbidden by Theorem 21), we see many other areas without points, and it is natural to ask whether there are some larger forbidden areas. In fact, contrary to what Figure 3 could suggest, the forbidden areas characterized in Theorem 21 are maximal in the sense that for each position outside the grey corners we can find a permutation that contains a point at this position. In fact, all the positions not forbidden by Theorem 21 are "covered" by skew-layered permutations with ≤ 2 runs, as our next result shows.
Then there exists π, a skew-layered permutation with ≤ 2 runs, such that for τ = T m (π) = b 1 b 2 . . . b n we have b i = j.
Proof: Assume j < i. Let π = (k, n − k) where k will be determined below. From (26) and discussion thereafter, we know: if m ≤ j − 1 then Solving the first two expressions for k we obtain that we need to set The case j > i is similar, and for j = i we can take π = id which will do for any m. Finally, we remark that, since Theorem 21 establishes that the bandwidth of allowed positions for permutations in Im(T m ) decreases with m, one can be tempted to conjecture that for π = id we always have d(T(π)) < d(π). Such a claim would, of course, imply Theorem 21! However, such a conjecture is wrong: the smallest counter-example is π = 3412, and it is easy to see that any skew-layered permutation with at least two blocks, such that the first and last blocks are of size ≥ 2, is a counter-example.
For the proof, we shall exploit shadows and wiring diagrams for both k and . First, due to Observation 26.3, we know the kand the -shadows of τ: Now we introduce the (k − )-wiring diagram of π: the drawing that consists of S-paths from the k-wiring diagram of π, and the L-paths from the -wiring diagram of π. Thus, in the (k − )wiring diagram we have k (red) S-paths: for 1 ≤ j ≤ k, the jth S-path (denoted by S j ) connects the jth from left occurrences of the values from S := {1, 2, . . . , k}; and we have := n − (blue) L-paths: for 1 ≤ j ≤ the jth L-path (denoted by L j ) connects the jth from right occurrences of the values from L := { + 1, + 2, . . . , n}. The remaining values from {k + 1, k + 2, . . . , } are not connected by paths in such a diagram.
Additionally, we consider the pink paths of ρ k = (n − k, k) and the light-blue paths of ρ = (n − , ). By Proposition 23, these paths majorize the corresponding paths of π: For 1 ≤ j ≤ k, the path S j (π) is weakly to the left from the S j (ρ k ), and for 1 ≤ j ≤ , the path L j (π) is weakly to the right from the L j (ρ ).
At this point we notice that, since − k is odd, all the pink paths S j (ρ k ) and the light-blue paths L j (ρ ) cross each other at grid points of the diagram, see Figure 19. (Compare with Figure 12, where pink and light-blue paths cross each other between the rows of the diagram!) Denote by P i,j (1 ≤ i ≤ k, 1 ≤ j ≤ ) the crossing point of the path S i (ρ k ) and the path L j (ρ ): we refer to these points as conflict points. Since S ∩ L = ∅, it is impossible that both S i (π) and L j (π) pass through P i,j . This means that in the row of P i,j , at least one of the paths S i (π) and L j (π) is strongly majorized by the corresponding pink or, respectively, light-blue path.
For 1 ≤ i ≤ k, 1 ≤ j ≤ we say that the pair (i, j) is regular if some point of S i (π) lies on S i (ρ k ) after P i,j and before S i (π) and S i (ρ k ) reach their final position i, and some point of L j (π) lies on L j (ρ ) after P i,j and before L j (π) and L j (ρ ) reach their final position n + 1 − j. Next we prove two claims: • Claim 1: The pair (k, ) is regular.
Indeed, we have b k+1 = k and b = + 1; this means that, in the row which corresponds to τ = T n−2 (π), S k (π) coincides with S k (ρ k ), and L (π) coincides with L (ρ ). In both cases, the paths are after the conflict points and before their final columns.
• Claim 2: If a pair (i, j) is regular, then at least one of the pairs (i − 1, j), (i, j − 1) is regular. At least one of the paths S i (π), L j (π) does not contain the point P ij . Assume without loss of generality that S i (π) does not contain the point P ij . That is, in the row of P ij , S i (π) is strictly to the left from the pink path S i (ρ k ). Since S i (π) has later a point that lies on S i (ρ k ) (after P i,j , but before both paths reach their final position i), it makes a vertical step there, from a point α to a point β (refer to Figure 20). But this means that γ, the left neighbour of α, is also from S. Therefore γ is a point of S i−1 (π) on S i−1 (ρ k ), after P i−1,j but before both paths reach their final position i − 1. This means that the pair (i − 1, j) is regular. (If we assume above that L j (π) does not contain the point P ij , we obtain that (i, j − 1) is regular.) α β γ Fig. 20: Illustration to the proof of the claim: if (i, j) is regular, then (i − 1, j) is regular or (i, j − 1) is regular.
Starting with Claim 1 and applying Claim 2 repeatedly, we obtain that the pair (1, 1) is regular. However, the proof of Claim 2 applies to (1, 1) as well. Since (1, 1) is the highest conflict point, we get a contradiction.
It is also possible to reverse this proof and to explain it "from the top to the bottom". Then it essentially says that at least one of the sets, S and L, arrives at its final position sooner than in n − 1 iterations. However in τ these sets are not at their final position (as witnessed by (32)), and this is a contradiction.

35
[Second part of the proof: τ is thin and with no inner runs of odd size ⇒ τ ∈ Im(T n−2 ).] For each τ which is a thin permutation without odd inner runs, we will construct π such that T n−2 (π) = τ. If τ = id we can take π = id, so we assume from now on that τ = id. Let τ = thin(r 1 , r 2 , . . . , r s−1 , r s ) so that s > 1 and the numbers r 2 , . . . , r s−1 are even. We define π to be the skew-layered permutation (r s , r s−1 , . . . , r 2 , r 1 ).
We claim that for this π we have T n−2 (π) = τ. To see that, we analyse the wiring diagram of π, T(π), T 2 (π), . . .; an example is illustrated in Figure 21. Notice that this is the usual wiring diagram, in which paths connect fixed values. For the sake of visualization, each inner run of π is partitioned into two blocks of equal size, the left one and the right one. For the values from the left blocks of inner runs, and for all the values from the last run, we colour the paths in green. For the values from the right blocks of inner runs, and for all the values from the first run, we colour the paths in orange. Then, the paths have very clear description. Specifically, for an inner run of length r, the jth from left value (1 ≤ j ≤ r/2) generates the green path that consists of 5 segments (some of them can be empty): (1) a vertical segment of length (j − 1), (2) a slanted segment of slope 1 until the path reaches the position j, (3) a vertical segment of length r − 2j + 1, (4) a slanted segment of slope −1 until the path reaches its final position, (5) a vertical segment. The green paths of the last run do not have (4) and (5); orange paths are described similarly. The whole diagram is symmetric, and therefore the sequence of lengths of runs of τ is the reversal of the sequence of lengths of runs of π. 1 2 4 3 6 5 7 8 10 9 10 6 7 8 9 4 5 1 2 3 π τ = T n−2 (π) Fig. 21: Illustration to the proof of T n−2 ( (r s , . . . , r 1 )) = thin(r 1 , . . . , r s ) (where r 2 , . . . , r s−1 are even).
Our proof shows that in order to construct a permutation in Im(T n−2 ), one only has to choose positions (of the same parity) for the gaps between runs. This yields the enumerative formula, as stated in the claim.
Remark. In general, there are several permutations π that satisfy T n−2 (π) = τ for given τ ∈ Im(T n−2 ). Characterizing all such π is a challenging problem.

Skew-layered permutations: a family of worst cases
By Theorem 27, each skew-layered permutation of size n without odd inner runs has the (maximum possible for permutations of size n) cost n − 1. Characterizing all permutations with that cost is a challenging open problem. In this section, we present a necessary condition, and then we conclude with a conjecture concerning the cost of any skew-layered permutation.

Conclusion
In this article, we have seen that a simple sorting procedure like flip-sort has many interesting combinatorial and algorithmic facets. Our analysis of the best cases and the worst cases of this algorithm, our results on the underlying poset, the links with lattice paths, are just some first steps towards a more refined understanding of this process.
En passant, we listed a few conjectures, which, we hope, could tease the desire of the reader to work on this topic. The optimal cost of the computation of pop-stacked permutations is still open; other challenges are a finer analysis of the automata which recognize them (when the number of runs is fixed), the existence of closed-form formulas, a method to solve puzzling functional equations like the one given in Theorem 10.
We also believe that several of the notions and structures introduced in this article can also be useful for the next natural step: the average-case analysis of flip-sort. Even if this algorithm is not, in its naive version, as efficient as quicksort, it is very easy to implement, to parallelize, and it is still possible to optimize its implementation (this is a subject per se, like using double chained lists to perform the flips efficiently, or using some additional data structures to have a parsimonious reading of each iteration, etc). So there is not a "flip-sort" algorithm, but a family of flip-sort algorithms, and to finely tune them in order to decide what could be the optimal variant should clearly be the subject of future research.