不确定字符串上的实用 KMP/BM 风格模式匹配
Practical KMP/BM Style Pattern-Matching on Indeterminate Strings
AI总结:
本文提出两种空间高效的 KMP 和 BM 风格算法,通过预处理将不确定字符串映射为常规字符串,实现快速模式匹配,仅需 Θ(m) 额外空间且 BM 变体执行更快。
摘要:
本文描述了两种简单、快速且空间高效的算法,用于在不确定字符串 x = x[1..n] 中查找不确定模式 p = p[1..m] 的所有匹配,其中 p 和 x 均定义在“小”有序字母表 Σ 上——例如,σ= |Σ| ≤ 9。两种算法都依赖于一个预处理阶段,该阶段将 Σ 替换为大小为 σ_I = σ 的整数字母表 Σ_I,该字母表(以与字符串长度成线性的时间可逆地)将 x 和 p 分别映射到 Σ_I 上的等价常规字符串 y 和 q,其最大(不确定)字母可以用 32 位字表示(对于 σ≤4,因此对于 DNA 序列,8 位表示就足够了)。我们首先描述了经典的 Knuth-Morris-Pratt 算法的高效版本 KMP Indet,用于查找 q 在 y 中(即 p 在 x 中)的所有出现,但在必要时使用前缀数组而不是边界数组来控制转换后的模式 q 沿转换后的字符串 y 的移动。接着我们描述了 Boyer-Moore 算法的类似高效版本 BM Indet,在广泛的测试用例中,其执行速度明显快于 KMP Indet。一个值得注意的特点是,两种算法只需要很少的额外空间:Θ(m) 个字。我们推测类似的方法可能会为其他著名的模式匹配算法,特别是 Boyer-Moore 的几种变体,产生实用且高效的不确定等价物。
英文摘要:
In this paper we describe two simple, fast, space-efficient algorithms for finding all matches of an indeterminate pattern $p = p[1..m]$ in an indeterminate string $x = x[1..n]$, where both $p$ and $x$ are defined on a "small" ordered alphabet $Σ$ $-$ say, $σ= |Σ| \le 9$. Both algorithms depend on a preprocessing phase that replaces $Σ$ by an integer alphabet $Σ_I$ of size $σ_I = σ$ which (reversibly, in time linear in string length) maps both $x$ and $p$ into equivalent regular strings $y$ and $q$, respectively, on $Σ_I$, whose maximum (indeterminate) letter can be expressed in a 32-bit word (for $σ\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 $q$ in $y$ (that is, of $p$ in $x$), but, whenever necessary, using the prefix array, rather than the border array, to control shifts of the transformed pattern $q$ along the transformed string $y$. 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)$ 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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。