You are given a text T of length n and a pattern P of length p
Ask Expert

Be Prepared For The Toughest Questions

Practice Problems

You are given a text T of length n and a pattern P of length p

Q2:

You are given a text T of length n and a pattern P of length p. We say that two occurrences x and y are non-overlapping if |y-x|≥ p. Design an O(n + p) time algorithm to report a maximal set of non-overlapping occurrences of P in T.

For example, say T = aabaabaabacdeaabaabac and P = aaba, then the occurrences of P in T are {0,3, 6, 13, 16}. We have to report the largest sized subset of the occurrences such that no two occurrences in the subset overlap. Notice that the occurrences 0 and 3 (also, 3 and 6, and 13 and 16) overlap. So, we have to report either {0,6, 13} or {0,6, 16).

Hint: Use KMP first. Then you need to do "something" greedily.

Hint
ComputerKnuth Morris Pratt (KMP) is an algorithm, which checks the characters from left to right. When a pattern has a sub-pattern appears more than one in the sub-pattern, it uses that property to improve the time complexity, also for in the worst case. The time complexity of KMP is O(n)....

Know the process

Students succeed in their courses by connecting and communicating with
an expert until they receive help on their questions

1
img

Submit Question

Post project within your desired price and deadline.

2
img

Tutor Is Assigned

A quality expert with the ability to solve your project will be assigned.

3
img

Receive Help

Check order history for updates. An email as a notification will be sent.

img
Unable to find what you’re looking for?

Consult our trusted tutors.

Developed by Versioning Solutions.