betaFeedback

WorksComputer Science

Enumeration Complexity of Permutation Classes

Abstract

We study classes of permutations that are defined by avoidance of forbidden patterns. For each fixed finite set BB of forbidden patterns, we study the avoider enumeration problem: given an integer nn, output all BB-avoiding permutations of length nn. Avoider enumeration is output-polynomial for every fixed BB. However, our main notion of efficiency is polynomial delay. We use the insert-maximum tree as a search tree, in which permutations are built by repeatedly inserting a new maximum while preserving pattern avoidance. This leads to the insert-maximum extension problem, which asks if a given permutation has an avoiding descendant at a specified depth. An algorithm for this problem can prune branches that cannot reach the target length. Hence, if this problem is in P, we obtain polynomial-delay enumeration. To investigate this problem, we introduce and study pockets, the maximal finite subtrees of the insert-maximum tree. For fixed BB, if there is a polynomial pp such that every pocket rooted at ρρ has at most p(∣ρ∣)p(|ρ|) nodes, then the extension problem is solvable in polynomial time and enumeration has polynomial delay. In particular, a bound on pocket depth depending only on BB suffices. We prove such a bound if the class is well-quasi-ordered, has a regular insertion encoding, or if BB omits one of the three maximum-position types: leftmost, interior, or rightmost. We also prove that extension is in NP for every fixed BB, even with binary-encoded target depth. On the negative side, we construct a fixed set of 5555 forbidden patterns for which extension is NP-complete. Consequently, enumerating valid extensions from a given starting permutation cannot have polynomial delay unless P=NP. This also answers a question of Hanika by showing that the forbidden permutation constraint satisfaction problem can be NP-complete for a fixed forbidden set.

Funding Manuel Bodirsky: Funded by the European Union (project POCOCOP, ERC Synergy grant No. 101071674). Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council Executive Agency. Neither the European Union nor the granting authority can be held responsible for them.

Disclosure of AI assistance.

ChatGPT with the GPT 5.6 Sol model was used during development of the fixed forbidden set BfinalB_{\mathrm{final}}. The interaction used Generalized Coloring of Permutations by Jelínek, Opler, and Valtr [12] as background and involved about 150 prompts over about four days. An initial suggested construction had 224 forbidden patterns, the longest of length 481. The suggestions to use increasing oscillations and simple permutations came from ChatGPT. The routing idea came from the provided paper. The construction was subsequently checked and simplified by the authors. The entire paper was thoroughly revised by the authors, and GPT 6 Astra and Claude Opus 5.5 were used for proofreading. The authors take full responsibility for the final text.

Introduction

Permutation patterns describe the relative order of selected entries in a permutation. A permutation contains a pattern if some subsequence has the same relative order as that pattern, and avoids it otherwise. For example, 2413 contains 132 through the entries 2, 4, 3, but avoids 321. Pattern avoidance provides a common language for structural and counting questions about permutations [20].

For a finite set of permutations BB, let Av⁡n(B)\operatorname{Av}_n(B) be the permutations of length nn that avoid every member of BB. We study the algorithmic task of enumerating all members of Av⁡n(B)\operatorname{Av}_n(B). Here enumeration means outputting the objects (whereas counting means computing their number). For fixed BB, let EnumAvoid⁡B\operatorname{EnumAvoid}_B denote the problem of enumerating all members of Av⁡n(B)\operatorname{Av}_n(B), without repetitions, where nn is given in unary.

An enumeration algorithm has polynomial delay if the time before the first output, between consecutive outputs, and between the last output and termination is bounded by a polynomial in the input size. This also requires polynomial-time termination when there is no output. We write DelayP for the class of enumeration problems admitting such an algorithm. An enumeration algorithm is output-polynomial if its total running time is bounded by a polynomial in the input size and the total encoded size of all outputs. We write OutputP for the corresponding class [13, 18].

Successive insertions of new maxima give a natural search tree, which we call the insert-maximum tree. When the class is nonempty, the root is the empty permutation. The children of a permutation are obtained by inserting the next maximum such that the resulting permutation is still in the class. Deleting the maximum gives each nonroot node a unique parent, so level nn contains exactly Av⁡n(B)\operatorname{Av}_n(B), without repetitions. Therefore, the required permutations can be enumerated with depth-first search. The difficulty is that a finite branch may contain many nodes but no permutation of the target length.

To guide the traversal, we consider an auxiliary decision problem. Fix a finite forbidden set BB. Given a permutation ρ\rho and a nonnegative integer kk, the problem ExtendMax⁡B\operatorname{ExtendMax}_B asks whether ρ\rho has a BB-avoiding extension obtained by inserting kk new maxima. Equivalently, it asks whether the subtree rooted at ρ\rho reaches depth kk. If this problem is solvable in polynomial time, then flashlight search (a general method for turning an extension oracle into an enumeration algorithm [18 Section 3.3]) can discard every branch that contains no output and thereby enumerate the target level with polynomial delay. We use ExtendMax⁡Bun\operatorname{ExtendMax}^{\mathrm{un}}_B with the superscripts un and bin to specify whether the given k∈Nk \in\mathbb{N} is encoded in unary or in binary.

Results

Every fixed finite set BB of forbidden permutations admits output-polynomial avoider enumeration. We give sufficient conditions on BB for polynomial-time extension and polynomial-delay enumeration. For a nonempty set of permutations BB, we write ∥B∥:=max⁡β∈B∣β∣\lVert B\rVert:= \max_{\beta\in B} \lvert\beta\rvert. A node is viable if it has extensions of arbitrary depth, and mortal otherwise. A pocket is a maximal finite subtree.

Theorem 1.1. For every finite set of permutations BB, the following hold.

  1. EnumAvoid⁡B∈\operatorname{EnumAvoid}_B \in OutputP.

  2. ExtendMax⁡Bbin\operatorname{ExtendMax}^{\mathrm{bin}}_B belongs to NP. For nonempty BB containing only nonempty patterns, every mortal permutation ρ\rho has depth at most (∥B∥−1)2(∣ρ∣+1)(\lVert B\rVert- 1)^2(\lvert\rho\rvert+ 1).

  1. If there is a polynomial pp such that every pocket rooted at ρ\rho has at most p(∣ρ∣)p(\lvert\rho\rvert) nodes, then ExtendMax⁡Bun\operatorname{ExtendMax}^{\mathrm{un}}_B and ExtendMax⁡Bbin\operatorname{ExtendMax}^{\mathrm{bin}}_B belong to P, and there is a polynomial delay algorithm for the extension enumeration problem.

  1. If Av⁡(B)\operatorname{Av}(B) is well-quasi-ordered, if it has a regular insertion encoding, or if BB consists of nonempty patterns and omits one of the leftmost, interior, or rightmost maximum-position types, then there is a constant DD such that every pocket has depth at most DD. Consequently, every pocket rooted at ρ\rho has size bounded by a polynomial in ∣ρ∣\lvert\rho\rvert, as required in the preceding item.

A partial order is well-quasi-ordered if it contains neither an infinite strictly descending chain nor an infinite antichain. Since the poset of finite permutations under pattern containment has no infinite strictly descending chains, a permutation class is well-quasi-ordered if and only if it contains no infinite antichain. This concept has been studied e.g. in [4]. Regular insertion encodings have been introduced in [2 Section 4].

Our main hardness result shows that efficient extension cannot be expected for every fixed basis. The result holds even when the forbidden set is fixed: only the starting permutation and the target depth are part of the input.

Theorem 1.2. There exists a set BfinalB_{\mathrm{final}} of 55 permutations, each of length at most 191, such that ExtendMax⁡Bfinalun\operatorname{ExtendMax}^{\mathrm{un}}_{B_{\mathrm{final}}} and ExtendMax⁡Bfinalbin\operatorname{ExtendMax}^{\mathrm{bin}}_{B_{\mathrm{final}}} are NP-complete.

We prove NP-hardness by reduction from monotone NAE-3SAT. In the constructed starting permutation, each Boolean state is represented by a pair of insertion sites; choosing one of the two sites encodes a bit. Fixed forbidden patterns ensure that an extension of maximum possible depth chooses exactly one site from every pair. Further patterns enforce equality along wires and the not-all-equal condition on clause triples. Increasing oscillations and simple marker permutations make these local constraints recognizable by ordinary pattern containment. A substantial part of the proof excludes unintended occurrences of the forbidden patterns.

