Counting Palindromes in Substrings

We propose a data structure and an online algorithm to report the number of distinct palindromes in any substring of an input string. Assume that the string S of length n arrives symbol-by-symbol and every symbol is followed by zero or more queries of the form “report the number of distinct palindromes in S[i..j]”. We use \(O(n\log n)\) total time to process the string plus \(O(\log n)\) time per query. The required space is \(O(n\log n)\) in general and O(n) in a natural particular case. As a simple application, we describe an algorithm reporting all palindromic rich substrings of an input string in \(O(n\log n)\) time and O(n) space.

[1]  Luca Q. Zamboni,et al.  Palindromic richness , 2008, Eur. J. Comb..

[2]  Arseny M. Shur,et al.  Finding Distinct Subpalindromes Online , 2013, Stringology.

[3]  Robert E. Tarjan,et al.  Making Data Structures Persistent , 1989, J. Comput. Syst. Sci..

[4]  H. Wilf,et al.  Uniqueness theorems for periodic functions , 1965 .

[5]  Jeffrey Shallit,et al.  Palindromic rich words and run-length encodings , 2015, Inf. Process. Lett..

[6]  Juha Kärkkäinen,et al.  A subquadratic algorithm for minimum palindromic factorization , 2014, J. Discrete Algorithms.

[7]  Srecko Brlek,et al.  On The Palindromic Complexity Of Infinite Words , 2004, Int. J. Found. Comput. Sci..

[8]  Hideo Bannai,et al.  Diverse Palindromic Factorization Is NP-complete , 2015, DLT.

[9]  Paul F. Dietz Optimal Algorithms for List Indexing and Subset Rank , 1989, WADS.

[10]  Hideo Bannai,et al.  Computing Palindromic Factorizations and Palindromic Covers On-line , 2014, CPM.

[11]  Donald E. Knuth,et al.  Fast Pattern Matching in Strings , 1977, SIAM J. Comput..

[12]  Zvi Galil,et al.  A Linear-Time On-Line Recognition Algorithm for ``Palstar'' , 1978, JACM.

[13]  Zvi Galil Real-time algorithms for string-matching and palindrome recognition , 1976, STOC '76.

[14]  Arseny M. Shur,et al.  Pal k is Linear Recognizable Online , 2015, SOFSEM.

[15]  Giuseppe Pirillo,et al.  Episturmian words and some constructions of de Luca and Rauzy , 2001, Theor. Comput. Sci..

[16]  Arseny M. Shur,et al.  EERTREE: An efficient data structure for processing palindromes in strings , 2018, Eur. J. Comb..

[17]  Peter M. Fenwick,et al.  A new data structure for cumulative frequency tables , 1994, Softw. Pract. Exp..

[18]  Gwénaël Richomme,et al.  Counting distinct palindromes in a word in linear time , 2010, Inf. Process. Lett..

[19]  Glenn K. Manacher,et al.  A New Linear-Time ``On-Line'' Algorithm for Finding the Smallest Initial Palindrome of a String , 1975, JACM.