Skip to content

Add Booth's algorithm for minimal string rotation - #7644

Merged
DenizAltunkapan merged 4 commits into
TheAlgorithms:masterfrom
vedant0517:contrib/booths-minimal-rotation
Oct 25, 2026
Merged

DenizAltunkapan merged 4 commits into
TheAlgorithms:masterfrom
vedant0517:contrib/booths-minimal-rotation

Conversation

@vedant0517

Copy link
Copy Markdown
Contributor

Summary

  • Implement Booth's algorithm to find the starting index of the lexicographically smallest cyclic rotation of a string.
  • Achieve O(n) time complexity and O(1) auxiliary space complexity.
  • Add JUnit tests covering empty strings, single characters, repeated characters, periodic strings, already-minimal rotations, and null input.
  • Include Javadoc documentation and an algorithm reference.

Example

For the input "baca", the lexicographically smallest rotation is "abac", which starts at index 3.

Complexity

  • Time: O(n)
  • Auxiliary Space: O(1)

Closes #7643

@codecov-commenter

codecov-commenter commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.21%. Comparing base (862de93) to head (ec19a52).

Files with missing lines Patch % Lines
...ava/com/thealgorithms/strings/BoothsAlgorithm.java 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7644   +/-   ##
=========================================
  Coverage     82.20%   82.21%           
- Complexity     8382     8392   +10     
=========================================
  Files           842      843    +1     
  Lines         26101    26125   +24     
  Branches       5090     5096    +6     
=========================================
+ Hits          21457    21478   +21     
- Misses         3857     3858    +1     
- Partials        787      789    +2     

☔ View full report in Codecov by Harness.
📢 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.

@vedant0517
vedant0517 marked this pull request as ready for review October 11, 2026 11:53
@DenizAltunkapan
DenizAltunkapan enabled auto-merge (squash) October 25, 2026 18:20
@DenizAltunkapan

Copy link
Copy Markdown
Member

@vedant0517 thanks!

@DenizAltunkapan
DenizAltunkapan merged commit 2dd1a0a into TheAlgorithms:master Oct 25, 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.

[FEATURE REQUEST] Add Booth's algorithm for lexicographically minimal string rotation

3 participants