## Abstract

A string*w* is*primitive* if it is not a power of another string (i.e., writing*w* =*v*
^{k} implies*k* = 1. Conversely,*w* is a*square* if*w* =*vv*, with*v* a primitive string. A string*x* is*square-free* if it has no nonempty substring of the form*ww*. It is shown that the square-freedom of a string of*n* symbols over an arbitrary alphabet can be tested by a CRCW PRAM with*n* processors in*O*(log*n*) time and linear auxiliary space. If the cardinality of the input alphabet is bounded by a constant independent of the input size, then the number of processors can be reduced to*n*/log*n* without affecting the time complexity of this strategy. The fastest sequential algorithms solve this problem*O*(*n* log*n*) or*O*(*n*) time, depending on whether the cardinality of the input alphabet is unbounded or bounded, and either performance is known to be optimal within its class. More elaborate constructions lead to a CRCW PRAM algorithm for detecting, within the same*n*-processors bounds, all positioned squares in*x* in time*O*(log*n*) and using linear auxiliary space. The fastest sequential algorithms solve this problem in*O*(*n* log*n*) time, and such a performance is known to be optimal.

This is a preview of subscription content, log in to check access.

## References

- [1]
A. Apostolico, On Context-Constrained Squares and Repetitions in a String,

*RAIRO Inform. Théor.*18 (1984), 147–159. - [2]
A. Apostolico, M. J. Atallah, L. L. Larmore, and H. S. McFaddin, Efficient Parallel Algorithms for String Editing and Related Problems,

*SIAM J. Comput.***19**(5) (1990), 968–988. Also,*Proceedings of the 26th Allerton Conference on Communications, Control and Computing*, Monticello, Ill., Sept. 1988, pp. 253–263. - [3]
A. Apostolico and Z. Galil (eds.),

*Combinatorial Algorithms on Words*, Nato ASI Series F, Vol. 12, Springer-Verlag, Berlin, 1985. - [4]
A. Apostolico, C. Iliopoulos, G. Landau, B. Schieber, and U. Vishkin, Parallel Construction of a Suffix Tree, with Applications,

*Algorithmica***3**(1988), 347–365. - [5]
A. Apostolico and F. P. Preparata, Optimal Off-Line Detection of Repetitions in a String,

*Theoret. Comput. Sci.***22**(1983), 297–315. - [6]
A. Apostolico and F. P. Preparata. Structural Properties of the String Stratistics Problem

*J. Comput. System. Sci.***31**(3) (1985), 394–411. - [7]
O. Berkman, D. Breslauer, Z, Galil, B. Schieber, and U. Vishkin, Hightly Parallelizable Problems,

*Proceedings of the 21st ACM Symposium on Theory of Computing*, Seattle, Wash., May 1989, pp. 309–319. - [8]
K. T. Chen, R. H. Fox, and R. C. Lyndon, Free Differential Calculus, IV,

*Ann. of Math.***68**(1958), 81–95. - [9]
M. Crochemore, An Optimal Algorithm for Computing the Repetitions in a Word,

*Inform. Process. Lett.***12**(5) (1981), 244–250. - [10]
M. Crochemore, Recherche Linearire d'un Carré dans un Mot

*C. R. Acad. Sci. Paris Sér. I***296**(1983), 781–784. - [11]
M. Crochemore and W. Rytter, Usefulness of the Karp-Miller-Rosenberg Strategy in the Design of Parallel Algorithms,

*Theoret. Comput. Sci.***88**(1991), 59–82. - [12]
J. P. Duval, Factorizing Words over an Ordered Alphabet,

*J. Algorithms***4**(1983), 363–381. - [13]
F. E. Fich, R. L. Ragde, and A. Wigderson, Relations between Concurrent-Write Models of Parallel Computation,

*Proceedings of the 3rd A CM Symposium on Principles of Distributed Computing*, Vancouver, B.C., Aug. 27–29, 1984, pp. 179–184. - [14]
M. Lothaire,

*Combinatorics on Words*, Addison-Wesley, Reading, Mass., 1982. - [15]
R. C. Lyndon and M. P. Shutzenberger, The Equation

*a*^{M}*= b*^{N}*c*^{P}in a Free Group,*Michigan Math. J.***9**(1962), 289–298. - [16]
M. G. Main and R. J. Lorentz, An

*O(n*log*n)*Algorithm for Finding all Repetitions in a String,*J. Algorithms***5**(1985), 422–432. - [17]
M. G. Main and R. J. Lorentz, Linear-Time Recognition of Square-Free Strings, in

*Combinatorial Algorithms on Words*(A. Apostolico and Z. Galil, eds.), Nato ASI Series F, Vol. 12, Springer-Verlag, Berlin, 1985, pp. 271–278. - [18]
M. Rabin, Discovering Repetitions in Strings, in

*Combinatorial Algorithms on Words*(A. Apostolico and Z. Galil, eds), Nato ASI Series F, Vol. 12, Springer-Verlag, Berlin, 1985, pp. 279–288. - [19]
A. Thue, Über unendliche Zeichenreihen,

*Norske Vid. Selsk. I Mat. Natur. Kl. Skr.*, Christiania no. 7 (1906), 1–22. - [20]
A. Thue, “Über die gegenseitige Lage gleicher Teile gewisser Zeichenreihen”,

*Norske Vid. Selsk. I Mat.-Natur. Kl. Skr.*, Christiania no. 1 (1912), 1–67. - [21]
C. K. Wong and A. K. Chandra, Bounds for the String Editing Problem,

*J. Assoc. Comput. Mach.***23**(1) (1976), 13–16.

## Author information

### Affiliations

## Additional information

This research was supported, through the Leonardo Fibonacci Institute, by the Istituto Trentino di Cultura, Trento, Italy. Additional support was provided by the French and Italian Ministries of Education, by the National Research Council of Italy, by the British Research Council Grant SERC-E76797, by NSF Grant CCR-89-00305, by NIH Library of Medicine Grant ROI LM05118, by AFOSR Grant 90-0107, and by NATO Grant CRG900293.

Communicated by C. K. Wong.

## Rights and permissions

## About this article

### Cite this article

Apostolico, A. Optimal parallel detection of squares in strings.
*Algorithmica* **8, **285–319 (1992). https://doi.org/10.1007/BF01758848

Received:

Revised:

Issue Date:

### Key words

- Parallel computation
- Combinatorial algorithms on words
- String matching
- Avoidable regularities
- Squares and repetitions in a string