Knuth-Morris-Pratt Search vs Boyer-Moore Search

Posted 每天更强一点...

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Knuth-Morris-Pratt Search vs Boyer-Moore Search相关的知识,希望对你有一定的参考价值。

Reference

[1] https://stackoverflow.com/questions/12656160/what-are-the-main-differences-between-the-knuth-morris-pratt-and-boyer-moore-sea?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

[2] http://www.cs.utexas.edu/~moore/best-ideas/string-searching/kpm-example.html

[3] http://www.cs.utexas.edu/~moore/best-ideas/string-searching/fstrpos-example.html

Boyer-Moore‘s approach is to try to match the last character of the pattern instead of the first one with the assumption that if there‘s not match at the end no need to try to match at the beginning. This allows for "big jumps" therefore BM works better when the pattern and the text you are searching resemble "natural text" (i.e. English)

Knuth-Morris-Pratt searches for occurrences of a "word" W within a main "text string" S by employing the observation that when a mismatch occurs, the word itself embodies sufficient information to determine where the next match could begin, thus bypassing re-examination of previously matched characters. (Source: Wiki)

This means KMP is better suited for small sets like DNA (ACTG)

Boyer-Moore technique match the characters from right to left, works well on long patterns. knuth moris pratt match the characters from left to right, works fast on short patterns.

 

以上是关于Knuth-Morris-Pratt Search vs Boyer-Moore Search的主要内容,如果未能解决你的问题,请参考以下文章

Knuth-Morris-Pratt 算法中的 DFA 构造

ZOJ 17届校赛 Knuth-Morris-Pratt Algorithm

ZOJ 3957: Knuth-Morris-Pratt Algorithm

除了 Knuth-Morris-Pratt、Rabin-Karp 等,还都有哪些可用的字符串匹配算法?

KMP(The Knuth-Morris-Pratt Algorithm)

ZOJ 3957 Knuth-Morris-Pratt Algorithm