knuth-morris-pratt

is there any paper or an explanation on how to implement a two dimensional KMP?

喜夏-厌秋 提交于 2019-12-03 16:59:23
I tried to solve the problem of two dimensional search using a combination of Aho-Corasick and a single dimensional KMP, however, I still need something faster. To elaborate, I have a matrix A of characters of size n1*n2 and I wish to find all occurrences of a smaller matrix B of size m1*m2 and I want that to be in O(n1*n2+m1*m2) if possible. For example: A = a b c b c b b c a c a c d a b a b a q a s d q a and B = b c b c a c a b a the algorithm should return the indexes of say, the upper left corner of the match, which in this case should return (0,1) and (0,3). notice that the occurrences

What is the theory behind KMP pattern matching algorithm? [closed]

痴心易碎 提交于 2019-12-03 05:13:50
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What is the theoretical basis of KMP pattern-matching algorithm? I understand the algorithm itself, but, don't understand how did

When to use Rabin-Karp or KMP algorithms?

时光毁灭记忆、已成空白 提交于 2019-12-03 00:05:11
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 .

What is the theory behind KMP pattern matching algorithm? [closed]

隐身守侯 提交于 2019-12-02 17:38:34
What is the theoretical basis of KMP pattern-matching algorithm? I understand the algorithm itself, but, don't understand how did Knuth, Morris and Pratt invent this algorithm. Was there any mathematical proof? Can you give a link please? The KMP matching algorithm is based on finite automata and works by implicitly building the transition table for an automaton that matches the string. Using a very clever linear-time preprocessing of the string to search for, a matching automaton can be constructed, and the automaton can then be simulated on the string to search in in linear time. The net

Find the smallest period of input string in O(n)?

烈酒焚心 提交于 2019-11-30 07:27:55
Given the following problem : Definition : Let S be a string over alphabet Σ . S' is the smallest period of S if S' is the smallest string such that : S = (S')^k (S'') , where S'' is a prefix of S . If no such S' exists , then S is not periodic . Example : S = abcabcabcabca . Then abcabc is a period since S = abcabc abcabc a , but the smallest period is abc since S = abc abc abc abc a . Give an algorithm to find the smallest period of input string S or declare that S is not periodic. Hint : You can do that in O(n) ... My solution : We use KMP , which runs in O(n) . By the definition of the