Is it possible to still perform a O(n) time complexity to search multiple occurrences of Knuth–Morris–Pratt algorithm?
Is it possible to still perform a O(n) time complexity to search multiple occurrences
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Suppose we have a string S[0,…,N]. Recall that the ith entry in the prefix array stores the length of the maximal prefix of S[0,…,i] that matches the suffix.
We can calculate the prefix array P for pattern$subject (assuming that $ doesn’t occur in subject). It remains to find indices such that P[i]==length(pattern), which can be done in linear time.