Skip to content
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

KMP classic algorithm and unit tests #125

Merged
merged 4 commits into from
Oct 23, 2019
Merged

KMP classic algorithm and unit tests #125

merged 4 commits into from
Oct 23, 2019

Conversation

jonathanmcchesney
Copy link
Contributor

Story: #124

Added KMP algorithm to classics folder, along with a series of unit tests to bring the file coverage up to 100%.
Updated file to keep in line with eslint rules.
Added comments and time complexity of the KMP pattern matching algorithm.
Added example use case in file preamble.

@knaxus knaxus deleted a comment from jonathanmcchesney Oct 23, 2019
@knaxus knaxus deleted a comment from jonathanmcchesney Oct 23, 2019
/* *
* The time complexity of KMP algorithm is O(n) in the worst case
* Example use case: Pattern = ABCABCACA Text = AAABCBAABCABCACACABBCA
* LPSArray = [ 0, 0, 0, 1, 2, 3, 4, 0, 1 ]
Copy link
Member

Choose a reason for hiding this comment

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

It should be LPSArray = [ 0, 1, 0, 0, 1, 0 ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @TheSTL the pattern had been updated to ABCABCACA. I feel this is a more intuitive example. I believe [ 0, 0, 0, 1, 2, 3, 4, 0, 1 ] to be the correct LPS, if there are any more queries or amendments you would like to be made, I’ll updage the PR as appropriate. Cheers.

Copy link
Member

Choose a reason for hiding this comment

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

I think this example is more understandable from previous one to compute LPS.

Copy link
Member

@TheSTL TheSTL left a comment

Choose a reason for hiding this comment

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

Thanks @jonathanmcchesney for PR 💯

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.

2 participants