[英]Are there multiple KMP algorithmic approaches with different space complexities? What is the difference?
I am reading about the KMP substring search algorithm and the examples I find online use an one-dimensional table to build the prefix information table.我正在阅读有关KMP substring 搜索算法的信息,我在网上找到的示例使用一维表来构建前缀信息表。
I also read the Sedgewick explanation and he used a 2-D array to build the table and explicitly states that the space complexity of KMP is O(RM)
where R
is the alphabet size and M
the pattern size while everywhere else it is stated that the space complexity is just O(M + N)
ie the text to process and the pattern size itself.我还阅读了 Sedgewick 的解释,他使用二维数组来构建表格,并明确指出 KMP 的空间复杂度为
O(RM)
,其中R
是字母大小, M
是模式大小,而其他地方都指出空间复杂度仅为O(M + N)
,即要处理的文本和图案大小本身。
So I am confused on the difference.所以我对差异感到困惑。 Are there multiple KMP algorithmic approaches?
是否有多种 KMP 算法方法? And do they have different scope?
他们有不同的 scope 吗? Or what am I missing?
或者我错过了什么?
Why is the 2D needed if 1D can solve the substring problem too?如果一维也能解决 substring 问题,为什么还需要二维呢?
I guess Sedgewick wanted to demonstrate a variant of KMP that constructs a deterministic finite automaton in the standard sense of that term.我猜 Sedgewick 想演示 KMP 的一种变体,它在该术语的标准意义上构造一个确定性有限自动机。 It's a weird choice that (as you observe) bloats the running time, but maybe there was a compelling pedagogical reason that I don't appreciate (then again my PhD was on algorithms, so...).
这是一个奇怪的选择,(正如您所观察到的)会使运行时间膨胀,但也许有一个我不欣赏的令人信服的教学原因(然后我的博士学位又是关于算法的,所以......)。 I'd find another description that follows the original more closely.
我会找到另一个更接近原文的描述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.