• Aucun résultat trouvé

7 Vincular and bivincular separable patterns

Dans le document Pattern Matching for Separable Permutations (Page 23-31)

This subsection is devoted to vincular and bivincular separable patterns. The problem isW[1]-complete for parameter the size of the pattern. As for regular pattern adding constraints can reduce the complexity of the problem. We prove that detecting a vincular or a bivincular separable pattern in a permutation is polynomial time solvable. To the best of our knowledge, this is the first time the pattern matching problem is proved to be tractable for a generalization of separable patterns. Since a vincular pattern is a bivincular pattern, we focus on bivincular patterns.

Recall that bivincular patterns generalize classical pattern even further than vincular patterns. Indeed, in bivincular pattern, not only positions but also val-ues of elements involved in an occurrence may be forced to be adjacent (see

Fig. 8: From left to right, the bivincular pattern σ = 1234x2143q, An occurrence of σ in 3216745, An occurrence of 2143 in 3216745 but not an occurrence ofσin 3216745 because the point (1,3) and (5,7) are in the forbidden area.

+ −

Fig. 9: From left to right the permutation 342561 (see fig 4) and the minimal rectangles of the nodes 342 and 56, the rectangles of the children of a negative node, the rectangles of the children of a positive node.

Section 2). Leteσ= (σ, X, Y) be a separable bivincular pattern2 of lengthkand π ∈Sn. We represent bivincular patterns (as well as occurrences of bivincular patterns in permutations) by diagrams. Such a diagram consists in the set of points at coordinates (i, σ[i]) drawn in the plane together with forbidden regions denoting adjacency constraints. A vertical forbidden region between two points denotes the fact that the occurrences of these two points must be consecutive in positions. In a similar approach, an horizontal forbidden region between two points denotes the fact that the occurrences of these two points must be con-secutive in value. Now given a permutationπ and a bivincular patternσ, The rational for introducing these augmented diagrams stems from the following fact:

πcontains an occurrence of a bivincular patterneσif there exists a set of points in the diagram ofπthat is order-isomorphic toσand if the forbidden region do not contain any point (see Figure 8).

The algorithm of section 3 cannot be used to find an occurrence of a bivin-cular pattern as we do not have any control on the position and the value of matching element.

Proposition 6. Given a permutation π of lengthn and a bivincular separable pattern σ of lengthk, there exists an O(kn6)time and O(kn4) space algorithm to decide whether σoccurs inπ.

2 This is a shortcut forσbeing separable and (σ, X, Y) being bivincular.

Given a bivincular separable permutation patterneσ, and a subsequenceσ0, we define the bivincular permutation σe0 has the binvincular permutation with the element ofσ0, with top line the top line of eσwhere we remove the elements not inσ0 and with bottom line the elements of the node wheremandm+ 1 are underlined if and only if mand m+ 1 are element of σ0 and mand m+ 1 are underlined in eσ, moreover:

– ifσ[i] is the bottommost element ofσ0 andσ[i−1]σ[i] orxσ[i] then we add the bottom left corner.

– ifσ[i] is the toptommost element ofσ0 andσ[i]σ[i+ 1] orσ[i]ythen we add the bottom right corner.

– ifσ[i] is the leftmost element ofσ0 andσ[i−1]σ[i] orpσ[i] then we add the top left corner.

– ifσ[i] is the leftmost element ofσ0 andσ[i−1]σ[i] orσ[i]qthen we add the top right corner.

Especially (remember thatσ(v) represent the subsequence embedded in the node v) we represent byeσ(v) the bivincular pattern formed by the subsequenceσ(v).

The idea of the algorithm is to use the separable tree ofσto find an occur-rence and a second trick: to find an occuroccur-rence ofeσ, we need to find an occurrence for the (permutation embedded in) its left child and the (permutation embedded in) its right child, such that those two permutations are compatible which each other. More precisely, the occurrences must be contain in rectangles such that the rectangle of the occurrence of left child is on the left of the rectangle of the occurrence of the right child, and one has to be above the other depending whetherσis decomposed in direct or skew sum. Note that this is enough to find a occurrence forσ, but notσ. Indeed the constraints on values and positions aree not respected.

