Title: Sorting permutations using a pop stack with a bypass
Domain: Math

Question: How can permutations be characterized and enumerated under sorting by a pop stack equipped with a bypass operation? In particular, which forbidden patterns give necessary-and-sufficient criteria for sortability, how can a bijection with suitably restricted Motzkin paths be constructed so that the counting sequence is the odd-indexed Fibonacci numbers, and how can one design and analyze an algorithm to compute preimages—especially for permutations with few preimages and for principal classes—with a structural description of these sets? Furthermore, how do these results extend to several pop stacks in parallel with bypass, yielding explicit bases for the sortable permutations, rational generating functions, and connections to classical sorting algorithms, with rigorous proofs throughout?

Background: 1. Sorting permutations in combinatorics | • Central research topic, studied through containers like stacks, queues, and pop stacks. | • Pattern avoidance provides the unifying framework to characterize sortable classes. | 2. Classical algorithms as context | • Stacksort (Knuth): Sortable class = Av(231), counted by Catalan numbers. | • Queuesort: Requires bypass, sortable class = Av(321), Catalan numbers. | • Bubblesort: Depth-1 variant, sortable class = Av({231, 321}), counted by powers of two. | 3. Pop stack with bypass (PSB) | • Operations: PUSH (insert into stack), POP (empty entire stack), BYPASS (direct to output). | • Key distinction: POP clears the whole stack, and BYPASS adds flexibility beyond classical stacks. | • Motivates the question: what patterns characterize PSB-sortable permutations, and how do they connect to broader enumeration frameworks?

Definitions: 1. Permutation basics | • A permutation π of size n is a bijection from [1,n] to [1,n], written as π = π₁···πₙ. | • Identity permutation: idₙ = 12···n. | • Sets: Sₙ = all permutations of size n, S = ⋃ Sₙ. | 2. Element relations | • Adjacent elements: consecutive in position. | • Consecutive elements: consecutive in value. | • Left-to-right maxima: LTR(π) = {πᵢ | πᵢ = max{πⱼ | j ≤ i}}. | • Example: π = 3645712 → Adjacent: (1,7); Consecutive: (5,6); LTR = {3,6,7}. | 3. Pattern avoidance framework | • Pattern containment: π contains ρ if a subsequence of π is order-isomorphic to ρ. | • Pattern avoidance: Av(ρ) = all π avoiding ρ; Av(T) = avoid all patterns in T. | • Permutation poset: (S, ≤) ordered by containment; classes are down-sets. | 4. PSB operations | • PUSH: insert current element into stack. | • POP: remove all stack elements to output. | • BYPASS: send current input directly to output. | • Distinction: POP clears full stack; BYPASS allows extra flexibility. |

Methodology: 1. Sortability characterization | • Goal: determine necessary and sufficient conditions for PSB sortability. | • Result: sortable permutations are exactly those avoiding 231 and 4213. | 2. Key analytical tools | • Noninversion preservation: PSB never creates new inversions. | • Stack entry characterization: elements entering the stack form decreasing subsequences tied to left-to-right maxima. | 3. Pattern analysis | • 231: forces two larger elements into the stack before a smaller one, causing unavoidable reversal. | • 4213: forces blocking in the stack, preventing correct output. | • Hence 231/4213 avoidance fully characterizes sortability. | 4. Enumeration via bijection | • Map PSB operations to ternary words with restrictions (start 0, end 0/2, avoid 12). | • Convert words to restricted Motzkin paths. | • Enumeration matches odd-indexed Fibonacci numbers. | 5. Extensions | • Parallel pop stacks (PSBP): sortable basis remains finite, generating function is rational. | • Algorithm compositions: combining PSB with Stacksort, Queuesort, or Bubblesort yields new avoidance classes; enumeration sequences often match known OEIS entries.

