Efficient Enumeration of Non-Equivalent Squares in Partial Words with Few Holes

  • Panagiotis Charalampopoulos
  • Maxime Crochemore
  • Costas S. Iliopoulos
  • Tomasz Kociumaka
  • Solon P. Pissis
  • Jakub Radoszewski
  • Wojciech Rytter
  • Tomasz Waleń
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10392)


A word of the form WW for some word \(W\in \varSigma ^*\) is called a square, where \(\varSigma \) is an alphabet. A partial word is a word possibly containing holes (also called don’t cares). The hole is a special symbol Open image in new window which matches (agrees with) any symbol from Open image in new window . A p-square is a partial word matching at least one square WW without holes. Two p-squares are called equivalent if they match the same set of squares. We denote by \( psquares (T)\) the number of non-equivalent p-squares which are factors of a partial word T. Let \(\mathrm {PSQUARES}_k(n)\) be the maximum value of \( psquares (T)\) over all partial words of length n with at most k holes. We show asymptotically tight bounds:
$$ c_1\cdot \min (nk^2,\, n^2) \le \mathrm {PSQUARES}_k(n) \le c_2\cdot \min (nk^2,\, n^2) $$
for some constants \(c_1,c_2>0\). We also present an algorithm that computes \( psquares (T)\) in \(\mathcal {O}(nk^3)\) time for a partial word T of length n with k holes. In particular, our algorithm runs in linear time for \(k=\mathcal {O}(1)\) and its time complexity near-matches the maximum number of non-equivalent p-square factors in a partial word.


  1. 1.
    Bannai, H., I, T., Inenaga, S., Nakashima, Y., Takeda, M., Tsuruta, K.: A new characterization of maximal repetitions by Lyndon trees. In: Indyk, P. (ed.) 26th Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2015, pp. 562–571. SIAM (2015)Google Scholar
  2. 2.
    Blanchet-Sadri, F., Bodnar, M., Nikkel, J., Quigley, J.D., Zhang, X.: Squares and primitivity in partial words. Discrete Appl. Math. 185, 26–37 (2015)MathSciNetCrossRefzbMATHGoogle Scholar
  3. 3.
    Blanchet-Sadri, F., Jiao, Y., Machacek, J.M., Quigley, J., Zhang, X.: Squares in partial words. Theor. Comput. Sci. 530, 42–57 (2014)MathSciNetCrossRefzbMATHGoogle Scholar
  4. 4.
    Blanchet-Sadri, F., Mercaş, R.: A note on the number of squares in a partial word with one hole. Inform. Theor. Appl. 43(4), 767–774 (2009)MathSciNetCrossRefzbMATHGoogle Scholar
  5. 5.
    Blanchet-Sadri, F., Mercaş, R.: The three-squares lemma for partial words with one hole. Theor. Comput. Sci. 428, 1–9 (2012)MathSciNetCrossRefzbMATHGoogle Scholar
  6. 6.
    Blanchet-Sadri, F., Mercaş, R., Scott, G.: Counting distinct squares in partial words. Acta Cybern. 19(2), 465–477 (2009)MathSciNetzbMATHGoogle Scholar
  7. 7.
    Blanchet-Sadri, F., Nikkel, J., Quigley, J.D., Zhang, X.: Computing primitively-rooted squares and runs in partial words. In: Kratochvíl, J., Miller, M., Froncek, D. (eds.) IWOCA 2014. LNCS, vol. 8986, pp. 86–97. Springer, Cham (2015). doi: 10.1007/978-3-319-19315-1_8 CrossRefGoogle Scholar
  8. 8.
    Crochemore, M., Hancart, C., Lecroq, T.: Algorithms on Strings. Cambridge University Press, Cambridge (2007)CrossRefzbMATHGoogle Scholar
  9. 9.
    Crochemore, M., Iliopoulos, C.S., Kociumaka, T., Kubica, M., Langiu, A., Radoszewski, J., Rytter, W., Szreder, B., Waleń, T.: A note on the longest common compatible prefix problem for partial words. J. Discrete Algorithms 34, 49–53 (2015)MathSciNetCrossRefzbMATHGoogle Scholar
  10. 10.
    Crochemore, M., Iliopoulos, C.S., Kubica, M., Radoszewski, J., Rytter, W., Waleń, T.: Extracting powers and periods in a word from its runs structure. Theor. Comput. Sci. 521, 29–41 (2014)MathSciNetCrossRefzbMATHGoogle Scholar
  11. 11.
    Crochemore, M., Rytter, W.: Squares, cubes, and time-space efficient string searching. Algorithmica 13(5), 405–425 (1995)MathSciNetCrossRefzbMATHGoogle Scholar
  12. 12.
    Deza, A., Franek, F., Thierry, A.: How many double squares can a string contain? Discrete Appl. Math. 180, 52–69 (2015)MathSciNetCrossRefzbMATHGoogle Scholar
  13. 13.
    Diaconu, A., Manea, F., Tiseanu, C.: Combinatorial queries and updates on partial words. In: Kutyłowski, M., Charatonik, W., Gębala, M. (eds.) FCT 2009. LNCS, vol. 5699, pp. 96–108. Springer, Heidelberg (2009). doi: 10.1007/978-3-642-03409-1_10 CrossRefGoogle Scholar
  14. 14.
    Fraenkel, A.S., Simpson, J.: How many squares can a string contain? J. Comb. Theory, Ser. A 82(1), 112–120 (1998)MathSciNetCrossRefzbMATHGoogle Scholar
  15. 15.
    Gusfield, D., Stoye, J.: Linear time algorithms for finding and representing all the tandem repeats in a string. J. Comput. Syst. Sci. 69(4), 525–546 (2004)MathSciNetCrossRefzbMATHGoogle Scholar
  16. 16.
    Halava, V., Harju, T., Kärki, T.: On the number of squares in partial words. RAIRO Theor. Inform. Appl. 44(1), 125–138 (2010)MathSciNetCrossRefzbMATHGoogle Scholar
  17. 17.
    Ilie, L.: A simple proof that a word of length \(n\) has at most \(2n\) distinct squares. J. Comb. Theory, Ser. A 112(1), 163–164 (2005)MathSciNetCrossRefzbMATHGoogle Scholar
  18. 18.
    Kociumaka, T.: Minimal suffix and rotation of a substring in optimal time. In: Grossi, R., Lewenstein, M. (eds.) Combinatorial Pattern Matching, CPM 2016. LIPIcs, vol. 54, pp. 28:1–28:12. Schloss Dagstuhl (2016)Google Scholar
  19. 19.
    Kolpakov, R.M., Kucherov, G.: Finding maximal repetitions in a word in linear time. In: 40th Annual Symposium on Foundations of Computer Science, FOCS 1999, pp. 596–604. IEEE Computer Society (1999)Google Scholar
  20. 20.
    Manea, F., Mercaş, R., Tiseanu, C.: An algorithmic toolbox for periodic partial words. Discrete Appl. Math. 179, 174–192 (2014)MathSciNetCrossRefzbMATHGoogle Scholar
  21. 21.
    Manea, F., Tiseanu, C.: Hard counting problems for partial words. In: Dediu, A.-H., Fernau, H., Martín-Vide, C. (eds.) LATA 2010. LNCS, vol. 6031, pp. 426–438. Springer, Heidelberg (2010). doi: 10.1007/978-3-642-13089-2_36 CrossRefGoogle Scholar

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  • Panagiotis Charalampopoulos
    • 1
  • Maxime Crochemore
    • 1
    • 2
  • Costas S. Iliopoulos
    • 1
  • Tomasz Kociumaka
    • 3
  • Solon P. Pissis
    • 1
  • Jakub Radoszewski
    • 1
    • 3
  • Wojciech Rytter
    • 3
  • Tomasz Waleń
    • 3
  1. 1.Department of InformaticsKing’s College LondonLondonUK
  2. 2.Université Paris-EstMarne-la-ValléeFrance
  3. 3.Faculty of Mathematics, Informatics and MechanicsUniversity of WarsawWarsawPoland

Personalised recommendations