Permutation patterns and pattern avoidance have been intensively studied in combinatorics and computer science, going back at least to the seminal work of Knuth on stack-sorting (1968). Perhaps the most natural algorithmic question in this area is deciding whether a given permutation of length $n$ contains a given pattern of length $k$.
In this work we give two new algorithms for this well-studied problem, one whose running time is $n^{k/4 + o(k)}$, and a polynomial-space algorithm whose running time is the better of $O(1.6181^n)$ and $O(n^{k/2 + 1})$. These results improve the earlier best bounds of $n^{0.47k + o(k)}$ and $O(1.79^n)$ due to Ahal and Rabinovich (2000) resp. Bruner and Lackner (2012) and are the fastest algorithms for the problem when $k \in Ω(\log{n})$. We show that both our new algorithms and the previous exponential-time algorithms in the literature can be viewed through the unifying lens of constraint-satisfaction.
Our algorithms can also count, within the same running time, the number of occurrences of a pattern. We show that this result is close to optimal: solving the counting problem in time $f(k) \cdot n^{o(k/\log{k})}$ would contradict the exponential-time hypothesis (ETH). For some special classes of patterns we obtain improved running times. We further prove that $3$-increasing and $3$-decreasing permutations can, in some sense, embed arbitrary permutations of almost linear length, which indicates that an algorithm with sub-exponential running time is unlikely, even for patterns from these restricted classes.
We investigate rules which allow variable elimination in binary CSP (constraint satisfaction problem) instances while conserving satisfiability. We study variable-elimination rules based on the language of forbidden patterns enriched with counting and quantification over variables and values. We propose new rules and compare them, both theoretically and experimentally. We give optimised algorithms to apply these rules and show that each define a novel tractable class. Using our variable-elimination rules in preprocessing allowed us to solve more benchmark problems than without.
An active topic in the study of random constraint satisfaction problems (CSPs) is the geometry of the space of satisfying or almost satisfying assignments as the function of the density, for which a precise landscape of predictions has been made via statistical physics-based heuristics. In parallel, there has been a recent flurry of work on refuting random constraint satisfaction problems, via nailing refutation thresholds for spectral and semidefinite programming-based algorithms, and also on counting solutions to CSPs. Inspired by this, the starting point for our work is the following questi…
Recent developments in approximate counting have made startling progress in developing fast algorithmic methods for approximating the number of solutions to constraint satisfaction problems (CSPs) with large arities, using connections to the Lovasz Local Lemma. Nevertheless, the boundaries of these methods for CSPs with non-Boolean domain are not well-understood. Our goal in this paper is to fill in this gap and obtain strong inapproximability results by studying the prototypical problem in this class of CSPs, hypergraph colourings. More precisely, we focus on the problem of approximately coun…
A ternary Permutation-CSP is specified by a subset $Π$ of the symmetric group $\mathcal S_3$. An instance of such a problem consists of a set of variables $V$ and a multiset of constraints, which are ordered triples of distinct variables of $V.$ The objective is to find a linear ordering $α$ of $V$ that maximizes the number of triples whose ordering (under $α$) follows a permutation in $Π$. We prove that all ternary Permutation-CSPs parameterized above average have kernels with quadratic numbers of variables.
In the field of constraint satisfaction problems (CSP), promise CSPs are an exciting new direction of study. In a promise CSP, each constraint comes in two forms: "strict" and "weak," and in the associated decision problem one must distinguish between being able to satisfy all the strict constraints versus not being able to satisfy all the weak constraints. The most commonly cited example of a promise CSP is the approximate graph coloring problem--which has recently seen exciting progress [BKO19, WZ20] benefiting from a systematic algebraic approach to promise CSPs based on "polymorphisms," op…
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 permutat…
We give a simple combinatorial algorithm to deterministically approximately count the number of satisfying assignments of general constraint satisfaction problems (CSPs). Suppose that the CSP has domain size $q=O(1)$, each constraint contains at most $k=O(1)$ variables, shares variables with at most $Δ=O(1)$ constraints, and is violated with probability at most $p$ by a uniform random assignment. The algorithm returns in polynomial time in an improved local lemma regime: \[ q^2\cdot k\cdot p\cdotΔ^5\le C_0\quad\text{for a suitably small absolute constant }C_0. \] Here the key term $Δ^5$ improv…
We introduce tensor network contraction algorithms for counting satisfying assignments of constraint satisfaction problems (#CSPs). We represent each arbitrary #CSP formula as a tensor network, whose full contraction yields the number of satisfying assignments of that formula, and use graph theoretical methods to determine favorable orders of contraction. We employ our heuristics for the solution of #P-hard counting boolean satisfiability (#SAT) problems, namely monotone #1-in-3SAT and #Cubic-Vertex-Cover, and find that they outperform state-of-the-art solvers by a significant margin.
Permutation $σ$ appears in permutation $π$ if there exists a subsequence of $π$ that is order-isomorphic to $σ$. The natural question is to check if $σ$ appears in $π$, and if so count the number of occurrences. We know that for any fixed length~k, we can check if a given pattern of length k appears in a permutation of length n in time linear in n, but being able to count all such occurrences in $f(k)\cdot n^{o(k/\log k)}$ time would refute the exponential time hypothesis (ETH). This motivates a systematic study of the complexity of counting occurrences for different patterns of fixed small le…
We show that the two problems of computing the permanent of an $n\times n$ matrix of $\operatorname{poly}(n)$-bit integers and counting the number of Hamiltonian cycles in a directed $n$-vertex multigraph with $\operatorname{exp}(\operatorname{poly}(n))$ edges can be reduced to relatively few smaller instances of themselves. In effect we derive the first deterministic algorithms for these two problems that run in $o(2^n)$ time in the worst case. Classic $\operatorname{poly}(n)2^n$ time algorithms for the two problems have been known since the early 1960's. Our algorithms run in $2^{n-Ω(\sqrt{n…
A sample of n generic points in the xy-plane defines a permutation that relates their ranks along the two axes. Every subset of k points similarly defines a pattern, which occurs in that permutation. The number of occurrences of small patterns in a large permutation arises in many areas, including nonparametric statistics. It is therefore desirable to count them more efficiently than the straightforward ~O(n^k) time algorithm. This work proposes new algorithms for counting patterns. We show that all patterns of order 2 and 3, as well as eight patterns of order 4, can be counted in nearly linea…
Packet reordering is an important property of network traffic that should be captured by analytical models of the Transmission Control Protocol (TCP). We study a combinatorial problem motivated by RESTORED, a TCP modeling methodology that incorporates information about packet dynamics. A significant component of this model is a many-to-one mapping B that transforms sequences of packet IDs into buffer sequences, in a manner that is compatible with TCP semantics. We show that the following hold: 1. There exists a linear time algorithm that, given a buffer sequence W of length n, decides whether …
We show for a broad class of counting problems, correlation decay (strong spatial mixing) implies FPTAS on planar graphs. The framework for the counting problems considered by us is the Holant problems with arbitrary constant-size domain and symmetric constraint functions. We define a notion of regularity on the constraint functions, which covers a wide range of natural and important counting problems, including all multi-state spin systems, counting graph homomorphisms, counting weighted matchings or perfect matchings, the subgraphs world problem transformed from the ferromagnetic Ising model…
We address the problem of the number of permutations that can be sorted by two stacks in series. We do this by first counting all such permutations of length less than 20 exactly, then using a numerical technique to obtain nineteen further coefficients approximately. Analysing these coefficients by a variety of methods we conclude that the OGF behaves as $$S(z) \sim A (1 - μ\cdot z)^γ,$$ where $μ=12.45 \pm 0.15,$ $γ= 1.5 \pm 0.3,$ and $A \approx 0.02$.
We study the complexity of approximate counting Constraint Satisfaction Problems (#CSPs) in a bounded degree setting. Specifically, given a Boolean constraint language $Γ$ and a degree bound $Δ$, we study the complexity of #CSP$_Δ(Γ)$, which is the problem of counting satisfying assignments to CSP instances with constraints from $Γ$ and whose variables can appear at most $Δ$ times. Our main result shows that: (i) if every function in $Γ$ is affine, then #CSP$_Δ(Γ)$ is in FP for all $Δ$, (ii) otherwise, if every function in $Γ$ is in a class called IM$_2$, then for all sufficiently large $Δ$, #…
In this paper, we design efficient algorithms to approximately count the number of edges of a given $k$-hypergraph, and to sample an approximately uniform random edge. The hypergraph is not given explicitly, and can be accessed only through its colourful independence oracle: The colourful independence oracle returns yes or no depending on whether a given subset of the vertices contains an edge that is colourful with respect to a given vertex-colouring. Our results extend and/or strengthen recent results in the graph oracle literature due to Beame et al. (ITCS 2018), Dell and Lapinskas (STOC 20…
The Permutation Pattern Matching problem asks, given two permutations $σ$ on $n$ elements and $π$, whether $σ$ admits a subsequence with the same relative order as $π$ (or, in the counting version, how many such subsequences are there). This natural problem was shown by Bose, Buss and Lubiw [IPL 1998] to be NP-complete, and hence we should seek exact exponential time solutions. The asymptotically fastest such solution up to date, by Berendsohn, Kozma and Marx [IPEC 2019], works in $\mathcal{O}(1.6181^n)$ time. We design a simple and faster $\mathcal{O}(1.415^{n})$ time algorithm for both the d…
Counting the number of permutations of a given total displacement is equivalent to counting weighted Motzkin paths of a given area (Guay-Paquet and Petersen, 2014). The former combinatorial problem is still open. In this work, we show that this connection allows to construct efficient algorithms for counting and for sampling such permutations. These algorithms provide a tool to better understand the original combinatorial problem. A by-product of our approach is a different way of counting based on certain building sequences for Motzkin paths, which may be of independent interest.
For many constraint satisfaction problems, the algorithm which chooses a random assignment achieves the best possible approximation ratio. For instance, a simple random assignment for {\sc Max-E3-Sat} allows 7/8-approximation and for every $\eps >0$ there is no polynomial-time ($7/8+\eps$)-approximation unless P=NP. Another example is the {\sc Permutation CSP} of bounded arity. Given the expected fraction $ρ$ of the constraints satisfied by a random assignment (i.e. permutation), there is no $(ρ+\eps)$-approximation algorithm for every $\eps >0$, assuming the Unique Games Conjecture (UGC). In …
We give an improved algorithm for counting the number of $1324$-avoiding permutations, resulting in 5 further terms of the generating function. We analyse the known coefficients and find compelling evidence that unlike other classical length-4 pattern-avoiding permutations, the generating function in this case does not have an algebraic singularity. Rather, the number of 1324-avoiding permutations of length $n$ behaves as $$B\cdot μ^n \cdot μ_1^{n^σ} \cdot n^g.$$ We estimate $μ=11.60 \pm 0.01,$ $σ=1/2,$ $μ_1 = 0.0398 \pm 0.0010,$ $g = -1.1 \pm 0.2$ and $B =9.5 \pm 1.0.$