简体   繁体   English

是否存在具有不同空间复杂度的多种 KMP 算法方法? 有什么区别?

[英]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.

相关问题 字符串模式匹配的KMP和Z算法有什么区别? - What is the difference between KMP and Z algorithm of string pattern matching? 多次出现的KMP算法 - KMP algorithm for multiple occurrences KMP 故障算法的功能是什么? - What is the function for the KMP Failure Algorithm? 我实施KMP算法有什么问题? - What's wrong with my implementation of the KMP algorithm? 构造一个KMP算法必须多次回溯的示例 - Construct an example where the KMP algorithm has to backtrack multiple times 如何用空格替换多个不同的字符? - How to replace multiple different chars with white space? 使用Ukkonen算法的时间复杂度,Knuth–Morris–Pratt(KMP)和后缀树之间的差异。 - Difference between Knuth–Morris–Pratt (KMP) and suffix tree using Ukkonen's algorithm for time complexity. 当目标是查找某个字符串的所有出现时,KMP的最坏情况复杂度是多少? - What's the worst case complexity for KMP when the goal is to find all occurrences of a certain string? main方法中String数组的不同表示法有什么区别? - What are difference in different notations of String array in main method? c ++中字符串的这两个不同初始化之间的区别是什么? - what's the difference between these two different initialization for a string in c++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM