Skip to content

Update with KMP substring search algorithm #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Update with KMP substring search algorithm #227

wants to merge 3 commits into from

Conversation

pandeysubash404
Copy link
Contributor

Implements the Knuth-Morris-Pratt (KMP) algorithm to efficiently find the first occurrence of a pattern in a given text. Uses the Longest Prefix Suffix (LPS) array to minimize unnecessary comparisons, resulting in a time complexity of O(n + m).

kmpSearch("abxabcabcaby", "abcaby") returns 6 since the pattern "abcaby" starts at index 6.

Searches for the first occurrence of the pattern in the text using the KMP algorithm.
The test uses to check if the actual output of kmpSearch matches the expected value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant