Pattern Matching with Variables: Fast Algorithms and New Hardness Results

Authors Henning Fernau, Florin Manea, Robert Mercas, Markus L. Schmid

Thumbnail PDF


  • Filesize: 0.68 MB
  • 14 pages

Document Identifiers

Author Details

Henning Fernau
Florin Manea
Robert Mercas
Markus L. Schmid

Cite AsGet BibTex

Henning Fernau, Florin Manea, Robert Mercas, and Markus L. Schmid. Pattern Matching with Variables: Fast Algorithms and New Hardness Results. In 32nd International Symposium on Theoretical Aspects of Computer Science (STACS 2015). Leibniz International Proceedings in Informatics (LIPIcs), Volume 30, pp. 302-315, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2015)


A pattern (i. e., a string of variables and terminals) maps to a word, if this is obtained by uniformly replacing the variables by terminal words; deciding this is NP-complete. We present efficient algorithms\footnote{The computational model we use is the standard unit-cost RAM with logarithmic word size. Also, all logarithms appearing in our time complexity evaluations are in base 2.} that solve this problem for restricted classes of patterns. Furthermore, we show that it is NP-complete to decide, for a given number k and a word w, whether w can be factorised into k distinct factors; this shows that the injective version (i.e., different variables are replaced by different words) of the above matching problem is NP-complete even for very restricted cases.
  • combinatorial pattern matching
  • combinatorics on words
  • patterns with variables
  • ${cal NP}$-complete string problems


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Amihood Amir and Igor Nor. Generalized function matching. Journal of Discrete Algorithms, 5:514-523, 2007. Google Scholar
  2. Dana Angluin. Finding patterns common to a set of strings. Journal of Computer and System Sciences, 21:46-62, 1980. Google Scholar
  3. Brenda S. Baker. Parameterized pattern matching: Algorithms and applications. Journal of Computer and System Sciences, 52:28-42, 1996. Google Scholar
  4. Pablo Barceló, Leonid Libkin, Anthony W. Lin, and Peter T. Wood. Expressive languages for path queries over graph-structured data. ACM Transactions on Database Systems, 37, 2012. Google Scholar
  5. Cezar Câmpeanu, Kai Salomaa, and Sheng Yu. A formal study of practical regular expressions. International Journal of Foundations of Computer Science, 14:1007-1018, 2003. Google Scholar
  6. Raphaël Clifford, Aram W. Harrow, Alexandru Popa, and Benjamin Sach. Generalised matching. In Proceedings of the 16th International Symposium on String Processing and Information Retrieval, SPIRE, volume 5721 of Lecture Notes in Computer Science, pages 295-301, 2009. Google Scholar
  7. Anne Condon, Ján Maňuch, and Chris Thachuk. The complexity of string partitioning. In Proceedings of 23th Annual Symposium on Combinatorial Pattern Matching, CPM, volume 7354 of Lecture Notes in Computer Science, pages 159-172, 2012. Google Scholar
  8. Maxime Crochemore. An optimal algorithm for computing the repetitions in a word. Information Processing Letters, 12(5):244-250, 1981. Google Scholar
  9. Maxime Crochemore and Wojciech Rytter. Usefulness of the Karp-Miller-Rosenberg algorithm in parallel computations on strings and arrays. Theoretical Computer Science, 88(1):59-82, 1991. Google Scholar
  10. Thomas Erlebach, Peter Rossmanith, Hans Stadtherr, Angelika Steger, and Thomas Zeugmann. Learning one-variable pattern languages very efficiently on average, in parallel, and by asking queries. Theoretical Computer Science, 261:119-156, 2001. Google Scholar
  11. Henning Fernau, Florin Manea, Robert Mercaş, and Markus L. Schmid. Revisiting Shinohara’s algorithm for computing descriptive patterns. Technical Report 14-3, Trier University, September 2014. descriptive_patterns_tech_report_Schmid.pdf. Google Scholar
  12. Henning Fernau and Markus. L. Schmid. Pattern matching with variables: A multivariate complexity analysis. In Proceedings of the 24th Annual Symposium on Combinatorial Pattern Matching, CPM, volume 7922 of LNCS, pages 83-94, 2013. Google Scholar
  13. Henning Fernau, Markus L. Schmid, and Yngve Villanger. On the parameterised complexity of string morphism problems. In Proceedings of the 33rd IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science, FSTTCS, volume 24 of Leibniz International Proceedings in Informatics (LIPIcs), pages 55-66, 2013. Google Scholar
  14. Jeffrey E. F. Friedl. Mastering Regular Expressions. O'Reilly, Sebastopol, CA, third edition, 2006. Google Scholar
  15. Michael R. Garey and David S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman & Co., New York, NY, USA, 1979. Google Scholar
  16. Dan Gusfield. Algorithms on strings, trees, and sequences: computer science and computational biology. Cambridge University Press, New York, NY, USA, 1997. Google Scholar
  17. Oscar H. Ibarra, Ting-Chuen Pong, and Stephen M. Sohn. A note on parsing pattern languages. Pattern Recognition Letters, 16:179-182, 1995. Google Scholar
  18. Juhani Karhumäki, Wojciech Plandowski, and Filippo Mignosi. The expressibility of languages and relations by word equations. Journal of the ACM, 47:483-505, 2000. Google Scholar
  19. Juha Kärkkäinen, Peter Sanders, and Stefan Burkhardt. Linear work suffix array construction. Journal of the ACM, 53:918-936, 2006. Google Scholar
  20. Michael Kearns and Leonard Pitt. A polynomial-time algorithm for learning k-variable pattern languages from examples. In Proceedings of the 2nd Annual Conference on Learning Theory, COLT, pages 57-71, 1989. Google Scholar
  21. Tomasz Kociumaka, Jakub Radoszewski, Wojciech Rytter, and Tomasz Waleń. Efficient data structures for the factor periodicity problem. In Proceedings of the 19th International Symposium on String Processing and Information Retrieval, SPIRE, volume 7608 of Lecture Notes in Computer Science, pages 284-294, 2012. Google Scholar
  22. M. Lothaire. Combinatorics on Words. Cambridge University Press, 1997. Google Scholar
  23. M. Lothaire. Algebraic Combinatorics on Words, chapter 3. Cambridge University Press, Cambridge, New York, 2002. Google Scholar
  24. Alexandru Mateescu and Arto Salomaa. Finite degrees of ambiguity in pattern languages. RAIRO Informatique Théoretique et Applications, 28:233-253, 1994. Google Scholar
  25. Yen K. Ng and Takeshi Shinohara. Developments from enquiries into the learnability of the pattern languages from positive data. Theoretical Computer Science, 397:150-165, 2008. Google Scholar
  26. Sebastian Ordyniak and Alexandru Popa. A parameterized study of maximum generalized pattern matching problems. In Proceedings of the 9th International Symposium on Parameterized and Exact Computation, IPEC, 2014. Google Scholar
  27. Daniel Reidenbach. Discontinuities in pattern inference. Theoretical Computer Science, 397:166-193, 2008. Google Scholar
  28. Daniel Reidenbach and Markus L. Schmid. Patterns with bounded treewidth. Information and Computation, 239:87-99, 2014. Google Scholar
  29. Takeshi Shinohara. Polynomial time inference of pattern languages and its application. In Proceedings of the 7th IBM Symposium on Mathematical Foundations of Computer Science, pages 191-209, 1982. Google Scholar