Online and Dynamic Recognition of Squarefree Strings

  • Jesper Jansson
  • Zeshan Peng
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3618)


The online squarefree recognition problem is to detect the first occurrence of a square in a string whose characters are provided as input one at a time. We present an efficient algorithm to solve this problem for strings over arbitrarily ordered alphabets. Its running time is O(n log n), where n is the ending position of the first square, which matches the running times of the fastest known algorithms for the analogous offline problem. We also present a very simple algorithm for a dynamic version of the problem over general alphabets in which we are initially given a squarefree string, followed by a series of updates, and the objective is to determine after each update if the resulting string contains a square and if so, report it and stop.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Apostolico, A., Preparata, F.P.: Optimal off-line detection of repetitions in a string. Theoretical Computer Science 22(3), 297–315 (1983)zbMATHCrossRefMathSciNetGoogle Scholar
  2. 2.
    Bean, D.R., Ehrenfeucht, A., McNulty, G.F.: Avoidable patterns in strings of symbols. Pacific Journal of Mathematics 85(2), 261–294 (1979)zbMATHMathSciNetGoogle Scholar
  3. 3.
    Benson, G.: Tandem repeats finder: A program to analyze DNA sequences. Nucleic Acids Research 27(2), 573–580 (1999)CrossRefMathSciNetGoogle Scholar
  4. 4.
    Breslauer, D.: Efficient String Algorithmics. PhD thesis, Columbia University (1992)Google Scholar
  5. 5.
    Castelo, A.T., Martins, W., Gao, G.R.: TROLL – tandem repeat occurrence locator. Bioinformatics 18(4), 634–636 (2002)CrossRefGoogle Scholar
  6. 6.
    Choffrut, C., Karhumäki, J.: Combinatorics of words. In: Salomaa, A., Rozenberg, G. (eds.) Handbook of Formal Languages, vol. 1, pp. 329–438. Springer, Heidelberg (1997)Google Scholar
  7. 7.
    Crochemore, M.: An optimal algorithm for computing the repetitions in a word. Information Processing Letters 12(5), 244–250 (1981)zbMATHCrossRefMathSciNetGoogle Scholar
  8. 8.
    Crochemore, M.: Transducers and repetitions. Theoretical Computer Science 45, 63–86 (1986)zbMATHCrossRefMathSciNetGoogle Scholar
  9. 9.
    Crochemore, M., Rytter, W.: Jewels of Stringology. World Scientific, Singapore (2002)CrossRefGoogle Scholar
  10. 10.
    Farach-Colton, M., Ferragina, P., Muthukrishnan, S.: On the sorting-complexity of suffix tree construction. Journal of the ACM 47(6), 987–1011 (2000)zbMATHCrossRefMathSciNetGoogle Scholar
  11. 11.
    Gusfield, D.: Algorithms on Strings, Trees, and Sequences. Cambridge University Press, Cambridge (1997)zbMATHCrossRefGoogle Scholar
  12. 12.
    Karhumäki, J.: Automata on words. In: Ibarra, O.H., Dang, Z. (eds.) CIAA 2003. LNCS, vol. 2759, pp. 3–10. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  13. 13.
    Kumar, V.: Algorithms for constraint satisfaction problems: A survey. AI Magazine 12(1), 32–44 (1992)Google Scholar
  14. 14.
    Lee, J.H.M., Leung, H.-F., Won, H.W.: Performance of a comprehensive and efficient constraint library based on local search. In: Proceedings of the 11th Australian Joint Conference on Artificial Intelligence, pp. 191–202 (1998)Google Scholar
  15. 15.
    Leung, H.-F., Peng, Z., Ting, H.-F.: An efficient online algorithm for square detection. In: Chwa, K.-Y., Munro, J.I.J. (eds.) COCOON 2004. LNCS, vol. 3106, pp. 432–439. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  16. 16.
    Main, M.G., Bucher, W., Haussler, D.: Applications of an infinite square-free co-CFL. Theoretical Computer Science 49(2–3), 113–119 (1987)zbMATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    Main, M.G., Lorentz, R.J.: An O(n logn) algorithm for finding all repetitions in a string. Journal of Algorithms 5(3), 422–432 (1984)zbMATHCrossRefMathSciNetGoogle Scholar
  18. 18.
    Main, M.G., Lorentz, R.J.: Linear time recognition of squarefree strings. In: Apostolico, A., Galil, Z. (eds.) Combinatorial Algorithms on Words. NATO ASI Series, vol. F 12, pp. 271–278. Springer, Heidelberg (1985)Google Scholar
  19. 19.
    Wong, J.H.Y., Leung, H.-F.: Solving fuzzy constraint satisfaction problems with fuzzy GENET. In: Proceedings of the 10th IEEE International Conference on Tools with Artificial Intelligence, pp. 184–191 (1998)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Jesper Jansson
    • 1
  • Zeshan Peng
    • 1
  1. 1.Department of Computer ScienceThe University of Hong KongHong Kong

Personalised recommendations