Skip to content

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

Open
vedant0517 wants to merge 3 commits into
TheAlgorithms:masterfrom
vedant0517:contrib/booths-minimal-rotation
Open

vedant0517 wants to merge 3 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

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.19%. Comparing base (e43ec38) to head (f33ad1a).

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.19%   82.19%           
- Complexity     8371     8377    +6     
=========================================
  Files           842      843    +1     
  Lines         26093    26117   +24     
  Branches       5090     5096    +6     
=========================================
+ Hits          21446    21467   +21     
  Misses         3858     3858           
- Partials        789      792    +3     

☔ 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
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

2 participants