Skip to main content
QUICK REVIEW

[论文解读] Fast Searching in Packed Strings

Philip Bille|arXiv (Cornell University)|Jul 17, 2009
Algorithms and Data Compression参考文献 15被引用 6
一句话总结

本文提出了一种在压缩字符串上进行精确字符串匹配的快速算法,利用一种新颖的分段自动机和查表转移模拟,实现了在单位成本字-RAM上的 $ O\bigl(\frac{n}{\log_\sigma n} + m + \mathrm{occ}\bigr) $ 时间复杂度。该方法利用字级并行性与紧凑的子自动机编码,当 $ m = o(n) $ 时超越了经典的Knuth-Morris-Pratt算法的复杂度界限,并在 $ m = O(n / \log_\sigma n) $ 时达到最优。

ABSTRACT

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 ight). $$ 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.

研究动机与目标

  • 解决在压缩字符串上字符串匹配的最坏情况时间复杂度问题,其中每个字存储多个字符。
  • 克服经典算法(如Knuth-Morris-Pratt)的局限性,这些算法假设逐字符访问,因此无法利用字级并行性。
  • 设计一种数据结构与算法,通过紧凑编码自动机子状态并借助查表实现快速模拟,从而实现接近最优的性能。
  • 证明当 $ m = O(n / \log_\sigma n) $ 时,该算法达到最优,与信息论下界一致。
  • 通过预计算与模式无关的表格,支持高效多模式搜索。

提出的方法

  • 引入分段自动机 $ C(P,r) $,即KMP自动机 $ K $ 的紧凑表示,将状态划分为大小为 $ r = \Theta(\log n) $ 的重叠区间。
  • 基于分段边界将自动机划分为子自动机,通过预计算的转移表格实现高效模拟。
  • 使用查表法计算每个分段的 Next 函数,从而在每次迭代中实现最多 $ r-1 $ 个字符的常数时间模拟。
  • 应用一种改进的模拟算法,批量处理轻量转移(非失败、非接受)并单独处理重载或接受转移。
  • 利用字级并行性和位运算同时处理多个字符,减少迭代次数。
  • 通过设置 $ t = n^\varepsilon $,将空间复杂度优化为 $ O(n^\varepsilon + m) $,在时间和空间复杂度之间实现平衡。

实验结果

研究问题

  • RQ1能否通过利用字级并行性,在压缩字符串匹配中实现每个字符的亚线性时间?
  • RQ2是否可以设计一种紧凑的自动机表示,支持快速模拟并实现最优时间复杂度?
  • RQ3如何在不因频繁状态变化导致 $ O(n) $ 时间开销的情况下,高效模拟压缩字符串中的自动机转移?
  • RQ4查表技术能否被适配到KMP自动机中,以在压缩字符串上实现最优性能?
  • RQ5压缩字符串匹配的理论性能极限是什么?我们能否达到这一极限?

主要发现

  • 所提出的算法在单位成本字-RAM(对数长度字长)上实现了 $ O\bigl(\frac{n}{\log_\sigma n} + m + \mathrm{occ}\bigr) $ 的时间复杂度。
  • 当 $ m = o(n) $ 时,该算法优于经典Knuth-Morris-Pratt算法的 $ O(n) $ 时间复杂度。
  • 当 $ m = O(n / \log_\sigma n) $ 时,该算法与信息论下界 $ \Omega\bigl(\frac{n}{\log_\sigma n} + \mathrm{occ}\bigr) $ 一致,因此达到最优。
  • 空间复杂度为 $ O(n^\varepsilon + m) $,其中任意常数 $ \varepsilon \in (0,1) $,支持高效的内存使用。
  • 该算法通过新颖的分段自动机和查表转移模拟,实现字符的批量处理,将迭代次数减少至 $ O(n/r + \mathrm{occ}) $。
  • 该方法可通过预计算与模式无关的表格,扩展至多模式搜索,实现跨查询的重复利用。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。