Skip to content

Add KMP string matching algorithm (#2719) #2930

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

Conversation

YashAstro11
Copy link

🚀 Description

This PR adds the implementation of the Knuth-Morris-Pratt (KMP) string matching algorithm under the strings/ directory.

  • Efficient pattern searching using LPS (Longest Prefix Suffix) array.
  • Time Complexity: O(n + m)
  • Space Complexity: O(m)

📂 File Added

  • strings/kmp_string_matching.cpp

✅ Related Issue

Closes #2719


Let me know if any changes are required. Glad to contribute! ✨

Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label May 14, 2025
Copy link
Contributor

Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

@github-actions github-actions bot closed this May 21, 2025
#include <iostream>
#include <vector>
using namespace std;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

452546

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @date 2025-04-13
*/

#include <iostream>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <iostream>
#include <iostream>![IMG_20250521_152127_815.jpg](https://github.com/user-attachments/assets/4efe756b-ed42-4c5c-9d8b-13b50339b786)
- # - [ ] []()_******_
```suggestion
#include <iostream>

******

}

if (j == m) {
cout << "Pattern found at index " << i - j << endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Author has not responded to the comments for over 2 weeks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Approved label CI does not add approved label to pull requests.
2 participants