For a fixed finite set BB of forbidden permutations, Hanika introduced the forbidden permutation constraint satisfaction problem FPCSP⁡(B)\operatorname{FPCSP}(B), where the input consists of two acyclic relations on a common finite set, and the task is to decide whether these relations can be completed to linear orders whose induced permutation avoids the fixed forbidden set BB [10 Problem 4.1]. Hanika asked whether there exists a fixed finite set BB of forbidden patterns for which FPCSP⁡(B)\operatorname{FPCSP}(B) is NP-complete. Since insert-maximum extension is a restriction of this problem, Theorem 1.2 answers his question affirmatively: FPCSP⁡(Bfinal)\operatorname{FPCSP}(B_{\mathrm{final}}) is NP-complete.

The hardness conclusion does not transfer to avoider enumeration. In particular, we do not prove that enumerating Av⁡n(Bfinal)\operatorname{Av}_n(B_{\mathrm{final}}) lacks a polynomial-delay algorithm. The distinction between an empty start and a supplied start is essential.

Related work

The insert-maximum tree is also called the pattern-avoidance tree [19 Section 1]. Kuszmaul uses the same insertion rule in an output-sensitive algorithm generating avoiders of all lengths at most nn [15 Algorithm 2]. Its runtime bound involves the total size of these levels and does not directly control the delay at a single target level. Gray-code constructions give efficient generation for several particular classes [7, 6]. Hartung, Hoang, Mütze, and Williams develop a broader generation framework based on permutation languages [11].

The insert-maximum tree and enumeration

We first fix the notation and the input conventions. The set BB of forbidden permutations is fixed throughout the paper. All algorithmic constants may depend on it.

A permutation π=π1⋯πn\pi= \pi_1 \cdots\pi_n of length ∣π∣=n|\pi| = n contains each element of [n]={1,…,n}[n] = \{1,\ldots,n\} exactly once. We call πi\pi_i the entry at position ii. The empty permutation is denoted by ε\varepsilon. For distinct numbers a1,…,ama_1,\ldots,a_m, their standardization st⁡(a1,…,am)\operatorname{st}(a_1,\ldots,a_m) is the unique permutation with the same relative order. A set of entries {πi1,…,πim}\{\pi_{i_1},\ldots,\pi_{i_m}\}, where i1<⋯<imi_1 < \cdots< i_m, is an occurrence of a permutation τ\tau in π\pi if st⁡(πi1,…,πim)=τ\operatorname{st}(\pi_{i_1},\ldots,\pi_{i_m}) = \tau. We call τ\tau a pattern of π\pi and write τ≤π\tau\leq\pi if such an occurrence exists. The entries of an occurrence induce τ\tau. Define Av⁡(B)={π:β≰π for all β∈B}\operatorname{Av}(B) = \{\pi: \beta\not\leq\pi\text{ for all }\beta\in B\}. A basis is an antichain of minimal excluded permutations. A finite forbidden set need not be a basis, but deleting its redundant members does not change the class. For nonempty BB, write ∥B∥:=max⁡β∈B∣β∣\|B\| := \max_{\beta\in B}|\beta|.

A permutation of length nn has gaps 0,…,n0,\ldots,n, which are the positions before and after the entries of the permutation; gap g∈{1,…,n−1}g \in\{1,\ldots,n-1\} is between the gg-th and the g+1g+1-st entry. Let ins⁡g(π)\operatorname{ins}_g(\pi) be the permutation obtained from π\pi by inserting n+1n+1 into gap gg. A gap is active if this permutation belongs to Av⁡(B)\operatorname{Av}(B) and inactive otherwise. The children of π\pi in the insert-maximum tree are the permutations of the form ins⁡g(π)\operatorname{ins}_g(\pi) for the active gaps gg of π\pi.

An extension of ρ\rho is a permutation σ∈Av⁡(B)\sigma\in\operatorname{Av}(B) such that deleting its ∣σ∣−∣ρ∣|\sigma|-|\rho| largest entries leaves ρ\rho. We write ρ⇝σ\rho\leadsto\sigma. Its depth over ρ\rho is ∣σ∣−∣ρ∣|\sigma|-|\rho|. Hereditary avoidance ensures that the unique sequence of successive maximum deletions from σ\sigma to ρ\rho stays in the class. Put

dB(ρ)=sup⁡{∣σ∣−∣ρ∣:ρ⇝σ}.d_B(\rho) = \sup\{|\sigma|-|\rho| : \rho\leadsto\sigma\}.

