gpt4 book ai didi

string-search - KMP 算法执行的比较次数是否比简化的 Boyer-Moore 算法少?

转载 作者:行者123 更新时间:2023-12-04 06:40:50 25 4
gpt4 key购买 nike

KMP (Knuth-Morris-Pratt) 算法执行的比较次数是否比简化的 Boyer-Moore 算法少?

最佳答案

Boyers Moore 算法通常应该以较少的比较来执行,引用自 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).

关于string-search - KMP 算法执行的比较次数是否比简化的 Boyer-Moore 算法少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4263200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com