English

State Complexity of Pattern Matching in Regular Languages

Formal Languages and Automata Theory 2018-11-06 v2

Abstract

In a simple pattern matching problem one has a pattern ww and a text tt, which are words over a finite alphabet Σ\Sigma. One may ask whether ww occurs in tt, and if so, where? More generally, we may have a set PP of patterns and a set TT of texts, where PP and TT are regular languages. We are interested whether any word of TT begins with a word of PP, ends with a word of PP, has a word of PP as a factor, or has a word of PP as a subsequence. Thus we are interested in the languages (PΣ)T(P\Sigma^*)\cap T, (ΣP)T(\Sigma^*P)\cap T, (ΣPΣ)T(\Sigma^* P\Sigma^*)\cap T, and (ΣshuP)T(\Sigma^* \mathbin{\operatorname{shu}} P)\cap T, where shu\operatorname{shu} is the shuffle operation. The state complexity κ(L)\kappa(L) of a regular language LL is the number of states in the minimal deterministic finite automaton recognizing LL. We derive the following upper bounds on the state complexities of our pattern-matching languages, where κ(P)m\kappa(P)\le m, and κ(T)n\kappa(T)\le n: κ((PΣ)T)mn\kappa((P\Sigma^*)\cap T) \le mn; κ((ΣP)T)2m1n\kappa((\Sigma^*P)\cap T) \le 2^{m-1}n; κ((ΣPΣ)T)(2m2+1)n\kappa((\Sigma^*P\Sigma^*)\cap T) \le (2^{m-2}+1)n; and κ((ΣshuP)T)(2m2+1)n\kappa((\Sigma^*\mathbin{\operatorname{shu}} P)\cap T) \le (2^{m-2}+1)n. We prove that these bounds are tight, and that to meet them, the alphabet must have at least two letters in the first three cases, and at least m1m-1 letters in the last case. We also consider the special case where PP is a single word ww, and obtain the following tight upper bounds: κ((wΣ)Tn)m+n1\kappa((w\Sigma^*)\cap T_n) \le m+n-1; κ((Σw)Tn)(m1)n(m2)\kappa((\Sigma^*w)\cap T_n) \le (m-1)n-(m-2); κ((ΣwΣ)Tn)(m1)n\kappa((\Sigma^*w\Sigma^*)\cap T_n) \le (m-1)n; and κ((Σshuw)Tn)(m1)n\kappa((\Sigma^*\mathbin{\operatorname{shu}} w)\cap T_n) \le (m-1)n. For unary languages, we have a tight upper bound of m+n2m+n-2 in all eight of the aforementioned cases.

Keywords

Cite

@article{arxiv.1806.04645,
  title  = {State Complexity of Pattern Matching in Regular Languages},
  author = {Janusz A. Brzozowski and Sylvie Davies and Abhishek Madan},
  journal= {arXiv preprint arXiv:1806.04645},
  year   = {2018}
}

Comments

30 pages, 17 figures

R2 v1 2026-06-23T02:27:40.177Z