How to find the number of the lexicographically minimal string rotation?

梦想的初衷 提交于 2019-12-21 12:40:49

问题


How to find the number of lexicographically minimal string rotation?

For example:

S = abab, N = 2
S = abca, N = 1
S = aaaa, N = 4

I tried Duval's algorithm, it works very long. The string length of 100000000 characters.


回答1:


Easy -- just determine the minimum period of the string. A string which is periodic in minimal period K will produce identical (and hence lexicographically equal) strings for exactly N/K different rotations, so whatever the lexicographic minimum is, it'll be the result of N/K different rotations.



来源:https://stackoverflow.com/questions/21026091/how-to-find-the-number-of-the-lexicographically-minimal-string-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!