For ρ∈Av⁡(B)\rho\in\operatorname{Av}(B) this belongs to Z≥0∪{∞}\mathbb{Z}_{\geq0} \cup\{\infty\}. Given ρ⇝σ\rho\leadsto\sigma, we call the entries of σ\sigma inherited from ρ\rho the root entries with respect to ρ\rho, or simply the root entries when ρ\rho is clear. The root gap of an inserted entry xx is the number of root entries appearing to the left of xx in σ\sigma.

The input to ExtendMax⁡B\operatorname{ExtendMax}_B is (ρ,k)(\rho,k), and the answer is Yes exactly when ρ\rho has an extension of depth kk. For enumeration, kk is encoded in unary. This is natural because an extension at depth kk has length ∣ρ∣+k|\rho|+k, so with a binary target even writing one output may require time exponential in the input length. On input (ρ,1k)(\rho,1^k), the extension enumeration problem EnumExt⁡B\operatorname{EnumExt}_B outputs all extensions of ρ\rho at depth kk, without repetitions. On input 1n1^n, the problem EnumAvoid⁡B\operatorname{EnumAvoid}_B is the special case ρ=ε\rho=\varepsilon and k=nk=n.

Proposition 2.1. For every fixed finite set of permutations BB,

ExtendMax⁡Bun∈P⟺EnumExt⁡B∈DelayP⟹EnumAvoid⁡B∈DelayP.\operatorname{ExtendMax}^{\mathrm{un}}_B \in\mathrm{P} \quad\Longleftrightarrow\quad \operatorname{EnumExt}_B \in\mathrm{DelayP} \quad\Longrightarrow\quad \operatorname{EnumAvoid}_B \in\mathrm{DelayP}.

Proof. Suppose that DBD_B is an algorithm that decides whether a given permutation τ\tau has an extension of depth jj in time polynomial in ∣τ∣+j|\tau|+j. On input (ρ,1k)(\rho,1^k), first execute DB(ρ,k)D_B(\rho,k) and terminate if the answer is No. Otherwise, traverse the subtree of the insert-maximum tree rooted at ρ\rho in depth-first order, stopping at level n:=∣ρ∣+kn := |\rho|+k. For each child σ\sigma of a visited permutation, descend to σ\sigma only if DB(σ,n−∣σ∣)D_B(\sigma,n-|\sigma|) returns Yes. At level nn, output the permutation.

The oracle tests ensure that only branches leading to the target level are explored. Since every extension has a unique path from ρ\rho, every required extension is output exactly once. Between consecutive outputs, the search backtracks and descends through at most 2k2k levels, considering at most n+1n+1 children at each level. Since each oracle call takes polynomial time in nn, the delay is polynomial. The same holds before the first output and after the last.

Conversely, a polynomial-delay enumerator decides extension existence in polynomial time by running until its first output or termination.

Finally, setting ρ=ε\rho=\varepsilon gives EnumAvoid⁡B∈DelayP\operatorname{EnumAvoid}_B \in\mathrm{DelayP}.

Output-polynomial avoider enumeration

An enumeration problem belongs to OutputP if its total running time is polynomial in the input size and the total size of the output.

Theorem 3.1. For every fixed finite set BB of permutations. EnumAvoidB∈_B \in OutputP.

Proof. Write aj:=∣Av⁡j(B)∣a_j := |\operatorname{Av}_j(B)| and A<n:=∑j=0n−1ajA_{<n} := \sum_{j=0}^{n-1} a_j. If B=∅B = \varnothing or ε∈B\varepsilon\in B then the statement is trivial, so let us assume that this is not the case. We first claim that A<nA_{<n} is bounded by a polynomial in nn and ana_n. The Kaiser–Klazar growth gap says that a permutation class either has polynomial growth or satisfies an≥λna_n \ge\lambda^n for all sufficiently large nn and some λ>1\lambda> 1 [14 Theorem 3.4]. In the first case the claim is immediate. In the second case, Marcus–Tardos gives a constant M>1M > 1 with aj≤Mja_j \le M^j for all jj [16 Corollary 2]. Choose an integer rr with M≤λrM \le\lambda^r. For all sufficiently large nn,

A<n≤∑j=0n−1Mj≤MnM−1≤anrM−1.A_{<n} \le\sum_{j=0}^{n-1} M^j \le\frac{M^n}{M-1} \le\frac{a_n^r}{M-1}.

