We present efficient algorithms computing all Abelian periods of two types in a word. Regular Abelian periods are computed in O(n log log n) randomized time which improves over the best previously known algorithm by almost a factor of n. The other algorithm, for full Abelian periods, works in O(n) time. As a tool we develop an O(n) time construction of a data structure that allows O(1) time gcd(i, j) queries for all 1 ≤ i, j ≤ n, this is a result of independent interest.
ACM Subject Classification
IntroductionThe area of Abelian stringology was initiated by Erdös who posed a question about the smallest alphabet size for which there exists an infinite Abelian-square-free word, see [11]. An example of such a word over five-letter alphabet was given by Pleasants [18] and afterwards the optimal example over four-letter alphabet was shown by Keränen [16]. Quite recently there have been several results on Abelian complexity in words [2,8,9, 10] and partial words [3,4] and on Abelian pattern matching [5,17]. Abelian periods were first defined and studied by Constantinescu and Ilie [6]. We say that two words are commutatively equivalent, if one can be obtained from the other by permuting its symbols. This relation can be conveniently described using Parikh vectors, which show frequency of each symbol of the alphabet in a word: x and y are commutatively equivalent if and only if the Parikh vectors P(x) and P(y) are equal.Let w be a non-empty word of length n over an alphabet Σ = {1, . . . , m}. We assume that m ≤ n, but if m is polynomially bounded, i.e. m = n O(1) , the letters of w can be renumbered in O(n) time so that m ≤ n. Let P(w) be an array such that P(w) [c] An integer q is called an Abelian period of w if for k = n q P 1,q = P q+1,2q = . . . = P (k−1)q+1,kq and P kq+1,n ≤ P 1,q .