When to use Rabin-Karp or KMP algorithms?
I have generated an string using the following alphabet. {A,C,G,T} . And my string contains more than 10000 characters. I'm searching the following patterns in it. ATGGA TGGAC CCGT I have asked to use a string matching algorithm which has O(m+n) running time. m = pattern length n = text length Both KMP and Rabin-Karp algorithms have this running time. What is the most suitable algorithm (between Rabin-Carp and KMP) in this situation? Ivaylo Strandjev When you want to search for multiple patterns, typically the correct choice is to use Aho-Corasick , which is somewhat a generalization of KMP .