1

I recently studied about string matching, and was inspired to think of a similar problem. Let p be a string of m characters and t be a text of n characters. Now the problem is to find out if p occurs in t in the following way: there exists an i in the range [0, n-1] such that:

p[ j ] = t [ i + j ] for j = 0, 1, ... ,m - 1,

where i + j is computed modulo n. As an example, in normal string matching, ABCD would not occur in CDEFAB, but you can see that in the above-defined problem, ABCD would occur in CDEFAB, i = 4 in this case.

Is there any linear-time algorithm to determine if a pattern p occurs in t? And has this problem been treated before?

Thanks in advance

2 Answers 2

1

I think you can still apply the linear time KMP algorithm to solve it. Just add m-1 characters t[0], t1,...,t[m-2] to the end of the text t. Ofcourse you only need to do this if you still have a candidate substring left in your table after the text t ends.

If test string is BCDEA
AXYZBCDE shall become AXYZBCDEAXYZ

Sign up to request clarification or add additional context in comments.

Comments

0

Just double t and make an ordinary lookup for p?

So you would look up ABCD in CDEFABCDEFAB and would get the right i. That can be made in linear time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.