除了 Knuth-Morris-Pratt、Rabin-Karp 等算法之外,还有哪些可用的字符串匹配算法呢?
Karp-Rabin
Shift Or
Morris-Pratt
Knuth-Morris-Pratt
Simon
Colussi
Galil-Giancarlo
Apostolico-Crochemore
Not So Naive
Forward Dawg Matching
Boyer-Moore
Turbo-BM
Apostolico-Giancarlo
Reverse Colussi
Horspool
Quick Search
Tuned Boyer-Moore
Zhu-Takaoka
Berry-Ravindran
Smith
Raita
Reverse Factor
Turbo Reverse Factor
Backward Oracle Matching
还有大约15个。
顺便说一句,如果您对字符串相似度算法(例如Levenshtein距离等)也感兴趣的话,您可能需要澄清一下,因为它们是密切相关的。
Simone Faro和Thierry Lecroq提供了一个C语言实现以及86种精确字符串匹配算法的参考资料,这些内容可以在"String Matching Algorithms Research Tool"中找到。
他们还提供了一个框架来对字符串匹配算法进行基准测试:
____________________________________________________________
Experimental results on englishTexts
Searching for a set of 200 patterns with length 128
Testing 5 algorithms
- [1/5] BM ..................[OK] 0.88 ms
- [2/5] EPSM ................[OK] 0.38 ms
- [3/5] KMP .................[OK] 6.23 ms
- [4/5] KR ..................[OK] 1.84 ms
- [5/5] TW ..................[OK] 2.70 ms
算法