References

  1. [1]Michael H. Albert and M. D. Atkinson. Simple permutations and pattern restricted permutations. Discrete Mathematics, 300:1–15, 2005. doi:10.1016/j.disc.2005.06.016.DOI
  2. [2]Michael H. Albert, Steve Linton, and Nik Ruškuc. The insertion encoding of permutations. The Electronic Journal of Combinatorics, 12:R47, 2005. doi:10.37236/1944.DOI
  3. [3]M. D. Atkinson, M. M. Murphy, and N. Ruškuc. Partially well-ordered closed sets of permutations. Order, 19(2):101–113, 2002. 10.1023/A:1016500300436.
  4. [4]Robert Brignall and Vincent Vatter. Labelled well-quasi-order for permutation classes. Combinatorial Theory, 2(3):Paper No. 14, 54, 2022. doi:10.5070/C62359178.DOI
  5. [6]Phan Thuan Do, Thi Thu Huong Tran, and Vincent Vajnorszki. Exhaustive generation for permutations avoiding (colored) regular sets of patterns. Discrete Applied Mathematics, 268:44–53, 2019. doi:10.1016/j.dam.2019.04.014.
  6. [7]W. M. B. Dukes, M. F. Flanagan, Toufik Mansour, and Vincent Vajnovszki. Combinatorial Gray codes for classes of pattern avoiding permutations. Theoretical Computer Science, 396(1–3):35–49, 2008. doi:10.1016/j.tcs.2007.12.002.DOI
  7. [8]Paul Erdős and George Szekeres. A combinatorial problem in geometry. Compositio Mathematica, 2:463–470, 1935.
  8. [9]Sylvain Guillemot and Dániel Marx. Finding small patterns in permutations in linear time. In Proceedings of the Twenty-Fifth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 82–101. SIAM, 2014. doi:10.1137/1.9781611973402.7.DOI
  9. [10]Tom Hanika. Forbidden permutation patterns and constraint satisfaction problems. Diplomarbeit, Technische Universität Dresden, Dresden, 2015.
  10. [11]Elizabeth Hartung, Hung P. Hoang, Torsten Mütze, and Aaron Williams. Combinatorial generation via permutation languages. I. fundamentals. Transactions of the American Mathematical Society, 375(4):2255–2291, 2022. doi:10.1090/tran/8199.DOI
  11. [12]Vít Jelínek, Michal Opler, and Pavel Valtr. Generalized coloring of permutations. Algorithmica, 86:2174–2210, 2024. doi:10.1007/s00453-024-01220-9.DOI
  12. [13]David S. Johnson, Mihalis Yannakakis, and Christos H. Papadimitriou. On generating all maximal independent sets. Information Processing Letters, 27(3):119–123, 1988. doi:10.1016/0020-0190(88)90065-8.DOI
  13. [14]Tomáš Kaiser and Martin Klazar. On growth rates of closed permutation classes. The Electronic Journal of Combinatorics, 9(2):R10, 2003. doi:10.37236/1682.DOI
  14. [15]William Kuszmaul. Fast algorithms for finding pattern avoiders and counting pattern occurrences in permutations. Mathematics of Computation, 87(310):987–1011, 2018. doi:10.1090/mcom/3216.
  15. [16]Adam Marcus and Gábor Tardos. Excluded permutation matrices and the Stanley–Wilf conjecture. Journal of Combinatorial Theory, Series A, 107(1):153–160, 2004. doi:10.1016/j.jcta.2004.04.002.DOI
  16. [17]Thomas J. Schaefer. The complexity of satisfiability problems. In Proceedings of the Tenth Annual ACM Symposium on Theory of Computing, STOC ’78, pages 216–226, New York, NY, USA, 1978. Association for Computing Machinery. doi:10.1145/800133.804350.DOI
  17. [18]Yann Strozecki. Enumeration complexity: Incremental time, delay and space. Habilitation thesis, Université de Versailles Saint-Quentin-en-Yvelines, 2021. arXiv:2309.17042, doi:10.48550/arXiv.2309.17042.
  18. [19]Vincent Vatter. Finitely labelled generating trees and restricted permutations. Journal of Symbolic Computation, 41(5):559–572, 2006. doi:10.1016/j.jsc.2005.10.003.DOI
  19. [20]Vincent Vatter. Permutation classes. In Miklós Bóna, editor, Handbook of Enumerative Combinatorics, pages 753–833. CRC Press, Boca Raton, 2015.

Paper details

vlnc:W_n9nv4uk8
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 7

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents