Content deleted Content added
→Booth's Algorithm: add docstring |
mNo edit summary |
||
Line 1:
In [[computer science]], the '''lexicographically minimal string rotation''' or '''lexicographically least circular substring''' is the problem of finding the [[String_(computer_science)#Rotations|rotation of a string]] possessing the lowest [[lexicographical order]] of all such rotations. For example, the lexicographically minimal rotation of "bbaaccaadd" would be "aaccaaddbb". It is possible for a string to have multiple lexicographically minimal rotations, but for most applications this does not matter as the rotations must be equivalent. Finding the lexicographically minimal rotation is useful as a way of [[Text normalization|normalizing]] strings. If the strings represent potentially [[
| author = Kellogg S. Booth
| last2 = Colbourn | first2 = Charles J.
Line 34:
| issn = 0020-0190 }}
</ref>
The algorithm uses a modified preprocessing function from the [[
<syntaxhighlight lang="python">
Line 56:
return k
</syntaxhighlight>
Of interest is that removing all lines of code which modify the value of {{mvar|k}} results in the original Knuth-Morris-Pratt preprocessing function, as {{mvar|k}} (representing the rotation) will remain zero. Booth's algorithm runs in {{tmath|O(n)}} time, where {{mvar|n}} is the length of the string. The algorithm performs at most {{tmath|3n}} comparisons in the worst case, and requires auxiliary memory of length {{mvar|n}} to hold the failure function table.
===Shiloach's Fast Canonization Algorithm===
Shiloach (1981)<ref>{{cite journal
| title = Fast canonization of circular strings
Line 108:
==See also==
* [[Lyndon word]]
* [[
==References==
|