English

Practical KMP/BM Style Pattern-Matching on Indeterminate Strings

Data Structures and Algorithms 2024-02-19 v3

Abstract

In this paper we describe two simple, fast, space-efficient algorithms for finding all matches of an indeterminate pattern p=p[1..m]p = p[1..m] in an indeterminate string x=x[1..n]x = x[1..n], where both pp and xx are defined on a "small" ordered alphabet Σ\Sigma - say, σ=Σ9\sigma = |\Sigma| \le 9. Both algorithms depend on a preprocessing phase that replaces Σ\Sigma by an integer alphabet ΣI\Sigma_I of size σI=σ\sigma_I = \sigma which (reversibly, in time linear in string length) maps both xx and pp into equivalent regular strings yy and qq, respectively, on ΣI\Sigma_I, whose maximum (indeterminate) letter can be expressed in a 32-bit word (for σ4\sigma \le 4, thus for DNA sequences, an 8-bit representation suffices). We first describe an efficient version KMP Indet of the venerable Knuth-Morris-Pratt algorithm to find all occurrences of qq in yy (that is, of pp in xx), but, whenever necessary, using the prefix array, rather than the border array, to control shifts of the transformed pattern qq along the transformed string yy. We go on to describe a similar efficient version BM Indet of the Boyer- Moore algorithm that turns out to execute significantly faster than KMP Indet over a wide range of test cases. A noteworthy feature is that both algorithms require very little additional space: Θ(m)\Theta(m) words. We conjecture that a similar approach may yield practical and efficient indeterminate equivalents to other well-known pattern-matching algorithms, in particular the several variants of Boyer-Moore.

Keywords

Cite

@article{arxiv.2204.08331,
  title  = {Practical KMP/BM Style Pattern-Matching on Indeterminate Strings},
  author = {Hossein Dehghani and Neerja Mhaskar and W. F. Smyth},
  journal= {arXiv preprint arXiv:2204.08331},
  year   = {2024}
}
R2 v1 2026-06-24T10:51:00.289Z