Springer Nature is making SARS-CoV-2 and COVID-19 research free. View research | View latest news | Sign up for updates

A Fast Algorithm for Permutation Pattern Matching Based on Alternating Runs


The NP-complete Permutation Pattern Matching problem asks whether a k-permutation P is contained in a n-permutation T as a pattern. This is the case if there exists an order-preserving embedding of P into T. In this paper, we present a fixed-parameter algorithm solving this problem with a worst-case runtime of \({\mathcal O}(1.79^{\mathsf {run}(T)}\cdot n\cdot k)\), where \(\mathsf {run}(T)\) denotes the number of alternating runs of T. This algorithm is particularly well-suited for instances where T has few runs, i.e., few ups and downs. Moreover, since \(\mathsf {run}(T)<n\), this can be seen as a \({\mathcal O}(1.79^{n}\cdot n\cdot k)\) algorithm which is the first to beat the exponential \(2^n\) runtime of brute-force search. Furthermore, we prove that under standard complexity theoretic assumptions such a fixed-parameter tractability result is not possible for \(\mathsf {run}(P)\).

This is a preview of subscription content, log in to check access.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7


  1. 1.

    The reason why we do not set \(b_{\mathsf {run}(P)}=\lfloor \mathsf {run}(F(\mathsf {run}(P))/2\rfloor \) is a rather technical one: \(F(\mathsf {run}(P))\) may end with a run up if the last run in P is a run up and may end with a run down if the last run in P is a run down. This would lead to unwanted collisions concerning the Index function and consequently would prohibit the proof of Lemma 5.


  1. 1.

    Ahal, S., Rabinovich, Y.: On complexity of the subpattern problem. SIAM J. Discrete Math. 22(2), 629–649 (2008)

  2. 2.

    Albert, M., Aldred, R., Atkinson, M., Holton, D.: Algorithms for pattern involvement in permutations. In: Eades, P., Takaoka, T. (eds.) Algorithms and Computation, Lecture Notes in Computer Science, vol. 2223, pp. 355–367. Springer, Berlin (2001)

  3. 3.

    Albert, M.H., Aldred, R.E.L., Atkinson, M.D., van Ditmarsch, H.P., Handley, B.D., Handley, C.C., Opatrny, J.: Longest subsequences in permutations. Australas. J. Comb. 28, 225–238 (2003)

  4. 4.

    André, D.: Étude sur les maxima, minima et séquences des permutations. Annales scientifiques de l’École normale supérieure 3(1), 121–135 (1884)

  5. 5.

    Bóna, M.: Combinatorics of Permutations. Discrete Mathematics and Its Applications. Chapman & Hall/CRC, Boca Raton (2004)

  6. 6.

    Bose, P., Buss, J.F., Lubiw, A.: Pattern matching for permutations. Inf. Process. Lett. 65(5), 277–283 (1998)

  7. 7.

    Bouvel, M., Rossin, D.: The longest common pattern problem for two permutations. Pure Math. Appl. 17(1–2), 55–69 (2006)

  8. 8.

    Bouvel, M., Rossin, D., Vialette, S.: Longest common separable pattern among permutations. In: Ma, B., Zhang, K. (eds.) Combinatorial Pattern Matching, Lecture Notes in Computer Science, pp. 316–327. Springer, Berlin (2007)

  9. 9.

    Bruner, M.L., Lackner, M.: A fast algorithm for permutation pattern matching based on alternating runs. In: Fomin, F.V., Kaski, P. (eds.) Algorithm Theory—SWAT 2012, Lecture Notes in Computer Science, vol. 7357, pp. 261–270. Springer, Berlin (2012)

  10. 10.

    Bruner, M.L., Lackner, M.: The computational landscape of permutation patterns. Pure Math. Appl. 24(2), 83–101 (2013)

  11. 11.

    Chang, M.S., Wang, F.H.: Efficient algorithms for the maximum weight clique and maximum weight independent set problems on permutation graphs. Inf. Process. Lett. 43(6), 293–295 (1992)

  12. 12.

    Crochemore, M., Iliopoulos, C.S., Kociumaka, T., Kubica, M., Langiu, A., Pissis, S.P., Radoszewski, J., Rytter, W., Waleń, T.: Order-preserving incomplete suffix trees and order-preserving indexes. In: Kurland, O., Lewenstein, M., Porat, E. (eds.) String Processing and Information Retrieval, Lecture Notes in Computer Science, vol. 8214, pp. 84–95. Springer, Berlin (2013)

  13. 13.

    David, F.N., Barton, D.E.: Combinatorial Chance. Griffin, London (1962)

  14. 14.

    Downey, R., Fellows, M.: Fundamentals of Parameterized Complexity. Texts in Computer Science. Springer, Berlin (2013)

  15. 15.

    Downey, R.G., Fellows, M.R.: Parameterized Complexity. Springer, Berlin (1999)

  16. 16.

    Flajolet, P., Sedgewick, R.: Analytic Combinatorics. Cambridge University Press, Cambridge (2009)

  17. 17.

    Flum, J., Grohe, M.: Parameterized Complexity Theory. Springer, Berlin (2006)

  18. 18.

    Fomin, F., Kratsch, D.: Exact Exponential Algorithms. Texts in Theoretical Computer Science. An EATCS Series. Springer, Berlin (2010)

  19. 19.

    Gawrychowski, P., Uznański, P.: Order-preserving pattern matching with \(k\) mismatches. In: Kulikov, A.S., Kuznetsov, S.O., Pevzner, P. (eds.) Combinatorial Pattern Matching, Lecture Notes in Computer Science, vol. 8486, pp. 130–139. Springer, Berlin (2014)

  20. 20.

    Guillemot, S., Marx, D.: Finding small patterns in permutations in linear time. In: Proceedings of the Twenty-Fifth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA’14, pp. 82–101. SIAM (2014)

  21. 21.

    Guillemot, S., Vialette, S.: Pattern matching for 321-avoiding permutations. In: Dong, Y., Du, D.Z., Ibarra, O. (eds.) Algorithms and Computation, Lecture Notes in Computer Science, vol. 5878, pp. 1064–1073. Springer, Berlin (2009)

  22. 22.

    Guo, J., Niedermeier, R.: Invitation to data reduction and problem kernelization. SIGACT News 38(1), 31–45 (2007)

  23. 23.

    Ibarra, L.: Finding pattern matchings for permutations. Inf. Process. Lett. 61(6), 293–295 (1997)

  24. 24.

    Kim, J., Eades, P., Fleischer, R., Hong, S.H., Iliopoulos, C.S., Park, K., Puglisi, S.J., Tokuyama, T.: Order-preserving matching. Theor. Comput. Sci. 525, 68–79 (2014)

  25. 25.

    Kitaev, S.: Patterns in Permutations and Words. Springer, Berlin (2011)

  26. 26.

    Klenke, A.: Probability Theory: A Comprehensive Course. Springer, Berlin (2008)

  27. 27.

    Knuth, D.E.: The Art of Computer Programming: Fundamental Algorithms, vol. I. Addison-Wesley, Reading (1968)

  28. 28.

    Kubica, M., Kulczyński, T., Radoszewski, J., Rytter, W., Wale, T.: A linear time algorithm for consecutive permutation pattern matching. Inf. Process. Lett. 113(12), 430–433 (2013)

  29. 29.

    Levene, H., Wolfowitz, J.: The covariance matrix of runs up and down. Ann. Math. Stat. 15(1), 58–69 (1944)

  30. 30.

    Mäkinen, E.: On the longest upsequence problem for permutations. Int. J. Comput. Math. 77(1), 45–53 (2001)

  31. 31.

    Niedermeier, R.: Invitation to Fixed-Parameter Algorithms, Lecture Series in Mathematics and Its Applications. Oxford University Press, Oxford (2006)

  32. 32.

    Saxena, S., Yugandhar, V.: Parallel algorithms for separable permutations. Discrete Appl. Math. 146(3), 343–364 (2005)

  33. 33.

    Schensted, C.: Longest increasing and decreasing subsequences. Canad. J. Math. 13,179–191(1961)

  34. 34.

    Simion, R., Schmidt, F.W.: Restricted permutations. Eur. J. Comb. 6, 383–406 (1985)

  35. 35.

    Van Emde Boas, P.: Machine models and simulations. In: Van Leeuwen, J. (ed.) Handbook of Theoretical Computer Science, vol. A. Elsevier, Amsterdam (1990)

  36. 36.

    Vatter, V.: Permutation patterns. In: Bóna, M. (ed.) Handbook of Enumerative Combinatorics. CRC Press, Boca Raton (2015)

Download references


We would like to thank the anonymous reviewers for their feedback and suggestions leading to numerous improvements of this paper. The first author was supported by the Austrian Science Foundation FWF, Grant P25337-N23, the second author by the Austrian Science Foundation FWF, Grant P25518-N23 and Y698.

Author information

Correspondence to Marie-Louise Bruner.

Additional information

A preliminary version of this paper [9] appeared in the proceedings of the 13th Scandinavian Symposium and Workshops on Algorithm Theory, SWAT 2012.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Bruner, M., Lackner, M. A Fast Algorithm for Permutation Pattern Matching Based on Alternating Runs. Algorithmica 75, 84–117 (2016).

Download citation


  • Permutation patterns
  • Parameterized complexity
  • Pattern matching
  • Fixed-parameter tractability
  • Exponential algorithms
  • Combinatorics