Answer: | 1. Pattern Characterization and Algorithm Optimality | Permutations sortable by the pop stack with bypass (PSB) are precisely those that avoid the patterns 231 and 4213 ￼. If a permutation contains either pattern, the sorting process inevitably outputs elements in the wrong order. Conversely, if a permutation avoids both, all steps of the PSB algorithm are valid, and the permutation is successfully sorted. The algorithm functions optimally by maintaining consecutive elements in the stack, prioritizing PUSH over BYPASS, and handling left-to-right maxima efficiently. | | 2. Enumeration via Motzkin Paths and Fibonacci Numbers | Sortable permutations can be encoded as ternary words built from the PSB operations (PUSH = 0, BYPASS = 1, POP+PUSH = 2). These words must begin with 0, end with 0 or 2, and avoid the factor 12. This encoding establishes a bijection with a restricted class of Motzkin paths: paths start with an up-step, end with a down-step, avoid adjacent horizontal–down or down–horizontal pairs, and enforce immediate return to the axis after each down-step. The enumeration of these paths yields the odd-indexed Fibonacci numbers F_{2n-1}, so sortable permutations of size n are counted by this sequence. | | 3. Preimages under PSB | Every permutation has a well-defined set of preimages under PSB. The algorithm for constructing preimages relies on decomposing a permutation by its left-to-right maxima and reinserting removed elements under specific rules ￼. Results include: | • Permutations with no preimage are exactly those not ending with their maximum, with count (n-1)(n-1)!. | • Those with exactly one preimage are characterized by ending with n, having left-to-right maxima that are consecutive but nonadjacent, and enumerated by a summation formula involving binomial coefficients. | • Those with two preimages have a similar structure, where the first maximum may be adjacent, but others are not, with counts given by a more complex combinatorial expression. | These cases illustrate the structural link between left-to-right maxima and preimage behavior. | | 4. Preimages of Permutation Classes | For certain principal classes, preimages under PSB remain classes. If the basis permutation begins with its maximum (n\alpha) or begins with the second maximum and ends with the maximum ((n-1)\alpha n), then preimages form classes whose bases can be described explicitly ￼. In contrast, for patterns such as \alpha n\beta or \alpha(n-1)n with |\alpha|\geq 2, preimages are not closed under containment, and thus do not form classes. | | 5. Compositions with Classical Sorting Algorithms | Composing PSB with other sorting operators yields new avoidance characterizations: | • Stacksort after PSB sorts exactly permutations avoiding patterns {2341, 25314, 52314, 45231, 42531, 3̄5241}. | • Queuesort after PSB yields the avoidance class {3421, 53241, 53214}, with enumeration matching OEIS A218225. | • Bubblesort after PSB corresponds to avoiding {2341, 3421, 3241, 25314, 52314, 53214}, with generating function (1-3x)/(1-4x+2x^2). | Similarly, when PSB is applied after Queuesort or Bubblesort, distinct pattern bases characterize the sortable sets, with generating functions matching known OEIS sequences . | | 6. Pop Stacks in Parallel with Bypass | For two pop stacks in parallel with bypass, the sortable permutations are characterized by avoiding the finite set {2341, 25314, 42513, 42531, 45213, 45231, 52314, 642135, 642153}. The corresponding algorithm (PSBP) ensures optimality by selecting appropriate push/bypass moves. The resulting class has a rational generating function | G(x) = \frac{(1-x)(1-2x)(1-4x)}{1-8x+20x^2-18x^3+3x^4}, | recorded as sequence A374165 in OEIS. In general, for any number k of parallel pop stacks with bypass, the basis of forbidden patterns is finite, and the generating function is rational. | |

Checklist: 1. Defines fundamental concepts: permutation π, pop stack operations (PUSH, POP, BYPASS), and the pattern avoidance framework. | 2. Characterizes PSB-sortable permutations by avoidance of patterns 231 and 4213, showing necessity and sufficiency. | 3. Establishes a bijection between sortable permutations and restricted Motzkin paths, proving the enumeration equals odd-indexed Fibonacci numbers. | 4. Provides an algorithm for computing preimages under PSB and analyzes its correctness. | 5. Characterizes permutations with exactly 0, 1, or 2 preimages and gives enumerative results. | 6. Determines when preimages of principal pattern classes remain classes and identifies their bases. | 7. Analyzes compositions of PSB with Stacksort, Queuesort, and Bubblesort, giving forbidden pattern characterizations and generating functions. | 8. Establishes the finite basis theorem for k parallel pop stacks with bypass, proves rationality of generating functions, and develops the PSBP algorithm for two parallel stacks. | 9. States key technical lemmas including noninversion preservation and stack entry characterization. | 10. Explains the structural link between left-to-right maxima and stack operations in PSB sorting. | 11. Extends the framework to words and specialized permutation classes.