Skip to content

feat(strings): add Kasai's algorithm for LCP array construction#7324

Merged
alxkm merged 2 commits intoTheAlgorithms:masterfrom
Keykyrios:feat/add-kasai-algorithm
Mar 18, 2026
Merged

feat(strings): add Kasai's algorithm for LCP array construction#7324
alxkm merged 2 commits intoTheAlgorithms:masterfrom
Keykyrios:feat/add-kasai-algorithm

Conversation

@Keykyrios
Copy link
Contributor

Description

This PR adds an implementation of Kasai's Algorithm to the strings directory. The algorithm constructs the Longest Common Prefix (LCP) array from a provided string and its Suffix Array in O(N) time complexity. This perfectly complements the existing SuffixArray.java implementation.

A comprehensive JUnit 5 test suite (KasaiAlgorithmTest.java) has also been included to validate various standard and edge cases. I have also verified that clang-format is completely satisfied.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Implement Kasai's algorithm to compute the Longest Common Prefix (LCP) array in O(N) time given a string and its suffix array. Add KasaiAlgorithm.java and KasaiAlgorithmTest.java.
@Keykyrios Keykyrios marked this pull request as ready for review March 18, 2026 18:11
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.46%. Comparing base (7d57c57) to head (7ea6636).

Files with missing lines Patch % Lines
...java/com/thealgorithms/strings/KasaiAlgorithm.java 96.15% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7324      +/-   ##
============================================
+ Coverage     79.43%   79.46%   +0.03%     
- Complexity     7062     7077      +15     
============================================
  Files           788      789       +1     
  Lines         23124    23150      +26     
  Branches       4545     4553       +8     
============================================
+ Hits          18368    18396      +28     
+ Misses         4022     4021       -1     
+ Partials        734      733       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@alxkm alxkm left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you for the contribution.

@alxkm alxkm merged commit af1d9d1 into TheAlgorithms:master Mar 18, 2026
7 checks passed
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.

3 participants