Approximate Counting of Permutation Patterns

Omri Ben-Eliezer, Slobodan Mitrovic, Pranjal Srivastava

TL;DR

This paper introduces the first deterministic, near-linear time algorithm to approximately count permutation patterns of length up to $k=5$. By leveraging "Birgé decomposition"—a technique typically used in distribution testing—the authors prove that while exact counting is computationally "hard" (linked to the difficulty of counting cycles in graphs), a high-quality approximation can be achieved much faster, establishing a significant gap between exact and approximate complexity.

What Problem Does This Paper Address?

In the world of combinatorics and data analysis, a "permutation pattern" is a specific relative ordering of elements within a larger sequence. For example, finding the pattern "132" in the sequence $(10, 20, 50, 30)$ means looking for three indices $i < j < k$ such that their values follow the same relative order as $1, 3, 2$ (in this case, $10, 50, 30$).

Counting these patterns is vital for non-parametric statistics (testing if two variables are independent), ranking systems, and bioinformatics. However, as the pattern length $k$ grows, counting becomes incredibly difficult. For $k=4$, exact counting is known to be as hard as counting 4-cycles in a graph, which likely cannot be done in linear time. The authors ask: Can we break this "polynomial barrier" if we settle for a $(1 + \varepsilon)$-approximation instead of an exact count?

Methods

The authors combine classical data structures with a clever observation about monotonicity:

  1. Birgé Decomposition (Coresets for Monotone Functions): This is the paper's "secret sauce." If a sequence of numbers is monotone (always increasing or decreasing), you don't need to look at every number to approximate their sum; you only need to sample a logarithmic number of points.
  2. Structural Separators: Many patterns (like "2413") don't look monotone at first glance. The authors use "separators"—essentially vertical and horizontal lines in a 2D representation of the permutation—to split the problem into sub-regions where the counts do become monotone.
  3. Approximate 2D Segment Trees: To handle 5-patterns, the authors developed a specialized data structure that can approximately count "12-patterns" (increasing pairs) within any arbitrary axis-aligned rectangle in $O(\text{polylog } n)$ time.
  4. Computer-Assisted Case Analysis: While the proofs for $k=4$ are manual, the sheer number of cases for $k=5$ (512 configurations) required a computer-assisted approach to verify that their "recipe" for approximation works for every possible pattern.

Datasets

As a theoretical computer science paper, it does not use standard machine learning datasets. Instead:

  • Synthetic Permutations: The algorithm is designed to work on any sequence $f: [n] \to \mathbb{R}$.
  • Software Verification: The authors provided a GitHub repository containing the source code used to enumerate and verify the 512 cases for $k=5$ patterns.

Key Insights and Ideas

  • Hidden Monotonicity: The most profound insight is that even if a permutation is chaotic, the function that counts how many ways a pattern can be completed is often monotone relative to the position or value of the elements you fix.
  • The Exact vs. Approximate Gap: The paper proves a "polynomial separation." For certain 4-patterns, exact counting takes $n^{1+\Omega(1)}$ time (under standard complexity assumptions), but approximation takes only $\tilde{O}(n)$ time.
  • Riemann Integration Analogy: The use of Birgé decomposition can be thought of as a discrete version of Riemann integration for monotone functions, allowing the algorithm to skip vast amounts of computation while maintaining a strict error bound.

Key Results

  • Near-Linear Approximation: For any pattern of length $k \leq 5$, the algorithm returns a $(1 + \varepsilon)$-approximation in $n \cdot (\varepsilon^{-1} \log n)^{O(1)}$ time.
  • Efficient Enumeration: The authors also provide an algorithm to list $t$ copies of a pattern in $(n + t) \cdot \log^{O(1)} n$ time.
  • Data Structure Performance: Their new 2D segment tree for 12-copy counts achieves near-linear preprocessing time and polylogarithmic query time, which is a significant improvement over what is possible for exact 12-range counting.

Limitations and Future Work

  • Small $k$ Constraint: The current techniques are "ad hoc" for $k \leq 5$. Extending this to general $k$ remains a major open challenge. The authors conjecture that approximate counting is fundamentally easier than exact counting for all $k$.
  • Deterministic vs. Randomized: While this algorithm is deterministic, the authors note that a randomized approach using "stratified sampling" might be simpler to implement, though it wouldn't provide the same worst-case guarantees.
  • Lower Bounds: There are currently no non-trivial lower bounds for approximate counting. We don't yet know if there's a pattern that requires more than near-linear time to approximate.

Summary updated

BibTeX
@inproceedings{beneliezer2026approximate,
  author = {Omri Ben-Eliezer and Slobodan Mitrovic and Pranjal Srivastava},
  title = {{Approximate Counting of Permutation Patterns}},
  booktitle = {SODA},
  year = {2026},
  doi = {10.1137/1.9781611978971.210},
}

Loading related content...

Figure