A Fast Algorithm for Permutation Pattern Matching Based on Alternating Runs Marie-Louise Bruner and Martin Lackner Vienna University of Technology July 6, 2012 SWAT 2012, Helsinki M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 1 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. Does 53142 contain 231 as a pattern? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. Does 53142 contain 231 as a pattern? X (342 is a matching) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. Does 53142 contain 231 as a pattern? X (342 is a matching) Does 53142 contain 123 as a pattern? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. Does 53142 contain 231 as a pattern? X (342 is a matching) Does 53142 contain 123 as a pattern? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. Does 53142 contain 231 as a pattern? X (342 is a matching) Does 53142 contain 123 as a pattern? Does 53142 contain 4231 as a pattern? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Permutation patterns A permutation T (the text) contains P as a pattern if we can find a subsequence of T that is order-isomorphic to P. Does 53142 contain 231 as a pattern? X (342 is a matching) Does 53142 contain 123 as a pattern? Does 53142 contain 4231 as a pattern? X (5342 is a matching) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 2 Enumerative combinatorics Theorem The n-permutations that do not contain the pattern 123 are counted by the n-th Catalan number. M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 3 Enumerative combinatorics Theorem The n-permutations that do not contain the pattern 123 are counted by the n-th Catalan number. The same holds for every other pattern of length 3. M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 3 Enumerative combinatorics Theorem The n-permutations that do not contain the pattern 123 are counted by the n-th Catalan number. The same holds for every other pattern of length 3. Stanley-Wilf conjecture, shown by Marcus and Tardos (2004) For every permutation P there is a constant c such that the number of n-permutations that do not contain P as a pattern is bounded by c n . M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 3 Permutation Pattern Matching Permutation Pattern Matching (PPM) Instance: A permutation T of length n (the text) and a permutation P of length k ≤ n (the pattern). Question: Is there a matching of P into T ? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 4 Permutation Pattern Matching Permutation Pattern Matching (PPM) Instance: A permutation T of length n (the text) and a permutation P of length k ≤ n (the pattern). Question: Is there a matching of P into T ? 1993 (Bose, Buss, Lubiw): PPM is in general NP-complete. M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 4 Tractable cases of PPM I Pattern avoids both 3142 and 2413 M.L. Bruner, M. Lackner A Fast Algorithm for PPM O(kn4 ) July 6, 2012 5 Tractable cases of PPM I Pattern avoids both 3142 and 2413 I P = 12 . . . k or P = k . . . 21 M.L. Bruner, M. Lackner A Fast Algorithm for PPM O(kn4 ) O(n log log n) July 6, 2012 5 Tractable cases of PPM I Pattern avoids both 3142 and 2413 I P = 12 . . . k or P = k . . . 21 I P has length at most 4 M.L. Bruner, M. Lackner O(kn4 ) O(n log log n) O(n log n) A Fast Algorithm for PPM July 6, 2012 5 Tractable cases of PPM I Pattern avoids both 3142 and 2413 I P = 12 . . . k or P = k . . . 21 I P has length at most 4 I Pattern and Text avoid 321 M.L. Bruner, M. Lackner O(kn4 ) O(n log log n) O(n log n) A Fast Algorithm for PPM O(k 2 n6 ) July 6, 2012 5 The general case Anything better than the O∗ (2n ) runtime of brute-force search? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 6 Parameterized Complexity Theory Idea: confine the combinatorial explosion to a parameter of the input M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 7 Parameterized Complexity Theory Idea: confine the combinatorial explosion to a parameter of the input Fixed-parameter tractability A problem is fixed-parameter tractable with respect to a parameter k if there is a computable function f and an integer c such that there is an algorithm solving the problem in time O(f (k) · |I |c ). M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 7 Alternating runs 12 11 10 9 8 7 6 5 4 3 2 1 1 8 12 (up), 4 (down), 7 11 (up), 6 3 2 (down), 9 (up), 5 (down), 10 (up) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 8 Alternating runs 12 11 10 9 8 7 6 5 4 3 2 1 1 8 12 (up), 4 (down), 7 11 (up), 6 3 2 (down), 9 (up), 5 (down), 10 (up) Notation run(π)...the number of alternating runs in π, M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 8 The alternating run algorithm I Matching functions: Reduce the search space I Dynamic programming algorithm: Checks for every matching function whether there is a compatible matching M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 9 Matching functions Pattern P ↓ matching function ↓ Text T M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 10 Matching functions - an example Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 11 Matching functions - an example Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (2) F (1) M.L. Bruner, M. Lackner A Fast Algorithm for PPM F (3) July 6, 2012 11 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (2) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (2) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (1) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (1) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (1) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (1) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (1) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (3) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (3) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 The algorithm - finding a matching Pattern P Text T 12 11 10 9 4 8 7 3 6 5 2 4 3 1 2 1 F (3) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 12 Runtime √ Matching functions: Dynamic programming algorithm: M.L. Bruner, M. Lackner A Fast Algorithm for PPM run(T ) 2 O∗ (1.2611run(T ) ) July 6, 2012 13 Runtime √ Matching functions: run(T ) 2 Dynamic programming algorithm: O∗ (1.2611run(T ) ) In total: O∗ (1.784run(T ) ) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 13 Runtime √ Matching functions: run(T ) 2 Dynamic programming algorithm: O∗ (1.2611run(T ) ) In total: O∗ (1.784run(T ) ) → This is a fixed-parameter tractable (FPT) algorithm, i.e. a runtime of f (k) · nc . M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 13 Runtime √ Matching functions: run(T ) 2 Dynamic programming algorithm: O∗ (1.2611run(T ) ) In total: O∗ (1.784run(T ) ) → This is a fixed-parameter tractable (FPT) algorithm, i.e. a runtime of f (k) · nc . Since run(T ) ≤ n, we also obtain M.L. Bruner, M. Lackner A Fast Algorithm for PPM O∗ (1.784n ) July 6, 2012 13 Alternating runs in the pattern run(P) O∗ (1.784run(T ) ) O∗ run(P) n2 2run(P) M.L. Bruner, M. Lackner FPT, i.e. f (k) · nc XP, i.e. nf (k) A Fast Algorithm for PPM July 6, 2012 14 Alternating runs in the pattern run(P) O∗ (1.784run(T ) ) O∗ run(P) n2 2run(P) FPT, i.e. f (k) · nc XP, i.e. nf (k) no FPT result possible (W[1]-hardness) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 14 Conclusion Main results I O∗ (1.784run(T ) ) → FPT result I O∗ (1.784n ) → fastest general algorithm I W[1]-hardness for run(P) M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 15 Conclusion Main results I O∗ (1.784run(T ) ) → FPT result I O∗ (1.784n ) → fastest general algorithm I W[1]-hardness for run(P) Future work I PPM parameterized by some other parameter of P? By k = |P|? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 15 Conclusion Main results I O∗ (1.784run(T ) ) → FPT result I O∗ (1.784n ) → fastest general algorithm I W[1]-hardness for run(P) Future work I PPM parameterized by some other parameter of P? By k = |P|? I Kernelization results M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 15 Conclusion Main results I O∗ (1.784run(T ) ) → FPT result I O∗ (1.784n ) → fastest general algorithm I W[1]-hardness for run(P) Future work I PPM parameterized by some other parameter of P? By k = |P|? I Kernelization results I Other permutation statistics of the text? M.L. Bruner, M. Lackner A Fast Algorithm for PPM July 6, 2012 15
© Copyright 2026 Paperzz