arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 0907.3135cs.DS
收藏

压缩字符串的快速搜索

Fast Searching in Packed Strings

Philip Bille

摘要:

给定字符串$P$和$Q$,(精确)字符串匹配问题是找到与$P$匹配的$Q$中子字符串的所有位置。经典的Knuth-Morris-Pratt算法[SIAM J. Comput.,1977]在线性时间内解决了字符串匹配问题,如果我们一次只能读取一个字符,这是最佳的。然而,大多数字符串都是以打包的形式存储在计算机中的,一个单词中有几个字符,这使我们有机会同时读取多个字符。在本文中,我们研究了字符串匹配的最坏情况下的复杂性在包装表示。令$m \leq n$分别为长度$P$和$Q$,并令$σ$表示字母表的大小。在一个标准的单位成本字RAM的对数字长,我们提出了一个算法,使用时间$$ O\left(\frac{n}{\log_σn} + m + \occ\right). $$这里$\occ$是$P$的出现次数在$Q$。对于$m = o(n)$,这改进了Knuth-Morris-Pratt算法的$O(n)$界。此外,如果$m = O(n/\log_σn)$,我们的算法是最优的,因为任何算法都必须花费至少$Ω(\frac{(n+m)\log σ}{\log n} + \occ) = Ω(\frac{n}{\log_σn} + \occ)$时间来读取输入并报告所有事件。结果是通过一种新的自动机构造的基础上的克努特-莫里斯-普拉特算法结合一个新的紧凑表示的子自动机,允许最佳的制表为基础的模拟。

英文摘要:

Given strings $P$ and $Q$ the (exact) string matching problem is to find all positions of substrings in $Q$ matching $P$. The classical Knuth-Morris-Pratt algorithm [SIAM J. Comput., 1977] solves the string matching problem in linear time which is optimal if we can only read one character at the time. However, most strings are stored in a computer in a packed representation with several characters in a single word, giving us the opportunity to read multiple characters simultaneously. In this paper we study the worst-case complexity of string matching on strings given in packed representation. Let $m \leq n$ be the lengths $P$ and $Q$, respectively, and let $σ$ denote the size of the alphabet. On a standard unit-cost word-RAM with logarithmic word size we present an algorithm using time $$ O\left(\frac{n}{\log_σn} + m + \occ\right). $$ Here $\occ$ is the number of occurrences of $P$ in $Q$. For $m = o(n)$ this improves the $O(n)$ bound of the Knuth-Morris-Pratt algorithm. Furthermore, if $m = O(n/\log_σn)$ our algorithm is optimal since any algorithm must spend at least $Ω(\frac{(n+m)\log σ}{\log n} + \occ) = Ω(\frac{n}{\log_σn} + \occ)$ time to read the input and report all occurrences. The result is obtained by a novel automaton construction based on the Knuth-Morris-Pratt algorithm combined with a new compact representation of subautomata allowing an optimal tabulation-based simulation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