Minimal Cyclic String Rotation
Eliminate cyclic starts until only the least rotation remains.
By Riano · Published · Updated · Report a correction
Minimal Cyclic String Rotation
The minimal cyclic string rotation problem asks to find the lexicographically least rotation of a given word. For example, the word "baca" has rotations "baca", "acab", "caba", and "abac", with "abac" being the lexicographically smallest.
Worked Example
Consider the word aaba. We double it to aabaaaba to simulate cyclic rotations without modular arithmetic. The distinct rotations are:
aaba(start index 0)abaa(start index 1)baaa(start index 2)aaab(start index 3)
Comparing these lexicographically: aaab < aaba < abaa < baaa.
The minimal rotation is aaab starting at index 3.
Experiment
In the interactive module (available at https://riano.app/module/minimal-cyclic-string-rotation), you can experiment with the algorithm:
- Select different preset words from the "Word preset" dropdown control.
- Observe the visualizer as it displays the doubled string and highlights the starting index (denoted as
k). - Test words with varying periodicity to see how the algorithm successfully eliminates inferior candidates.
Limitations
The original Booth algorithm published in 1980 contained a shortcut j - k >= n that could prematurely terminate and return an incorrect answer. Later errata by Booth corrected the condition to j - k > n, although the algorithm runs optimally even with the shortcut entirely removed. Additionally, this module focuses strictly on finite, lowercase ASCII strings within memory limits, and the interactive viewer requires the string to be small enough to render readably.
References
The algorithm and errata are thoroughly documented by its author.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Minimal Cyclic String Rotation module.
Try Minimal Cyclic String Rotation on Riano →