A permutation is a sequence in which each number from the set appears exactly once. We then say that a permutation contains a permutation , if has a subsequence of length whose elements have the same relative order as the elements of (see Section 2 for a more formal definition). If does not contain , we say that avoids .
An essential algorithmic problem involving permutations is Permutation Pattern Matching (PPM): Given a permutation (‘pattern’) of size and (‘text’) of size , does contain ? Bose, Buss and Lubiw  have shown that PPM is NP-complete. This result has motivated a study of various variants of PPM, in particular to obtain the best possible runtime dependence on . Guillemot and Marx  provided the break-through result in this direction by establishing the fixed-parameter tractability of PPM in terms of the pattern length with algorithm running in time. The first phase of their algorithm finds a suitable decomposition that relies on the proof of Stanley-Wilf conjecture given by Marcus and Tardos . Subsequently, Fox  refined the results by Marcus and Tardos and thereby reduced the complexity of the algorithm to .
Several algorithms also exist whose runtimes depend on different parameters than the length of . Bruner and Lackner  described an algorithm for PPM with run time where is the number of consecutive monotone sequences needed to obtain via concatenation. Ahal and Rabinovich  designed an algorithm for PPM that runs in time where is a certain graph associated to the pattern and denotes the treewidth of . Later Jelínek, Opler and Valtr  introduced a related parameter , called the grid-width of , and showed that is equivalent to up to a constant and thereby implying an algorithm for PPM running in time .
Another approach to tackling the hardness of PPM is to restrict the choice of pattern to a particular permutation class , where a permutation class is a set of permutations such that for every , every permutation contained in belongs to as well.
|-Pattern Permutation Pattern Matching (-Pattern PPM)|
|Input:||A pattern of size and a permutation of size .|
|Question:||Does contain ?|
For a permutation , we let denote the class of permutations avoiding . Notice that -Pattern PPM simply reduces to finding the longest increasing subsequence of , which is a well-known problem and can be solved in time . Bose, Buss and Lubiw  showed that -Pattern PPM can be solved in polynomial time if is the class of the so-called separable permutations. Further improvements were given by Ibarra , Albert et al.  and by Yugandhar and Saxena . Recently, Jelínek and Kynčl  completely resolved the hardness of -Pattern PPM for classes avoiding a single pattern. They proved that -Pattern PPM is polynomial-time solvable for and NP-complete otherwise.
Lately, a new type of permutation classes has been gaining a lot of attention. The grid class of a matrix whose entries are permutation classes, denoted by , is a class of permutations admitting a grid-like decomposition into blocks that belong to the classes . If moreover contains only and we say that is a monotone grid class. To each matrix we also associate a graph , called the cell graph of . We postpone their full definitions to Section 2.
Monotone grid classes were introduced partly by Atkinson, Murphy and Ruškuc  and in full by Murphy and Vatter  who showed that a monotone grid class is partially well-ordered if and only if is a forest. Brignall  later extended their results to a large portion of general grid classes. General grid classes themselves were introduced by Vatter  in his paper investigating the growth rates of permutation classes. Since then the grid classes played a central role in most subsequent works on growth rates of permutation classes [4, 27]. Bevan [8, 9] tied the growth rates of grid classes to algebraic graph theory.
Given the prominent role of grid classes in recent developments of the permutation pattern research, it is only natural to investigate the hardness of searching patterns that belong to a grid class. Neou, Rizzi and Vialette  designed a polynomial-time algorithm solving -Pattern PPM when is the class of the so-called wedge permutations, which can be also described as a monotone grid class. Consequently, Neou  asks at the end of his thesis about the hardness of -Pattern PPM for a monotone grid class .
In Section 3, we answer the question of Neou by proving that for a monotone grid class , the problem -Pattern PPM is polynomial-time solvable if the cell graph is a forest, NP-complete otherwise.
In Section 4, we further extend our results to matrices whose every entry is a permutation class of bounded grid-width. We prove that for such grid classes, -Pattern PPM is polynomial-time solvable if is a forest which does not contain a certain type of path, and NP-complete otherwise.
A permutation of length is a sequence in which each element of the set appears exactly once. When writing out short permutations explicitly, we shall omit all punctuation and write, e.g., for the permutation . The permutation diagram of is the set of points in the plane. Note that we use Cartesian coordinates, that is, the first row of the diagram is at the bottom. We blur the distinction between permutations and their permutation diagrams, e.g., we shall refer to ‘the point set ’ rather than ‘the point set of the diagram of the permutation ’.
For a point in the plane, we denote its first coordinate as , and its second coordinate as . A subset of a permutation diagram is isomorphic to a subset of a permutation diagram if there is a bijection such that for any pair of points of we have if and only if , and if and only if . A permutation of length contains a permutation of length , if there is a subset of isomorphic to the permutation diagram of . Such a subset is then an occurrence (or a copy) of in . If does not contain , we say that avoids .
A permutation class is a set of permutations with the property that if is in , then all the permutations contained in are in as well. For a permutation , we let denote the class of -avoiding permutations. We shall sometimes use the symbols and as short-hands for the class of increasing permutations and the class of decreasing permutations .
For a permutation of length the reverse of is the permutation , the complement of is the permutation , and the inverse of is the permutation satisfying . We let , and denote the reverse, complement and inverse of , respectively. For a permutation class , we let denote the set , and similarly for and . Note that , and are again permutation classes.
A permutation of length is a horizontal alternation if all the even entries of
precede all the odd entries of, i.e., there are no indices such that is odd and is even. A permutation is a vertical alternation if is a horizontal alternation.
Griddings and grid classes.
For two sets and of numbers, we write if every element of is smaller than any element of . In particular, both and holds for any .
A matrix whose entries are permutation classes is called a gridding matrix. Moreover, if the entries of belong to the set then we say that is a monotone gridding matrix. A -gridding of a permutation of length are two sequences of (possibly empty) disjoint integer intervals and such that both and are equal to . We call the set an -cell of . An -gridding of a permutation is a -gridding such that the restriction of to the -cell is isomorphic to a permutation from the class . If possesses an -gridding, then is said to be -griddable and equipped with a fixed -gridding is called an -gridded permutation. We let be the class of -griddable permutations. Note that for consistency with our Cartesian numbering convention, we number the rows of a matrix from bottom to top.
The cell graph of the gridding matrix , denoted , is the graph whose vertices are the cells of that contain an infinite class, with two vertices being adjacent if they share a row or a column of and all cells between them are finite or empty. A proper turning path in is a path such that no three consecutive cells of share the same row or column. See Figure 1.
An interval family is a set of pairwise disjoint integer intervals. The intervalicity of a set , denoted by , is the size of the smallest interval family whose union is equal to . For a point set in the plane, let denote its projection on the -axis and similarly its projection on the -axis. We write and as short for and , respectively. For a subset of the permutation diagram, the grid-complexity of is the maximum of and .
A grid tree of a permutation of length is a rooted binary tree with leaves, each leaf being labeled by a distinct point of the permutation diagram. Let denote the point set of the labels on the leaves in the subtree of rooted in . The grid-width of a vertex in is the grid-complexity of , and the grid-width of , denoted by , is the maximum grid-width of a vertex of . Finally, the grid-width of a permutation , denoted by , is the minimum of over all grid trees of .
We also consider a linear version of this parameter. We say that a rooted binary tree is a caterpillar if each vertex is either a leaf or has at least one leaf as a child. The path-width of a permutation , denoted by , is the minimum of over all caterpillar grid trees of .
We now provide a useful alternative definition of path-width. For permutations and of length , the path-width of in -ordering, denoted by is the maximum grid-complexity attained by a set for some .
A permutation of length has path-width if and only if the minimum value of over all permutations of length is exactly .
Suppose that as witnessed by a caterpillar grid tree . Observe that all leaves of except for the deepest pair lie in different depths. Define to simply order the labels by the depths of their leaves, defining arbitrarily the order of the two deepest leaves. Then every set corresponds exactly to the set for some vertex of .
In order to prove the other direction, we define a sequence of caterpillar trees in the following way. Let be a single vertex labeled by . For , let be the binary rooted tree with left child a leaf labeled by and right child the tree . The tree is a caterpillar grid tree of and for every inner vertex the set is equal to for some . The claim follows. ∎
Ahal and Rabinovich  designed an algorithm for PPM that runs in time where is a certain graph associated to the pattern and denotes the treewidth of . The following theorem follows by combining this algorithm with the result of Jelínek et al.  who showed that up to a constant, is equivalent to .
Importantly, Theorem 2 implies that -Pattern PPM is decidable in polynomial time whenever the class has bounded grid-width. In fact, we obtain all the polynomial-time solvable cases of -Pattern PPM in this paper via showing that has bounded grid-width.
3 Monotone grid classes
This section is dedicated to proving that the complexity of -Pattern PPM is for a monotone gridding matrix determined by whether contains a cycle.
For a monotone gridding matrix one of the following holds:
Either is a forest, has bounded path-width and -Pattern PPM can be decided in polynomial time, or
contains a cycle, has unbounded grid-width and -Pattern PPM is NP-complete.
A consistent orientation of a monotone gridding matrix is a pair of functions such that , and for every , the value is positive if and negative if .
Intuitively speaking, the purpose of the consistent orientation is to ‘orient’ each nonempty cell of a monotone gridding matrix, so that -cells are oriented towards the top-right or towards the bottom-left, while the -cells are oriented towards the top-left or the bottom-right. The orientation is consistent in the sense that in a given column , either all the nonempty cells are oriented left-to-right (if ) or right-to-left (if ), while in a row , they are all oriented bottom-to-top (if ) or top-to-bottom (if ). See Figure 2 (left) for an example of a gridding matrix with a consistent orientation.
Not every monotone gridding matrix has a consistent orientation: consider, e.g., a gridding matrix with three cells equal to and one cell equal to . However, Albert et al.  observed that we can transform a given gridding matrix into another, similar gridding matrix that has a consistent orientation. Let be a monotone gridding matrix and a positive integer. The refinement of is the matrix obtained from by replacing each -entry by a diagonal matrix with all the non-empty entries equal to , each