开发者

Does KMP algorithm perform less comparisons than the simplified Boyer-Moore algorithm?

Does the KMP (Knuth–Morris–Pratt) algorith开发者_如何学Pythonm perform fewer comparisons than the simplified Boyer-Moore algorithm?


The Boyers Moore algorithm should usually perform with less comparisons to quote from here

It should be reasonably clear that, if it is normally the case that a given letter doesnt appear at all in the search string, then this algorithm only requires approx N/M character comparisons (N=length(s1), M=length(s2)) - a big improvement on the KMP algorithm, which still requires N. However, if this is not the case then we may need up to N+M comparisons again (with the full version of the algorithm). Fortunately, for many applications we get close to the N/M performance. If the search string is very large, then it is likely that a given character WILL appear in it, but we still get a good improvement compared with the other algorithms (approx N*2/alphabet_size if characters are randomly distributed in a string).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