Fast Algorithms for Finding Pattern Avoiders and Counting Pattern Occurrences in Permutations

William Kuszmaul
9/28/2015
cs.DMcs.DSmath.CO

Official code: williamkuszmaul/patternavoidance (4 stars, MIT, last commit 2016-11-23).

Abstract

Given a set $Π$ of permutation patterns of length at most $k$, we present an algorithm for building $S_{\le n}(Π)$, the set of permutations of length at most $n$ avoiding the patterns in $Π$, in time $O(|S_{\le n - 1}(Π)| \cdot k + |S_{n}(Π)|)$. Additionally, we present an $O(n!k)$-time algorithm for counting the number of copies of patterns from $Π$ in each permutation in $S_n$. Surprisingly, when $|Π| = 1$, this runtime can be improved to $O(n!)$, spending only constant time per permutation. Whereas the previous best algorithms, based on generate-and-check, take exponential time per permutation analyzed, all of our algorithms take time at most polynomial per outputted permutation. If we want to solve only the enumerative variant of each problem, computing $|S_{\le n}(Π)|$ or tallying permutations according to $Π$-patterns, rather than to store information about every permutation, then all of our algorithms can be implemented in $O(n^{k+1}k)$ space. Using our algorithms, we generated $|S_5(Π)|, \ldots, |S_{16}(Π)|$ for each $Π\subseteq S_4$ with $|Π| > 4$, and analyzed OEIS matches. We obtained a number of potentially novel pattern-avoidance conjectures. Our algorithms extend to considering permutations in any set closed under standardization of subsequences. Our algorithms also partially adapt to considering vincular patterns.

View on arXivView PDF

Code Implementations(1)

MIT

Code for generating permutations avoiding a set of patterns, or counting pattern-hits in every permutation in S_n.

43C++, PythonJul 17, 20159 years agoMIT

Similar Papers

Cite this paper

@article{kuszmaul2015fast,
  title  = {Fast Algorithms for Finding Pattern Avoiders and Counting Pattern Occurrences in Permutations},
  author = {William Kuszmaul},
  year   = {2015},
  eprint = {1509.08216},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1509.08216}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1509.08216.svg)](https://codeofpaper.com/paper/1509.08216)

Discussion