This is where the second trick comes handy: remark that given that σe = σfα⊕fσβ, if the topmost, bottommost, leftmost and rightmost elements of σfα (resp.σfβ) are respectively in the top, bottom, left and right edges of the rectangle of the occurrence of σfα (resp. σfβ) and if the two rectangle are consecutive in the x-coordinate (the first minimal rectangle end atxand the second minimal rectangle start atx+ 1), then the matching of the right most element ofσfαand the matching of the left most element ofσfβare consecutive in index. In the same fashion, if the rectangles are consecutive in the y-coordinate (the first minimal rectangle end at y and the second minimal rectangle start at y+ 1), then the matching of the top most element of σfα and the matching of the bottom most element ofσfβ are consecutive in value.

The above remark allow us to take care of the constraint value between the bottommost element of σfβ and the topmost element ofσfα and the constraint position between the leftmost element of fσβ and the rightmost element ofσfα.

Moreover remark that an occurrence of σfα (resp. σfβ) take care of all con-straint on value and position of the elements inσα(resp.σβ) except for it topmost and rightmost (resp. bottommost and leftmost) elements. So the only constraint left are on those elements, be we can take care of them by positioning the rect-angle correctly.

In the following, ifuis a leaf such thatσ[i] =σ(u) then we writeσ(u+ 1) to representσ[i+ 1] andσ(u−1) to representσ[i−1].

The pattern matching problem with bivincular permutation can be solved by the following family of subproblems : For every nodev of Tσ, for every two i, j∈[n] withi≤j, for every lower and upper bound lb,ub ∈[n] with lb≤ub, which form a rectangle with left bottom corner (i,lb) and with right top corner (j,ub), we want to decide whether the rectangle contains an occurrence ofσ(v),e which give us the notation

T rue if there exists an occurence of the bivincular pattern eσ(v) in πwhere every element are contains

in the rectangle ((i,lb),(j,ub)).

F alse otherwise

By abuse of language, we say that eσ(v) occurs in ((i,lb),(j,ub)). This problem can be solve by the following induction:

Base:Ifv is a leaf then :

A leaf occurs in ((i,lb),(j,ub)) if and only if the rectangle is not empty. This is what the first condition is testing. The fourth next conditions assure that the matched element is on an edge of ((i,lb),(j,ub)). For example if σ(v)σ(v+ 1) then the matched element must be on the right edge, and intuitively σ(v+ 1) will be on the left edge of the ”next” rectangle.

Step. Herei < j and lb<ub and we let vL and vR stands for the left and right child ofv respectively.

Suppose that σ(v) occurs in ((i,lb),(j,ub)), and that v is a positive node.

Soσ(v) =σ(vL)⊕σ(vR), in other wordsσ(v) forms a stair up of two rectangles and so must the occurrence ofσ(v). So an occurrence ofσ(v) is composed by a left rectangle that contains the occurrence of σ(vL) and a right rectangle that contains the occurrence ofσ(vR).

To find whetherσ(v) occurs in ((i,lb),(j,ub)) we just have to find whether such occurrence of σ(vL) andσ(vR) exists. We can do so by trying every pair of such rectangle, but to reduce the number of pair to test and to control the

i ι jlb b ub

Fig. 10: What the pair of rectangle looks like.

position and value of the elements of the occurrence we require that the left rectangle share the same bottom edge and the same left edge as the rectangle ((i,lb),(j,ub)) ie the left rectangle is ((i,lb),(∗,∗)), the right rectangle share the same top edge and the same right edge as rectangle ((i,lb),(j,ub)) ie the right rectangle is ((∗,∗),(j,ub)) and that the left rectangle is consecutive in x and y coordinate to the right rectangle. In other words, we will try to find an occurrence ofσ(vL) andσ(vR) in every pair of rectangle ((i, ι−1),(lb, b−1) and ((ι, j),(b,ub)), see Figure 10. In notation this gives us:

PMBv,i,j,lb,ub= _

ι∈(i,j]

b∈(lb,ub]

PMBvL,i,ι−1,lb,b−1∧PMBvR,ι,j,b,ub

The case wherev is a negative node can be dealt with symmetry:

PMBv,i,j,lb,ub= _

ι∈(i,j]

b∈(lb,ub]

PMBvL,i,ι−1,b−1,ub∧PMBvR,ι,j,lb,b

If there is no condition on position nor on value, this algorithm solves the pattern matching problem: If σ = σα⊕σβ, then every element of σα is left and below every element ofσβ. Moreover if there is an occurrence ofσαand an occurrence of σβ such that the elements of the occurrence of σα are left below the elements of the occurrence ofσβ then there exists an occurrence ofσ in π.

More formally we have to check every case possible, and to whether or not the element really occur on the edges.

For the constraints on position and value, intuitively, Whenever we have σ(v)σ(v0),and w as the deepest ancestor of v and v0, σ(v) will be matched to the right edge of the left rectangle andσ(v0) will be matched to the left edge of the right rectangle so that σ(v) and σ(v0) are consecutive in index. Likewise if (σ(v))σ(v0),σ(v) will be matched to the top edge of the left rectangle andσ(v0) will be matched to the bottom edge of the right rectangle so thatσ(v) andσ(v0) are consecutive in value. See Figure 12). More

Position Constraint. There are 3 types of position constraint added by bivincular permutation.

σ(v)

σ(v0)

i ι jlb

b ub

Fig. 11: The matching elements ofσ(v) andσ(v0) are consecutive in value if and only ifσ(v) is matched to b−1 andσ(v0) is matched tob.

σ(v) σ(v0)

i ι jlb

b ub

Fig. 12: The matching element ofσ(v) and σ(v0) are consecutive in position if and only ifσ(v) is matched to π[ι−1] andσ(v0) is matched toπ[ι].

– If xσ[1] then the leftmost element of σ must be matched to the leftmost element ofπ (σ[1] occurs inπ[1] in an occurrence ofσ in π). Remark that the leaf v such that σ(v) = σ[1] is the leftmost ancestor of rσ. Note that the rectangle of a left child shares the same left edge as the rectangle of his father (by induction), plus this is solved in the base case and the base case asks to the matched element to be on its left edge, finally note that the main problem hasx= 1 for its left edge.

– The conditionσ[nσ]y follows the same idea as the condition xσ[1].

– Ifσ(v)σ(v0) (and thusσ(v+ 1) =σ(v0) andσ(v) =σ(v0−1) ) then the index of the occurrence of σ(v) andσ(v0) must be consecutive. In other words if σ(v) occurs in π[j] then σ(v0) must occur in π[j + 1]. Let w be the first common ancestor ofv and v0 and wL be the left child ofw andwR be the right child ofw. First note thatv is the rightmost ancestor of wL and thus the rectangle ofv shares the same right edge as the rectangle ofwL, plusv0 is the leftmost ancestorwRand thus the rectangle ofv0 shares the same left edge as the rectangle ofwR. Moreover those cases are solved as base cases and the base case asks to the element matching v to be on its right edge, and to the element matchingv0 to be on its left edge. Finally remark that the pair of rectangles of two brothers is consecutive in the x-coodinate (by induction).

Before diving into the value constraints, we highlight a property.

Fig. 13: ifv occurs in the dotted rectangle thenuoccurs in the bold rectangle

Property 4. Given a nodevand a leafu, such thatσ(u) is the maximal (respec-tively minimal) element of σ(v) then if v occurs in ((i,lb),(j,ub)) then there exists i ≤ ι ≤ ι0 ≤ j, and lb ≤ b ≤ub and uoccurs in ((ι, b),(ι0,ub)) (resp.

((ι,lb),(ι0, b))).

In other words ifvoccurs in a rectangleRanduis the leaf with the maximal element ofσ(v) then there exists an occurrence ofuincluded in a rectangle that shares the same top edge as R (see fig 13). Especially if PMBv,i,j,lb,ub is true then PMBu,ι,ι0,b,ub is true.

Proof. We focus on proving the assertion in the case whereσ(u) is the maximal element of σ(v), the other case can be dealt by symmetry. Suppose that the assertion is false. If the rectangle of ucan not have the same top edge as the rectangle ofv it means that there exists a rectangle in between, in other words there exists a value bigger thanσ(u) which is not possible.

Value Constraint. There are 3 types of value constraint added by bivincular permutation.

– If pσ(v) (and thus σ(v) = 1) then the minimal value of σ must occur in the minimal value ofπ. By property 4, the rectangle of σ(v) has the same bottom edge as the rectangle ofσ(rσ), plus this is solved in the base case and the base case asks to the matching element to be on the bottom edge, finally the rectangle ofrσ hasy= 1 as its bottom edge .

– Theσ(v)q follows the same idea aspσ(v).

