A new lower bound for deterministic pop-stack-sorting
Abstract.
The pop-stack-sorting process is a variation of the stack-sorting process. We consider a deterministic version of this process. We prove a lemma which characterises interior elements of increasing runs after iterations of the process and provide a new lower bound of for the number of iterations of the process to fully sort a uniformly randomly chosen permutation of length .
1. Introduction
Pop-stack-sorting was introduced by Avis and Newborn in [4]. It is a variation of the stack-sorting process first presented by Knuth in The Art of Computer Programming [14]. Pop-stack-sorting has been the subject of much research in recent years (see [2, 3, 5, 6, 7, 8, 10, 11, 12, 13]). For our purposes, a permutation is an ordered list of the elements of , where each element appears once. We write permutations in the one-line notation, that is . We consider the deterministic algorithm to which Defant refers as the function [9]. The function acts as follows: given a permutation , read the permutation from left to right and if there are any consecutive elements which are in decreasing order, reverse the order of those elements. For example, . Let be the average number of iterations of that it takes to transform a uniformly randomly chosen permutation of length to the identity permutation . In [9], Defant conjectured that
and asked, in that paper and at the Banff workshop on Analytic and Probabilistic Combinatorics in November 2022, if there exists such that
It was first proven in [16] that , and reproven in both [3, 1] using more direct arguments. The lower bound of was not proven by Defant in that paper, but we believe that his conjecture was based on an argument similar to a combination of Proposition 2 and Lemma 7.
In [15], Lichev gave a lower bound of . We improve this bound by proving the following theorem.
Theorem 1.
Let be the average number of iterations of that it takes to transform a uniformly randomly chosen permutation of length to the identity permutation. Then
2. Preliminaries
For brevity, we adopt the notation throughout the paper. Following the standard notation, the position of the element in the permutation is denoted . An increasing run in is a maximal set of elements , , such that and A decreasing run is defined similarly. Note that, by this definition, we do not refer to single elements as increasing (or decreasing) runs of length one. An element is in the interior of an increasing (or decreasing) run if it is an element of an increasing (or decreasing) run, but neither the first nor the last element of that run. We also refer to iterations of simply as iterations, and the th iteration as iteration .
Defant noted without proof in [9] that in the image of a permutation under , there are no decreasing runs of length more than three.
Proposition 2.
Let be a permutation. Then has no decreasing runs of length four or more.
Proof.
Suppose that has four adjacent elements, and , in that order, such that Since reverses decreasing runs, if two elements are in increasing order in , then they cannot be in the same decreasing run and therefore they are also in increasing order in . Thus, lies before in If there are no elements between them in , then and are in a decreasing run and are reversed in . Hence, there must be some element in between and with either or . Assume . If there are no elements between and in , then they are in the same decreasing run in and lies before in . Thus the decreasing run including and does not include , so that is between and in , a contradiction. A similar argument can be made to show that if then must be between and in . ∎
Since all decreasing runs in a pop-stack-sorted permutation are of length two or three, and we are intensely concerned with the manner in which individual elements move, we name each possible way of moving or holding position for an element during an iteration after the first.
We say that causes two elements to switch if they are in reverse order but not part of a decreasing run of length three. We say that causes three elements to pivot if they are in a decreasing run of length three, where the outermost elements both move and the middle of the three elements holds its position. We call the middle element of a pivot the center of the pivot. If an element is in the interior of an increasing run, or at the start of an increasing run in position , or the end of an increasing run in position , it has the same position after is applied, and we say that the element stops.
In any given iteration after the first, there are four ways to move: switch left, switch right, pivot left, pivot right, and two ways to hold position: be the center of a pivot, or stop.
Consider the example from above. Then we have
Applying again, we have
During iteration 2, the pair 1 and 4 and the pair 3 and 7 switch and the elements 2, 6, and 8 pivot, with 6 as the center of the pivot. The only elements which hold their position during iteration 2 are 6, 5, and 9; 6 is the center of a pivot and both 5 and 9 stop. Note also that the element 6, which is the center of a pivot in iteration 2, stops during iteration 1.
3. The pop-stop lemma and proof of Theorem 1
We begin with two observations regarding elements which stop. Let be a permutation of length .
Observation 3.
If three elements pivot during iteration , then the center of the pivot stops during iteration .
Proof.
If moves or is the center of a pivot during iteration , then is in an increasing run with at least one of its neighbors in , thus cannot be the center of a pivot during iteration , a contradiction. The only remaining possibility is that stops during iteration . ∎
Observation 4.
If an element moves to the left during iteration , , then during iteration it either moves to the left or stops. The corresponding statement for moving right also holds.
Proof.
If an element moves to the right or is the center of a pivot during iteration , then it is larger than its neighbor on its left in and thus cannot move to the left during iteration . Therefore, the element must move to the left or stop during iteration . ∎
The following lemma, which we refer to as the pop-stop lemma, gives some insight into the circumstances under which an element stops during iteration . Such elements are important because pivots (after the first iteration) are always preceded by a stop. Fix some in a permutation of length , where so that the sorting process eventually causes to move to the left. Intuitively, almost always moves to the left until it becomes a left-to-right maximum unless it encounters an element smaller than to its left and stops or it is the center of a pivot. However, both cases necessitate stops and therefore there must be smaller elements to the left of , and such elements never move to the right of . If stops during iteration where is large, there must be many elements which are smaller than to its left, or it must already be a left-to-right maximum. Thus, there exists some which depends on but not on such that cannot stop during iteration unless it is a left-to-right maximum.
Lemma 5 (pop-stop lemma).
Let be a permutation of length and let be in the interior of an increasing run. Then is either a left-to-right maximum of or there are at least elements smaller than to its left in . Similarly, is either a right-to-left-minimum of or there are at least elements larger than to its right in .
Proof.
We proceed by induction on , the number of iterations. If or , , so the statement is true by virtue of being in the interior of an increasing run.
Suppose an element moves left during iteration . Observation 4 implies that moves left for consecutive iterations for some (from iteration to iteration , inclusive) and either stops during iteration or . Let be the number of positions that moved in the previous iterations, so . It must be the case that .
If , then there are at least elements larger than to its right in .
If , then stops during iteration and is in the interior of an increasing run in . By the induction hypothesis, is a right-to-left minimum in or there are elements larger than to its right in . If is a right-to-left minimum in , it is also a right-to-left minimum in . If there are elements larger than to its right in , then there are at least
elements larger than to its right.
It follows that elements which move left in iteration are either right-to-left minima or have at least larger elements on their right in .
A symmetric argument shows that elements which move right are either left-to-right maxima or have at least smaller elements on their left in .
If an element stops during iteration , then it is in the interior of an increasing run in . By the induction hypothesis, in both and , is either a left-to-right maximum or there are elements smaller than to its left, and it is either a right-to-left minimum or there are elements larger than to its right.
Assume that the element is in the interior of an increasing run in . Now we proceed by cases.
-
Case 1:
The element is the center of a pivot during iteration .
It is not possible for to be a left-to-right maximum or right-to-left minimum in or , since , so we only consider the number of elements.
By Observation 3, stops during iteration and is in the interior of an increasing run in . By the induction hypothesis, in , there are at least elements smaller than to its left. The pivot causes one element smaller than to move from the right of to its left, so that, in , there are at least elements smaller than to its left. A symmetric argument shows that there are at least elements larger than to its right in .
-
Case 2:
The element moves right or left during iteration .
Suppose moves left. Then it must either be a right-to-left minimum or have at least elements larger than on its right in . The element either moves right during iteration , or it is in the interior of an increasing run in . In either case, it is either a left-to-right maximum or there are at least elements smaller than on its left in . Thus, is either a left-to-right maximum or there are at least elements smaller than on its left in .
A symmetric argument applies if moves right.
-
Case 3:
The element stops during iteration .
Each neighbor of either moves towards during iteration or stops. By the same arguments as in Case 2, in , is either a left-to-right maximum or there are at least elements smaller than on its left. Similarly, is either a right-to-left minimum or there are at least elements larger than on its right in . Therefore, in , is either a left-to-right maximum or there are at least elements smaller than on its left and is either a right-to-left minimum or there are at least elements larger than on its right.
∎
In order to be in the center of a pivot (after the initial iteration), an element must first stop. If an element is in position in and it is in the interior of an increasing run, the element has at least smaller elements to its left, so the pop-stop lemma guarantees that if it stops, then it is a left-to-right maximum. Since the center of a pivot has a larger element to its left, is not the center of a pivot, and neither are any other elements which are within positions from either end of .
The most an element can move in any iteration after the first is two positions by pivoting. Thus, for every two iterations, an element can move four positions, however, after those two iterations one more position at the end of the permutation cannot be the center of a pivot. Thus, we split the permutation into fifths; during roughly the first iterations, an element can move about positions, but in the following iterations positions can not be centers of pivots. This can be leveraged to yield the following theorem.
Theorem 6.
Let be a permutation of length and let the element (the th largest element) be in the th position after one iteration, that is, . Let be the least such that is the increasing permutation.
If , then
If (so that the element considered is ), then
Proof.
If , for the first iterations, the pop-stop lemma implies that position and all positions to its right cannot contain the center of a pivot, which does not contribute to our argument. During those iterations, the element moves from position in to the right at most two positions at a time for the next iterations, for a total of at most positions moved after iteration . Thus, is in position at most in . From there, it needs to move through at least another elements to reach its final position. The element can pivot for a maximum of iterations and then must switch for at least iterations to finish, giving a total of at least iterations to sort the permutation. The proof for is similar, but does not require the initial iterations. ∎
We note that this bound could be improved by a single iteration for some values of and if one were to consider the possibilities of the distance to travel after iterations mod 5, but such considerations give at most a change of one in the bound at the cost of a more complicated statement.
Lichev proved the following lemma ([15], Observation 1 and Observation 2).
Lemma 7.
In a uniformly randomly chosen permutation of length , there exists a.a.s. an element such that after the first iteration
4. Future directions
We note that the bound of is asymptotically the correct upper bound for the possible number of pivots to the right which any element can make. We present a family of permutations in which the element pivots times and reaches the final position after iterations.
Example 8.
Let , and let , , , . Construct a permutation as follows: take elements from and in the pattern in decreasing order. Once all of the elements from these sets have been exhausted, append each element of in increasing order at the end. Explicitly, this is the permutation Figure 1 shows this construction for .
In this case, the permutation takes iterations to be transformed into the identity; although is in the last position of , there are other elements which are not in order in .
We do not believe this bound is attainable for both the elements and in the same permutation. The following construction gives a permutation where each of and pivot roughly times.
Example 9.
Let , and let , , and let . Consider the permutation which consists of elements taken in the pattern in decreasing order. Figure 2 shows this construction for .
The permutation takes roughly iterations to be transformed into the identity permutation.
We believe that the pop-stop lemma can be used in future arguments to improve this lower bound in two ways.
First, for every two pivots in an “early” iteration which can be shown to be unlikely, the pop-stop lemma guarantees an “extra” pivot which is prevented later. For example, if it were possible to show that the average number of pivots in the first iterations for the element which must travel the furthest was , the pop-stop lemma gives a corresponding guaranteed switches at the end.
Second, our arguments in the proof of Theorem 6 use the pop-stop lemma to argue that there are no pivots near the left or right of . However, The lemma also implies that elements near the top or the bottom of cannot be the center of pivots. For example, in , if the element is in the interior of an increasing run, it has at least smaller elements to its left, so it cannot be the center of a pivot in and beyond, as a pivot requires that the element must stop in iteration and have an element smaller immediately to its right in . One can picture that the pop-stop lemma guarantees a square where no centers of pivots can occur that starts one element from the edge of the permutation (for the elements in the first and last positions and the elements and can never be the center of a pivot) and closes in one element in each direction every two iterations (see Figure 3). As Example 8 shows, it is not impossible for elements to pivot every time in the first iterations, but using these closing windows at the top and bottom might be one approach to show that it is rare in a uniformly randomly chosen permutation.
5. Acknowledgements
The authors are grateful to Colin Defant for introducing us to the problem and for some helpful suggestions and corrections. We are also grateful to Kelly Debure for lending us some time.
References
- [1] M. Albert and V. Vatter. How many pop-stacks does it take to sort a permutation? The Computer Journal, 65(10):2610–2614, 2022.
- [2] A. Asinowski, C. Banderier, S. Billey, B. Hackl, and S. Linusson. Pop-stack sorting and its image: permutations with overlapping runs. Acta Mathematica Universitatis Comenianae, 88(3):395–402, 2019.
- [3] A. Asinowski, C. Banderier, and B. Hackl. Flip-sort and combinatorial aspects of pop-stack sorting. Discrete Mathematics & Theoretical Computer Science, 22(Special issues), 2021.
- [4] D. Avis and M. Newborn. On pop-stacks in series. Utilitas Math, 19(129-140):410, 1981.
- [5] Y. Choi and N. Sun. The image of the pop operator on various lattices. arXiv preprint arXiv:2209.13695, 2022.
- [6] A. Claesson and B. Á. Guðmundsson. Enumerating permutations sortable by passes through a pop-stack. Advances in Applied Mathematics, 108:79–96, 2019.
- [7] A. Claesson, B. Á. Guðmundsson, and J. Pantone. Counting pop-stacked permutations in polynomial time. Experimental Mathematics, 32(1):97–104, 2023.
- [8] C. Defant. Enumeration of stack-sorting preimages via a decomposition lemma. Discrete Mathematics & Theoretical Computer Science, 22(Combinatorics), 2021.
- [9] C. Defant. Fertility monotonicity and average complexity of the stack-sorting map. European Journal of Combinatorics, 93:103276, 2021.
- [10] C. Defant. Meeting covered elements in -Tamari lattices. Advances in Applied Mathematics, 134:102303, 2022.
- [11] C. Defant. Pop-stack-sorting for Coxeter groups. Combinatorial Theory, 2 (3), 2022.
- [12] C. Defant and N. Williams. Coxeter pop-tsack torsing. Algebraic Combinatorics, 5(3):559–581, 2022.
- [13] L. Hong. The pop-stack-sorting operator on Tamari lattices. Advances in Applied Mathematics, 139:102362, 2022.
- [14] D. Knuth. The Art of Computer Programming: Sorting and searching. Addison-Wesley series in computer science and information processing. Addison-Wesley Publishing Company, 1968.
- [15] L. Lichev. Lower bound on the running time of pop-stack sorting on a random permutation. arXiv preprint arXiv:2212.09316, 2022.
- [16] P. Ungar. 2n noncollinear points determine at least 2n directions. Journal of Combinatorial Theory, Series A, 33(3):343–347, 1982.