Practical KMP/BM Style Pattern-Matching on Indeterminate Strings
Abstract
In this paper we describe two simple, fast, space-efficient algorithms for finding all matches of an indeterminate pattern in an indeterminate string , where both and are defined on a "small" ordered alphabet say, . Both algorithms depend on a preprocessing phase that replaces by an integer alphabet of size which (reversibly, in time linear in string length) maps both and into equivalent regular strings and , respectively, on , whose maximum (indeterminate) letter can be expressed in a 32-bit word (for , 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 in (that is, of in ), but, whenever necessary, using the prefix array, rather than the border array, to control shifts of the transformed pattern along the transformed string . 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: 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.
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}
}