– If σ(v)σ(v0) (and thus σ(v0) = σ(v) + 1) then the occurrence of σ(v) and σ(v0) must be consecutive. In other words if σ(v) occurs in π[j] thenσ(v0) must occur inπ[j] + 1. Letwbe the first common ancestor ofv andv0. Let wL be the left child of wandwR be the right child of w. Suppose thatwis positive then v is a child of wL and v0 is a child of wR. First remark that σ(v) is the the maximal element of σ(wL), otherwise σ(v) and σ(v0) would not be consecutive. Thus by property 4, the rectangle ofσ(v) has the same top edge as the rectangle ofσ(wL). Plusσ(v0) is the the minimal element of σ(wR), otherwiseσ(v) andσ(v0) would not be consecutive. Thus by property 4, the rectangle ofσ(v) has the same bottom edge as the rectangle ofσ(wR).

Moreover this is solved in the base case and the base case asks the element matchingσ(v) to be on its top edge and the element matchingσ(v0) to be on its bottom edge. Finally remark that the pair of rectangles of two brothers are consecutive in the y-coordinate (by induction). We can prove the same by symmetry ifwis negative.

So at the end of the algorithm we can decide whetherσeoccurs inπ. Finally, the algorithm haskn4 different cases, and each case try every pair of rectangle in constant time (by dynamic programming), so each case takes O(n2) time to solve. This gives us an O(kn6) time andO(kn4) space algorithm.

Acknowledgments

We thank the anonymous reviewers whose comments and suggestions helped improve and clarify this manuscript.

References

1. S. Ahal and Y. Rabinovich,On Complexity of the Subpattern Problem, SIAM Jour-nal on Discrete Mathematics22(2008), no. 2, 629–649.

2. M.H. Albert, R.E.L. Aldred, M.D. Atkinson, and D.A. Holton,Algorithms for pat-tern involvement in permutations, Proc. Inpat-ternational Symposium on Algorithms and Computation (ISAAC), Lecture Notes in Computer Science, vol. 2223, 2001, pp. 355–366.

3. D. Avis and M. Newborn,On pop-stacks in series, Utilitas Mathematica19(1981), 129–140.

4. P. Bille and I.L. Gørtz,The tree inclusion problem: In linear space and faster, ACM Trans. Algorithms7(2011), no. 3, 38.

5. P. Bose, J.F.Buss, and A. Lubiw,Pattern matching for permutations, Information Processing Letters65(1998), no. 5, 277–283.

6. M. Bouvel, D. Rossin, and S. Vialette,Longest common separable pattern between permutations, Proc. Symposium on Combinatorial Pattern Matching (CPM), Lon-don, Ontario, Canada (B. Ma and K. Zhang, eds.), Lecture Notes in Computer Science, vol. 4580, 2007, pp. 316–327.

7. M.-L. Bruner and M.Lackner, A fast algorithm for permutation pattern match-ing based on alternatmatch-ing runs, 13th Scandinavian Symposium and Workshops on Algorithm Theory (SWAT), Helsinki, Finland (F.V. Fomin and P. Kaski, eds.), Springer, 2012, pp. 261–270.

8. T.H. Cormen, C.E. Leiserson, R.L. Rivest, and C. Stein,Introduction to algorithms, third ed., MIT Press, Cambridge, 2009.

9. S. Giraudo and S. Vialette,Unshuffling permutations, 12th Latin American Theo-retical Informatics Symposium (LATIN), Lecture Notes in Computer Science, no.

9644, Springer, 2016, pp. 509–521.

10. S. Guillemot and D. Marx,Finding small patterns in permutations in linear time, Proceedings of the Twenty-Fifth Annual ACM-SIAM Symposium on Discrete Al-gorithms (SODA), Portland, Oregon, USA (C. Chekuri, ed.), SIAM, 2014, pp. 82–

101.

11. L. Ibarra,Finding pattern matchings for permutations, Information Processing Let-ters61(1997), no. 6, 293–295.

12. P. Kilpel¨ainen and H. Manilla,Ordered and unordered tree inclusion, SIAM J. on Comput.24(1995), no. 2, 340–356.

13. S. Kitaev,Patterns in permutations and words, Springer-Verlag, 2013.

14. D. Rossin and M. Bouvel,The longest common pattern problem for two permuta-tions, Pure Mathematics and Applications17(2006), 55–69.

15. V. Vatter, Permutation classes, Handbook of Enumerative Combinatorics (M. B´ona, ed.), Chapman and Hall/CRC, 2015, pp. 753–818.

Dans le document Pattern Matching for Separable Permutations (Page 23-31)

Documents relatifs