Tight Tradeoffs for RealTime Approximation of Longest Palindromes in Streams
 128 Downloads
Abstract
We consider computing a longest palindrome in the streaming model, where the symbols arrive onebyone and we do not have random access to the input. While computing the answer exactly using sublinear space is not possible in such a setting, one can still hope for a good approximation guarantee. Our contribution is twofold. First, we provide lower bounds on the space requirements for randomized approximation algorithms processing inputs of length n. We rule out Las Vegas algorithms, as they cannot achieve sublinear space complexity. For Monte Carlo algorithms, we prove a lower bound of \(\varOmega ( M \log \min \{\varSigma ,M\})\) bits of memory; here \(M=n/E\) for approximating the answer with additive error E, and \(M= \log n/\log (1+\varepsilon )\) for approximating the answer with multiplicative error \((1 + \varepsilon )\). Second, we design four realtime algorithms for this problem. Three of them are Monte Carlo approximation algorithms for additive error, “small” and “big” multiplicative errors, respectively. Each algorithm uses \(\mathcal {O}(M)\) words of memory. Thus the obtained lower bounds are asymptotically tight up to a logarithmic factor. The fourth algorithm is deterministic and finds a longest palindrome exactly if it is short. This algorithm can be run in parallel with a Monte Carlo algorithm to obtain better results in practice. Overall, both the time and space complexity of finding a longest palindrome in a stream are essentially settled.
Keywords
Palindrome Streaming Lower bound Realtime algorithmMathematics Subject Classification
68W32 68W25 68Q251 Introduction
In the streaming model of computation, a very long input arrives sequentially in small portions and cannot be stored in full due to space limitation. There is a variation of this model where several passes over the input stream are available, but in this paper we consider only the standard onepass model. While wellstudied in general, streaming is a rather recent trend in algorithms on strings. The main goals are minimizing the space complexity, i.e., avoiding storing the already seen prefix of the string explicitly, and designing realtime algorithm, i.e., processing each symbol in worstcase constant time. However, the algorithms are usually randomized and return the correct answer with high probability. The prime example of a problem on string considered in the streaming model is pattern matching, where we want to detect an occurrence of a pattern in a given text. It is somewhat surprising that one can actually solve it using polylogarithmic space in the streaming model, as proved by Porat and Porat [16]. A simpler solution was later given by Ergün et al. [6], while Breslauer and Galil designed a realtime algorithm [3]. Similar questions studied in such setting include multiplepattern matching [4], approximate pattern matching [5], and parametrized pattern matching [11].
We consider computing a longest palindrome in the streaming model, where a palindrome is a fragment which reads the same in both directions. This is one of the basic questions concerning regularities in texts and it has been extensively studied in the classical nonstreaming setting, see [1, 8, 13, 15] and the references therein. The notion of palindromes, but with a slightly different meaning, is very important in computational biology, where one considers strings over \(\{A,T,C,G\}\) and a palindrome is a sequence equal to its reverse complement (a reverse complement reverses the sequences and interchanges A with T and C with G); see [9] and the references therein for a discussion of their algorithmic aspects. Our results generalize to biological palindromes in a straightforward manner.
We denote by \({\textsf {LPS}}\) the following problem: given a string S, find the maximum length of a palindrome in S and a starting position of a palindrome of such length in S. Solving \({\textsf {LPS}}\) in the streaming model was first considered by Berenbrink et al. [2], who developed tradeoffs between the bound on the error and the space complexity for approximating the length of the longest palindrome with either additive or multiplicative error.^{1} They presented the algorithms solving the \({\textsf {LPS}}\) problem (i) in \(\mathcal {O}\big (\frac{n\sqrt{n}}{E}\big )\) time and \(\mathcal {O}\big (\frac{n}{E}\big )\) space with the additive error \(E\in [1,\sqrt{n}]\); (ii) in \(\mathcal {O}\big (\frac{n\log n}{\varepsilon \log (1+\varepsilon )}\big )\) time and \(\mathcal {O}\big (\frac{\log n}{\varepsilon \log (1+\varepsilon )}\big )\) space with the multiplicative error \((1+\varepsilon )\), where \(\varepsilon <1\); (iii) in \(\mathcal {O}(n)\) time and \(\mathcal {O}(\sqrt{n})\) space exactly, given the promise that the longest palindrome is shorter than\(\sqrt{n}\). All their algorithms are Monte Carlo, i.e., return the correct answer with high probability. They also proved that any Las Vegas algorithm achieving additive error \(E\) must necessarily use \(\varOmega \big (\frac{n}{E}\log \varSigma \big )\) bits of memory, which matches the space complexity of their Monte Carlo solution up to a logarithmic factor in the \(E\in [1,\sqrt{n}]\) range. These results leave a number of open questions both on more efficient algorithms (e.g., only the algorithm (iii) and a specific case of algorithm (i) are lineartime) and on tight lower bounds for the space complexity, in particular, for Monte Carlo algorithms. In the present paper we answer all these questions, essentially settling space and time complexity of \({\textsf {LPS}}\). As in [2], we use hashes and other common primitives of the streaming model, but otherwise our technique is different; in particular, we heavily rely on combinatorial lemmas on strings. This paper extends the early version [10] presented at CPM 2016.

Algorithm A for \({\textsf {LPS}}\) with additive error \(E\in [1,n]\) uses \(\mathcal {O}(n/E)\) words of memory. Compared to (i), it uses the same space, works faster if \(E=o(\sqrt{n})\), and lifts the restriction on E; another advantage is independence of the working time of the error. The space usage exactly matches the lower bound under reasonable assumptions \(\varSigma >n^{0.01}, E<n^{0.99}\)

Algorithm M for \({\textsf {LPS}}\) with multiplicative error \(\varepsilon \in (0, 1]\) uses \(\mathcal {O}\big (\frac{\log (n\varepsilon )}{\varepsilon }\big )\) words of memory. Compared to (ii), the space bound is lowered by at least the factor of \(\varepsilon ^{1}\) (since \(\log (1+\varepsilon )\) is equivalent to \(\varepsilon \) whenever \(\varepsilon <1\)), the time bound is lowered by the factor of \(\varepsilon ^{2}\cdot \log n\). The space usage matches the lower bound up to a logarithmic factor in the worst case (if \(\varepsilon \) is a constant and \(\varSigma =\mathcal {O}(\log n)\)); the match is exact if \(\varepsilon <n^{0.01},\varSigma >n^{0.01}\)

Algorithm M’ for \({\textsf {LPS}}\) with multiplicative error \(\varepsilon \in (1, n]\) uses \(\mathcal {O}\big (\frac{\log n}{\log (1+\varepsilon )}\big )\) words of memory. It has no analogs in [2] and matches the space lower bound up to a logarithmic factor
The paper is organized as follows: we study lower bounds in Sect. 2, and algorithms in Sect. 3. We also note that Monte Carlo algorithms compute hash values of certain substrings of the input string and use these values to check whether a substring is a palindrome; false positives correspond to hash collisions, false negatives are impossible.
1.1 Notation and Definitions
Let S denote a string of length n over an alphabet \(\varSigma =\{1,\ldots ,N\}\), where N is polynomial in n. We write S[i] for the ith symbol of S and \(S[i\ldots j]\) for its substring (or factor) \(S[i] S[i {+} 1] \cdots S[j]\); thus, \(S[1\ldots n]=S\). A prefix (resp. suffix) of S is a substring of the form \(S[1\ldots j]\) (resp., \(S[j\ldots n]\)). A string S is a palindrome if it equals its reversal\(S[n]S[n{}1]\cdots S[1]\). By L(S) we denote the length of a longest palindrome which is a factor of S. The symbol \(\log \) stands for the binary logarithm.
We consider the streaming model of computation: the input string \(S[1\ldots n]\) (called the stream) is read left to right, one symbol at a time, and cannot be stored, because the available space is sublinear in n. The space is counted as the number of \(\mathcal {O}(\log n)\)bit machine words. An algorithm is realtime if the number of operations between two reads is bounded by a constant. An approximation algorithm for a maximization problem has additive errorE (resp., multiplicative error\(\varepsilon \)) if it finds a solution with the cost at least \(OPTE\) (resp., \(\frac{OPT}{1+\varepsilon }\)), where OPT is the cost of optimal solution; here both E and \(\varepsilon \) can be functions of the size of the input. For an instance \({\textsf {LPS}}(S)\) of the \({\textsf {LPS}}\) problem, \(OPT=L(S)\).
A Las Vegas algorithm always returns a correct answer, but its working time and memory usage on the inputs of length n are random variables. A Monte Carlo algorithm gives a correct answer with high probability (greater than \(11/n\)) and has deterministic working time and space.
2 Lower Bounds
In this section we use Yao’s minimax principle [18] to prove lower bounds on the space complexity of the \({\textsf {LPS}}\) problem in the streaming model, where the length n and the alphabet \(\varSigma \) of the input stream are specified. We denote this problem by LPS\(_{\varSigma }[n]\).
Theorem 1
(Yao’s minimax principle for randomized algorithms) Let \(\mathcal {X}\) be the set of inputs for a problem and \(\mathcal {A}\) be the set of all deterministic algorithms solving it. For every \(x \in \mathcal {X}\) and \(a \in \mathcal {A}\), let \(c(a,x)\ge 0\) be the cost of running a on x.
Let \(\mathcal {P},\mathcal {Q}\) be probability distributions over \(\mathcal {A}\) and \(\mathcal {X}\), respectively. Then \(\max _{x \in \mathcal {X}} \mathbf {E}_{A \sim \mathcal {P}}[c(A,x)] \ge \min _{a \in \mathcal {A}} \mathbf {E}_{X \sim \mathcal {Q}}[c(a,X)].\)
We use the above theorem for both Las Vegas and Monte Carlo algorithms. For Las Vegas algorithms, we consider only correct algorithms, and c(x, a) is the memory usage. For Monte Carlo algorithms, we consider all algorithms (not necessarily correct) with memory usage not exceeding a certain threshold, and c(x, a) is the correctness indicator function, i.e., \(c(x,a)=0\) if the algorithm is correct and \(c(x,a)=1\) otherwise.
Our proofs will be based on appropriately chosen padding. The padding requires a constant number of fresh characters. If \(\varSigma \) is twice as large as the number of required fresh characters, we can still use half of it to construct a difficult input instance, which does not affect the asymptotics. Otherwise, we construct a difficult input instance over \(\varSigma \), then add enough new fresh characters to facilitate the padding, and finally reduce the resulting larger alphabet to binary at the expense of increasing the size of the input by a constant factor.
Lemma 1
For any alphabet \(\varSigma =\{1,2,\ldots ,\sigma \}\) there exists a morphism \(h : \varSigma ^* \rightarrow \{0,1\}^*\) such that, for any \(c\in \varSigma \), \(h(c) = 2\sigma +6\) and, for any string w, w contains a palindrome of length \(\ell \) if and only if h(w) contains a palindrome of length \((2\sigma +6)\cdot \ell \).
Proof

either is centered inside some 00 and thus corresponds to a palindrome of odd length \(\ell \) in w;

or is centered in the middle between two consecutive occurrences of 00 and thus corresponds to a palindrome of even length \(\ell \) in w.
For the padding we will often use an infinite string \(\nu = 0^11^10^21^20^31^3\ldots \), or more precisely its prefixes of length d, denoted \(\nu (d)\). Here 0 and 1 should be understood as two characters not belonging to the original alphabet. The longest palindrome in \(\nu (d)\) has length \(\mathcal {O}(\sqrt{d})\).
Theorem 2
(Las Vegas approximation) Let \(\mathsf {A}\) be a Las Vegas streaming algorithm solving LPS\(_{\varSigma }[n]\) with additive error \(E\le 0.99 n\) or multiplicative error \((1+\varepsilon ) \le 100\) using s(n) bits of memory. Then \(\mathbf {E}[s(n)]=\varOmega (n \log \varSigma )\).
Proof
By Theorem 1, it is enough to construct a probability distribution \(\mathcal {Q}\) over \(\varSigma ^n\) such that for any deterministic algorithm \(\mathsf {D}\), its expected memory usage on a string chosen according to \(\mathcal {q}\) is \(\varOmega (n \log \varSigma )\) in bits.
Consider solving LPS\(_{\varSigma }[n]\) with additive error \(E\). We define \(\mathcal {Q}\) as the uniform distribution over \(\nu (\frac{E}{2}) x \$\$ y \nu (\frac{E}{2})^R\), where \(x,y \in \varSigma ^{n'}\), \(n' = \frac{n}{2}\frac{E}{2}1\), and $ is a special character not in \(\varSigma \). Let us look at the memory usage of \(\mathsf {D}\) after having read \(\nu (\frac{E}{2}) x\). We say that x is “good” when the memory usage is at most \(\frac{n'}{2}\log \varSigma \) and “bad” otherwise. Assume that \(\frac{1}{2}\varSigma ^{n'}\) of all x’s are good, then there are two strings \(x \not = x'\) such that the state of \(\mathsf {D}\) after having read both \(\nu (\frac{E}{2}) x\) and \(\nu (\frac{E}{2}) x'\) is exactly the same. Hence the behavior of \(\mathsf {D}\) on \(\nu (\frac{E}{2}) x\$\$ x^R \nu (\frac{E}{2})^R\) and \(\nu (\frac{E}{2}) x'\$\$ x^R \nu (\frac{E}{2})^R\) is exactly the same. The former is a palindrome of length \(n = 2n'+E+2\), so \(\mathsf {D}\) must answer at least \(2n'+2\), and consequently the latter also must contain a palindrome of length at least \(2n'+2\). A palindrome inside \(\nu (\frac{E}{2}) x'\$\$ x^R \nu (\frac{E}{2})^R\) is either fully contained within \(\nu (\frac{E}{2})\), \(x'\), \(x^R\) or it is a middle palindrome. But the longest palindrome inside \(\nu (\frac{E}{2})\) is of length \(\mathcal {O}(\sqrt{E})<2n'+2\) (for n large enough) and the longest palindrome inside x or \(x^R\) is of length \(n'<2n'+2\), so since we have exluded other possibilities, \(\nu (\frac{E}{2}) x'\$\$ x^R \nu (\frac{E}{2})^R\) contains a middle palindrome of length \(2n'+2\). This implies that \(x=x'\), which is a contradiction. Therefore, at least \(\frac{1}{2}\varSigma ^{n'}\) of all x’s are bad. But then the expected memory usage of \(\mathsf {D}\) is at least \(\frac{n'}{4}\log \varSigma \), which for \(E\le 0.99 n\) is \(\varOmega (n \log \varSigma )\) as claimed.
Now consider solving LPS\(_{\varSigma }[n]\) with multiplicative error \((1+\varepsilon )\). An algorithm with multiplicative error \((1+\varepsilon )\) can also be considered as having additive error \(E=n \cdot \frac{\varepsilon }{1+\varepsilon }\), so if the expected memory usage of such an algorithm is \(o(n\log \varSigma )\) and \((1+\varepsilon ) \le 100\) then we obtain an algorithm with additive error \(E\le 0.99n\) and expected memory usage \(o(n\log \varSigma )\), which we already know to be impossible.\(\square \)
Now we move to Monte Carlo algorithms. We first consider exact algorithms solving LPS\(_{\varSigma }[n]\); lower bounds on approximation algorithms will be then obtained by padding the input appropriately. We introduce an auxiliary problem midLPS\(_{\varSigma }[n]\), which is to compute the length of the middle palindrome in a string of even length n over an alphabet \(\varSigma \).
Lemma 2
There exists a constant \(\gamma \) such that any randomized Monte Carlo streaming algorithm \(\mathsf {A}\) solving midLPS\(_{\varSigma }[n]\) or LPS\(_{\varSigma }[n]\) exactly with probability \(1\frac{1}{n}\) uses at least \(\gamma \cdot n \log \min \{\varSigma , n\}\) bits of memory.
Proof
First we prove that if \(\mathsf {A}\) is a Monte Carlo streaming algorithm solving midLPS\(_{\varSigma }[n]\) exactly using less than \(\lfloor \frac{n}{2} \log \varSigma  \rfloor \) bits of memory, then its error probability is at least \(\frac{1}{n\varSigma }\).
By Theorem 1, it is enough to construct probability distribution \(\mathcal {Q}\) over \(\varSigma ^n\) such that for any deterministic algorithm \(\mathsf {D}\) using less than \(\lfloor \frac{n}{2} \log \varSigma  \rfloor \) bits of memory, the expected probability of error on a string chosen according to \(\mathcal {Q}\) is at least \(\frac{1}{n\varSigma }\).
Choose an arbitrary maximal matching of strings from \(\varSigma ^{n'}\) into pairs \((x,x')\) such that \(\mathsf {D}\) is in the same state after reading either x or \(x'\). At most one string per state of \(\mathsf {D}\) is left unpaired, that is at most \(2^{\lfloor \frac{n}{2} \log \varSigma  \rfloor 1}\) strings in total. Since there are \(\varSigma ^{n'}=2^{n' \log \varSigma } \ge 2\cdot 2^{\lfloor \frac{n}{2} \log \varSigma  \rfloor 1}\) possible strings of length \(n'\), at least half of the strings are paired. Let s be longest common suffix of x and \(x'\), so \(x = v c s\) and \(x' = v' c' s\), where \(c \not = c'\) are single characters. Then \(\mathsf {D}\) returns the same answer on \(w(x,n's,c)\) and \(w(x',n's,c)\), even though the length of the middle palindrome is exactly 2s in one of them, and at least \(2s+2\) in the other one. Therefore, \(\mathsf {D}\) errs on at least one of these two inputs. Similarly, it errs on either \(w(x,n's,c')\) or \(w(x,n's,c')\). Thus the error probability is at least \(\frac{1}{2n'\varSigma } = \frac{1}{n\varSigma }\).
To obtain a lower bound for Monte Carlo additive approximation, we observe that any algorithm solving LPS\(_{\varSigma }[n]\) with additive error \(E\) can be used to solve LPS\(_{\varSigma }[\frac{nE}{E+1}]\) exactly by inserting \(\frac{E}{2}\) zeroes between every two characters, in the very beginning, and in the very end. However, this reduction requires \(\log (\frac{E}{2})\le \log n\) additional bits of memory for counting up to \(\frac{E}{2}\) and cannot be used when the desired lower bound on the required number of bits \(\varOmega (\frac{n}{E}\log \min (\varSigma ,\frac{n}{E})\) is significantly smaller than \(\log n\). Therefore, we need a separate technical lemma which implies that both additive and multiplicative approximation with error probability \(\frac{1}{n}\) require \(\varOmega (\log n)\) bits of space.
Lemma 3
Let \(\mathsf {A}\) be any randomized Monte Carlo streaming algorithm solving LPS\(_{\varSigma }[n]\) with additive error at most 0.99n or multiplicative error at most \(n^{0.49}\) and error probability \(\frac{1}{n}\). Then \(\mathsf {A}\) uses \(\varOmega (\log n)\) bits of memory.
Proof
By Theorem 1, it is enough to construct a probability distribution \(\mathcal {Q}\) over \(\varSigma ^n\) such that for any deterministic algorithm \(\mathsf {D}\) using at most \(s(n)=o(\log n)\) bits of memory, the expected probability of error on a string chosen according to \(\mathcal {Q}\) is \(\frac{1}{2^{s(n)+2}} > \frac{1}{n}\).
Let \(n' = s(n)+1\). For any \(x,y \in \varSigma ^{n'}\), let \(w(x,y) = \nu (\frac{n}{2}n')^R x y^R \nu (\frac{n}{2}n')\). Observe that if \(x=y\) then w(x, y) contains a palindrome of length n, and otherwise the longest palindrome there has length at most \(2n'+\mathcal {O}(\sqrt{n}) = \mathcal {O}(\sqrt{n})\), thus any algorithm with additive error of at most 0.99n or with a multiplicative error at most \(n^{0.49}\) must be able to distinguish between these two cases (for n large enough).
Let \(S \subseteq \varSigma ^{n'}\) be an arbitrary family of strings of length \(n'\) such that \(S = 2 \cdot 2^{s(n)}\), and let \(\mathcal {Q}\) be the uniform distribution on all strings of the form w(x, y), where x and y are chosen uniformly and independently from S. By a counting argument, we can create at least \(\frac{S}{4}\) pairs \((x,x')\) of elements from S such that the state of \(\mathsf {D}\) is the same after having read \(\nu (\frac{n}{2}n')^Rx\) and \(\nu (\frac{n}{2}n')^Rx'\). (If we create the pairs greedily, at most one such x per state of memory can be left unpaired, so at least \(S  2^{s(n)} = \frac{S}{2}\) elements are paired.) Thus, \(\mathsf {D}\) cannot distinguish between \(w(x,x')\) and w(x, x), and between \(w(x',x')\) and \(w(x',x)\), so its error probability must be at least \(\frac{S/2}{S^2} = \frac{1}{4\cdot 2^{s(n)}}\). Thus if \(s(n) = o(\log n)\), the error rate is at least \(\frac{1}{n}\) for n large enough, a contradiction.
\(\square \)
Combining the reduction with the technical lemma and taking into account that we are reducing to a problem with string length of \(\varTheta (\frac{n}{E})\), we obtain the following.
Theorem 3
(Monte Carlo additive approximation) Let \(\mathsf {A}\) be any randomized Monte Carlo streaming algorithm solving LPS\(_{\varSigma }[n]\) with additive error \(E\) with probability \(1\frac{1}{n}\). If \(E\le 0.99n\) then \(\mathsf {A}\) uses \(\varOmega (\frac{n}{E} \log \min \{\varSigma ,\frac{n}{E}\} )\) bits of memory.
Proof
Finally, we consider multiplicative approximation. The proof follows the same basic idea as of Theorem 3, however is more technically involved. The main difference is that due to uneven padding, we are reducing to midLPS\(_{\varSigma }[n']\) instead of LPS\(_{\varSigma }[n']\).
Theorem 4
(Monte Carlo multiplicative approximation) Let \(\mathsf {A}\) be any randomized Monte Carlo streaming algorithm solving LPS\(_{\varSigma }[n]\) with multiplicative error \((1+\varepsilon )\) with probability \(1\frac{1}{n}\). If \(n^{0.98} \le \varepsilon \le n^{0.49}\) then \(\mathsf {A}\) uses \(\varOmega (\frac{\log n}{\log (1+\varepsilon )}\log \min \{\varSigma ,\frac{\log n}{\log (1+\varepsilon )}\})\) bits of memory.
Proof
3 RealTime Algorithms
In this section we design realtime Monte Carlo algorithms within the space bounds matching the lower bounds from Sect. 2 up to a factor bounded by \(\log n\). The algorithms make use of the hash function known as the Karp–Rabin fingerprint [12]. We first describe this function and its properties and then provide an overview of our algorithms.
Proposition 1
Definition 1
For an input stream S, its ith frameI(i) is defined as the tuple \((i, F^F(1,i{}1), F^R(1,i{}1), r^{(i  1)}\bmod p, r^{i}\bmod p)\).
The proposition below is immediate from definitions and Proposition 1.
Proposition 2
 (1)
Given I(i) and S[i], the tuple \(I(i{+}1)\) can be computed in \(\mathcal {O}(1)\) time.
 (2)
Given I(i) and \(I(j{+}1)\), the string \(S[i\ldots j]\) can be checked for being a palindrome in \(\mathcal {O}(1)\) time.
All algorithms in this section follow the same scheme. The outer cycle works in \(n=S\) iterations; on ith iteration, the symbol S[i] is read and processed, and the \((i+1)\)th frame is computed from the ith frame. Each algorithm computes all frames but stores only a fraction of them, based on the available space. After reading S[i], each algorithm checks whether some suffix of \(S[1\ldots i]\) is a palindrome of bigger length than the longest previously found palindrome, and updates the longest palindrome respectively. The suffixes available for this check depend on stored frames; each check takes \(\mathcal {O}(1)\) time by Proposition 2 (2). Several combinatorial lemmas are proved to show that on each iteration it is sufficient to check a constant number of suffixes.
Assume that \(S[i\ldots j]\) is the longest palindrome in S. It is quite probable that the ith frame will be unavailable after reading S[j]. However, we will be able to show that in all cases some “close enough” \((i{+}k)\)th frame will be available after reading \(S[j{}k]\). Then the palindrome \(S[i{+}k\ldots j{}k]\) will be found at the \((j{}k)\)th iteration, providing the approximation of the longest palindrome within the required error bound.
The technical part of the algorithms is the maintenance of the list of stored frames in a way that (a) guarantees the approximation error; (b) provides a constanttime access to the frames needed on each particular iteration; (c) allows a constanttime update at each iteration.
3.1 Additive Error
Theorem 5
There is a realtime Monte Carlo algorithm solving each instance \({\textsf {LPS}}(S)\) with the additive error \(E=E(n)\) using \(\mathcal {O}(n/E)\) space, where \(n=S\).
First we present a simple (and slow) algorithm which solves the posed problem, i.e., finds in S a palindrome of length \(\ell (S)\ge L(S)E\), where L(S) is the length of the longest palindrome in S. Later this algorithm will be converted into a realtime one. We store the frames I(j) for some values of j in a doublylinked list SP in the decreasing order of j’s. The longest palindrome currently found is stored as a pair \(answer=(pos,len)\), where pos is its initial position and len is its length. Let \( t_E= \lfloor \frac{E}{2} \rfloor \).
Proposition 3
Algorithm ABasic finds in S a palindrome of length \(\ell (S)\ge L(S)E\) using \(\mathcal {O}(n/E)\) time per iteration and \(\mathcal {O}(n/E)\) space.
Proof
The resource to speed up Algorithm ABasic stems from the following
Lemma 4
During one iteration, the length answer.len is increased by at most \(2 \cdot t_E\).
Proof
Let \(S[j \ldots i]\) be the longest palindrome found at the ith iteration. If \(i  j + 1 \le 2 t_E\) then the statement is obviously true. Otherwise the palindrome \(S[j {+} t_E \ldots i {} t_E]\) of length \(i  j + 1  2 t_E\) was considered before (at the \((i {} t_E)\)th iteration), and the statement holds again. \(\square \)
3.2 Multiplicative Error for \({\varepsilon \le 1}\)
Theorem 6
There is a realtime Monte Carlo algorithm solving each instance \({\textsf {LPS}}(S)\) with multiplicative error \(\varepsilon =\varepsilon (n)\in (0,1]\) using \(\mathcal {O}\big (\frac{\log (n \varepsilon )}{\varepsilon }\big )\) space, where \(n=S\).
As in the previous section, we first present a simpler algorithm MBasic with nonlinear working time and then upgrade it to a realtime algorithm. The algorithm must find a palindrome of length \(\ell (S)\ge \frac{L(S)}{1+\varepsilon }\). The next lemma is straightforward.
Lemma 5
If \(\varepsilon \in (0,1]\), the condition \(\ell (S)\ge L(S)(1\frac{\varepsilon }{2})\) implies \(\ell (S)\ge \frac{L(S)}{1+\varepsilon }\).
Lemma 6
For any integers \(a \ge 1\) and \(b \ge 0\), there exists a unique integer \(j \in [a, a+2^b)\) such that \(\textit{ttl}(j) \ge 2^{q_\varepsilon +2+b}\).
Proof
By (9), \(\textit{ttl}(j) \ge 2^{q_\varepsilon + 2 + b}\) if and only if \(\beta (j)\ge b\), i.e., j is divisible by \(2^b\) by the definition of \(\beta \). Among any \(2^b\) consecutive integers, exactly one has this property.\(\square \)
Lemma 7
After each iteration, the first interval (resp., the last interval; each of the remaining intervals) in (10) contains \(2^{q_\varepsilon + 2}\) (resp., at most \(2^{q_\varepsilon + 1}\); exactly \(2^{q_\varepsilon + 1}\)) positions for which the frames are stored in the list SP.
The number of the intervals in (10) is \(\mathcal {O}(\log (n\varepsilon ))\), so from Lemma 7 and the definition of \(q_\varepsilon \) we have the following.
Lemma 8
After each iteration, the size of the list SP is \(\mathcal {O}\big (\frac{\log (n\varepsilon )}{\varepsilon }\big )\).
Proposition 4
Algorithm MBasic finds a palindrome of length \(\ell (S)\ge \frac{L(S)}{1+\varepsilon }\) using \(\mathcal {O}\big (\frac{\log (n\varepsilon )}{\varepsilon }\big )\) time per iteration and \(\mathcal {O}\big (\frac{\log (n\varepsilon )}{\varepsilon }\big )\) space.
Proof
Both the time per iteration and the space are dominated by the size of the list SP. Hence the required complexity bounds follow from Lemma 8. For the proof of correctness, let \(S[i\ldots j]\) be a palindrome of length L(S). Further, let \(d = \lfloor \log L(S)\rfloor \).
Now we speed up Algorithm MBasic. It has two slow parts: deletions from the list SP and checks for palindromes. Lemmas 9 and 10 show that, similar to Sect. 3.1, \(\mathcal {O}(1)\) checks are enough at each iteration.
Lemma 9
Suppose that at some iteration the list SP contains consecutive elements I(d), I(c), I(b), I(a). Then \(b  a \le d  b\).
Proof
Let j be the number of the considered iteration. Note that \(a< b< c < d\). Consider the interval in (10) containing a. If \(a \in (j  2^{q_\varepsilon + 2}, j]\), then \(b  a = 1\) and \(d  b = 2\), so the required inequality holds. Otherwise, let \(a \in (j  2^{q_\varepsilon + 2 + x}, j  2^{q_\varepsilon + 2 + x  1}]\). Then by (9) \(\beta (a)\ge x\); moreover, any frame I(k) such that \(a<k\le j\) and \(\beta (k)\ge x\) is in SP. Hence, \(b  a \le 2^x\). By Lemma 7 each interval, except for the leftmost one, contains at least \(2^{q_\varepsilon +1}\ge 4\) elements. Thus each of the numbers b, c, d belongs either to the same interval as a or to the previous interval \((j 2^{q_\varepsilon + 2 + x  1}, j  2^{q_\varepsilon + 2 + x  2}]\). Again by (9) we have \(\beta (b),\beta (c),\beta (d)\ge x1\). So \(c{}b,d {} c \ge 2^{x  1}\), implying the result.\(\square \)
We want to avoid checking all frames from the list SP at line 7 of Algorithm MBasic. As in Sect. 3.1, we can save comparisons for the frames I(a) where a is too big (even if \(S[a\ldots n]\) is a palindrome, its length is at most len) or too small (\(S[a\ldots n]\) is not a palindrome, since otherwise its “central” subpalindrome of length greater than len have been considered at one of the previous iterations). We call an element I(a) of SPvaluable at ith iteration if a is neither too big nor too small in the sense above. Thus it is enough to check the condition in line 7 only for the frames valuable at the current iteration.
Lemma 10
At each iteration, SP contains at most three valuable frames. Moreover, if \(I(d'),I(d)\) are consecutive elements of SP such that \(id'<answer.len\le id\), where i is the number of the current iteration, then the valuable frames are consecutive in SP, starting with I(d).
Proof
Let d be as in the condition of the lemma. If I(d) is followed in SP by at most two frames, we are done. If it is not the case, let the next three frames be I(c), I(b), and I(a), respectively. If \(S[a\ldots i]\) is a palindrome then \(S[a {+} (b {} a) \ldots i {} (b {} a)]\) is also a palindrome. At the iteration \(i {} (b {} a)\) the frame I(b) was in SP, so this palindrome was considered by the algorithm. Hence, at the ith iteration the value answer.len is at least the length of this palindrome, which is \(i  a + 1  2 (b  a)\). By Lemma 9, \(ba\le db\), implying \(answer.len\ge i  a + 1  (b  a)  (d  b) = i  d + 1\). This inequality contradicts the definition of d; hence, \(S[a\ldots i]\) is not a palindrome. By the same argument, the frames following I(a) in SP do not produce palindromes as well. Thus, only the frames I(d), I(c), I(b) are valuable.\(\square \)
Lemma 10 tells us that it is sufficient to execute lines 7–8 of Algorithm MBasic for at most three consecutive elements of SP (the picture is as in Fig. 1, but with up to three “candidates”). Now we turn to deletions. The function \(\textit{ttl}(x)\) has the following nice property.
Lemma 11
The function \(x \rightarrow x + \textit{ttl}(x)\) is injective.
Proof
Note that \(\beta (x + \textit{ttl}(x) ) = \beta (x)\) from the definition of \(\textit{ttl}\). Hence the equality \(x + \textit{ttl}(x)=y + \textit{ttl}(y)\) implies \(\beta (x)=\beta (y)\), then \(\textit{ttl}(x)=\textit{ttl}(y)\) by (9), and finally \(x=y\). \(\square \)
Lemma 12
Both \(\beta (x)\) and \(BS(x + 1)\) can be obtained from BS(x) in \(\mathcal {O}(1)\) time.
Proof
The first number in BS(x) is \(\beta (x)\). Let us construct \(BS(x+1)\). Let [a, b] be the first segment in BS(x). If \(a > 2\), then \(BS(x + 1)=[0,0]\cup BS(x)\). If \(a = 1\), then \(BS(x + 1)=[0, b]\cup (BS(x)\backslash [1,b])\). Now let \(a = 0\). If \(BS(x)=\{[0,b]\}\) then \(BS(x+1)=\{[b{+}1,b{+}1]\}\). Otherwise let the second segment in BS(x) be [c, d]. If \(c > b + 2\), then \(BS(x + 1)=[b {+} 1, b {+} 1]\cup (BS(x)\backslash [0,b])\). Finally, if \(c = b + 2\), then \(BS(x + 1)=[b{+}1, d]\cup (BS(x)\backslash \{[0,b],[c,d]\})\). \(\square \)
Thus, if we support one list BS which is equal to BS(i) at the end of the ith iteration, we have \(\beta (i)\). If I(a) should be deleted from SP at this iteration, then \(i=a+\textit{ttl}(a)\) and hence \(\beta (a)=\beta (i)\) (see Lemma 11). The following lemma is trivial.
Lemma 13
If \(a < b\) and \(\textit{ttl}(a) = \textit{ttl}(b)\), then I(a) is deleted from SP before I(b).
Proof of Theorem 6
After every iteration, Algorithm M has the same list SP (see Fig. 2) as Algorithm MBasic, because these algorithms add and delete the same elements. Due to Lemma 10, Algorithm M returns the same answer as Algorithm MBasic. Hence by Proposition 4 Algorithm M finds a palindrome of required length. Further, Algorithm M supports the list BS of size \(\mathcal {O}(\log n)\) and the array QU containing \(\mathcal {O}(\log n)\) queues of total size equal to the size of SP. Hence, it uses \(\mathcal {O}(\frac{\log (n\varepsilon )}{\varepsilon })\) space in total by Lemma 8. The cycle in lines 13–14 performs at most three iterations. Indeed, let z be the value of sp after the previous iteration. Then this cycle starts with \(sp=previous(z)\) (or with \(sp=z\) if z is the first element of SP) and ends with \(sp=next(next(z))\) at the latest. By Lemma 12, both BS(i) and \(\beta (i)\) can be computed in \(\mathcal {O}(1)\) time. Therefore, each iteration takes \(\mathcal {O}(1)\) time. \(\square \)
Remark
Since for \(n^{0.99} \le \varepsilon \le 1\) the classes \(\mathcal {O}\big (\frac{\log n}{\log (1+\varepsilon )}\big )\) and \(\mathcal {O}\big (\frac{\log (n\varepsilon )}{\varepsilon }\big )\) coincide, Algorithm M uses space within a \(\log n\) factor from the lower bound of Theorem 4. Furthermore, for an arbitrarily slowly growing function \(\varphi \) Algorithm M uses o(n) space whenever \(\varepsilon =\frac{\varphi (n)}{n}\).
3.3 Multiplicative Error for \({\varepsilon > 1}\)
Theorem 7
There is a realtime Monte Carlo algorithm solving each instance \({\textsf {LPS}}(S)\) with multiplicative error \(\varepsilon =\varepsilon (n)\in (1,n]\) using \(\mathcal {O}\big (\frac{\log (n)}{\log (1+\varepsilon )}\big )\) space, where \(n=S\).
Our aim is to transform Algorithm M into realtime Algorithm M’ which solves \({\textsf {LPS}}(S)\) with the multiplicative error \(\varepsilon >1\) using \(\mathcal {O}\big (\frac{\log n}{\log (1+\varepsilon )}\big )\) space. The basic idea of transformation is to replace all binary representations with those in base proportional to \(1+\varepsilon \), and thus shrink the size of the lists SP and BS. To implement this idea, we define below the analogs of the functions \(\beta (i)\) and ttl(i), the lists SP and BS, and the queue QU. To distinguish analogs from their originals, we add \('\) to all notation.
Lemma 14
Each interval in (12) contains at most 5 numbers of frames stored in \(SP'\). Each of the intervals \(0,\ldots ,m\) contains at least 3 such numbers.
Proof
All 4 frames with the numbers from the 0th interval are in \(SP'\) by (11). For any \(j=1,\ldots ,m{+}1\), a frame with the number in the jth interval is in \(SP'\) if and only if its position is divisible by \(k^j\); see (11). The length of this interval is less than \(\frac{9}{2} k^j\), giving us upper bound of \(\big \lceil \frac{9}{2} \big \rceil = 5\) elements. Similarly, if \(j\ne m{+}1\), the jth interval has the length \(\frac{9}{2} k^j  \frac{9}{2} k^{j1}\) and thus contains at least \(\big \lfloor \frac{9}{2} \frac{k1}{k} \big \rfloor \) numbers of frames in \(SP'\). Since \(k \ge 4\), the claim follows. \(\square \)
Next we take Algorithm MBasic (see p. 14) and replace ttl and SP by their primed analogs. We refer to the resulting algorithm as Algorithm M’Basic.
Proposition 5
Algorithm M’Basic finds a palindrome of length \(\ell (S) \ge \frac{L(S)}{1+\varepsilon }\) using \(\mathcal {O}\big (\frac{\log n}{\log (1+\varepsilon )}\big )\) space.
Proof
Let \(S[i\ldots j]\) be a palindrome of length L(S). Let \(d = \big \lfloor \log _k \frac{L(S)}{4} \big \rfloor \). Without loss of generality we assume \(d \ge 0\), as otherwise \(L(S) < 4\le \textit{ttl}'(i)\) and the palindrome \(S[i\ldots j]\) will be detected exactly. Since \(L(S) \ge 4 k^d\), let \(a_1<a_2<a_3<a_4<a_5\) be consecutive positions which are multiples of \(k^d\) (i.e., \(\beta '(a_1),\ldots ,\beta '(a_5) \ge d\)) such that \(a_2 \le \frac{i+j}{2} < a_3\). Then in particular \(i < a_1\), and there is a palindrome \(S[ a_1 \ldots (i+ja_1) ]\) such that \(a_3 \le (i+ja_1) < a_5\). Since \(a_1 + \textit{ttl}'(a_1) \ge a_5\), this particular palindrome will be detected by Algorithm M’Basic; thus \(\ell (S) \ge a_3a_1=2 k^d\). However, we have \(L(S) < 4k^{d+1}\), hence \(\frac{L(S)}{\ell (S)} < 2k \le (1+\varepsilon )\).
Space complexity follows from bound on size of the list \(SP'\), which is at most \(5 \big \lceil \log _k\frac{2n}{9} \big \rceil +1 = \mathcal {O}\big ( \frac{\log n}{\log (1+\varepsilon )}\big )\). \(\square \)
We follow the framework of Sect. 3.2, providing an analogous speedup for Algorithm M’Basic. Consider the checks for palindromes. We adopt the same notion of a valuable frame as in Sect. 3.2: recall that a frame I(a) is valuable at ith iteration if a is neither too big (making the substring \(S[a\ldots i]\) too short to update the maximum) nor too small (such that \(S[a\ldots i]\) cannot be a palindrome). First we need the following property, which is a more general analog of Lemma 9; an analog of Lemma 10 is then proved with its help.
Lemma 15
Suppose that at some iteration the list \(SP'\) contains consecutive elements I(d), I(c), and \(d\le ianswer.len\), where i is the number of the current iteration. Further, let I(a) be another element of \(SP'\) at this iteration and \(a<c\). If c, d belong to the same interval of (12), then I(a) is not valuable.
Proof
Lemma 16
At each iteration, \(SP'\) contains at most three valuable elements. Moreover, if \(I(d'),I(d)\) are consecutive elements of \(SP'\) such that \(id'<answer.len\le id\), where i is the number of the current iteration, then the valuable elements are consecutive in \(SP'\), starting with I(d).
Proof
Let \(a<b<c<d\) be such that the elements I(d), I(c), I(b) are consecutive in \(SP'\) and I(a) belongs to \(SP'\). Then either b, c or c, d are in the same interval of (12), and thus a is not valuable by Lemma 15. \(\square \)
Next we prove an analog of Lemma 11 to show that deletions from the list \(SP'\) can be performed in constant time.
Lemma 17
The function \(h(x)= x + \textit{ttl}'(x)\) maps at most two different values of x to the same value. Moreover, if \(h(x)=h(y)\) and \(\beta '(x)\ge \beta '(y)\), then \(\beta '(x)=\beta '(h(x))+1\) and \(\beta '(y)=0\).
Proof
Let \(h(x)=h(y)\). If \(\beta '(x)=\beta '(y)\) then \(ttl'(x)=ttl'(y)\) by (11), implying \(x=y\). Hence all preimages of h(x) have different values of \(\beta '\). Assume \(\beta '(x)>\beta '(y)\). Then we have, for some integer j, \(x=j\cdot k^{\beta '(x)}\) and \(h(x)=(j+4)k^{\beta '(x)} + \frac{k}{2}\cdot k^{\beta '(x)1}\) by (11). Since k is even, we get \(\beta '(h(x))=\beta '(x)1\). If \(\beta '(y)>0\), we repeat the same argument and obtain \(\beta '(x)=\beta '(y)\), contradicting our assumption. Thus \(\beta '(y)=0\). The claim now follows. \(\square \)
3.4 The Case of Short Palindromes
A typical string contains only short palindromes, as Lemma 18 below shows (for more on palindromes in random strings, see [17]). Knowing this, it is quite useful to have a deterministic realtime algorithm which finds a longest palindrome exactly if it is “short”, otherwise reporting that it is “long”. The aim of this section is to describe such an algorithm (Theorem 8).
Lemma 18
If an input stream \(S\in \varSigma ^*\) is picked up uniformly at random among all strings of length n, where \(n\ge \varSigma \), then for any positive constant c the probability that S contains a palindrome of length greater than \(\frac{2(c+1)\log n}{\log \varSigma }\) is \(\mathcal {O}(n^{c})\).
Proof
Theorem 8

solves \({\textsf {LPS}}(S)\) exactly if \(L(S)<m\);

finds a palindrome of length m or \(m{+}1\) as an approximated solution to \({\textsf {LPS}}(S)\) if \(L(S)\ge m\).
To prove Theorem 8, we present an algorithm based on the Manacher algorithm [15]. We add two features: work with a sliding window instead of the whole string to satisfy the space requirements and lazy computation to achieve real time. (The fact that the original Manacher algorithm admits a realtime version was shown by Galil [7]; we adjusted Galil’s approach to solve \({\textsf {LPS}}\).) The details follow.
Remark
During n iterations of Algorithm EBasic, the main cycle is executed at most 3n times. Indeed, each iteration executes the main cycle with the current value of c and increases c by 0.5 before each additional execution, if any. Since c never decreases, we get the mentioned bound. Each execution takes constant time, so Algorithm EBasic works in \(\mathcal {O}(n)\) time but not in real time; for example, processing the last letter of the string \(a^nb\) requires n executions of the main cycle.
By conditions of the theorem, we are not interested in palindromes of length \(>m{+}1\). Thus, processing a suffixpalindrome of length m or \(m{+}1\) we assume that the symbol comparison in line 7 fails. So Algorithm EBasic needs no access to S[i] or Rad[i] whenever \(i<nm\). Hence we store only recent values of S and Rad and use circular arrays CS and CRad of size \(\mathcal {O}(m)\) for this purpose. For example, the symbol \(S[n{}i]\) is stored in \(CS[(n{}i)\bmod (m{+}1)]\) during \(m{+}1\) successive iterations and then is replaced by \(S[n{}i{+}m{+}1]\); the same scheme applies to the array Rad. In this way, all elements of S and Rad, needed by Algorithm EBasic, are accessible in constant time. Further, we define a queue Q of size q for lazy computations; it contains symbols that are read from the input and await processing.
Proof of Theorem 8
 (\(*\))

if the current value of q is positive, then the current value of X is less than the value of X at the moment when q was zero for the last time.
It remains to prove that Algorithm E returns the same pair (len, pos) as Algorithm EBasic with a sliding window, in spite of the fact that Algorithm E stops earlier. Suppose that Algorithm E stops with \(q>0\) after n iterations. Then the longest palindrome that could be found by processing the symbols in Q has the radius \(X=n+qc\). Now consider the iteration mentioned in (\(*\)) and let \(n'\) and \(c'\) be the values of n and c after it; so \(X'=n'c'\). Since q was zero after that iteration, the processing phase on this iteration included reading the symbol \(S[n']\) from Q and subsequent execution of the main cycle; during this execution Algorithm EBasic tried to extend a suffixpalindrome of \(S[1\ldots n'{}1]\) with the center \(c''\le c'\). If this extension was successful, then a palindrome of radius at least \(X'\) was found. If it was unsuccessful, then \(c'\ge c''+1/2\) and hence \(S[1\ldots n'{}1]\) has a suffixpalindrome of length at least \(X'1/2\). Thus, a palindrome of length \(X\le X'1/2\) is not longer than a longest palindrome seen before, and processing the queue cannot change the pair (len, pos). Thus, Algorithm E is correct. The theorem is proved. \(\square \)
Remark
Lemma 18 and Theorem 8 show a practical way to solve \({\textsf {LPS}}\). Algorithm E is fast and lightweight (2m machine words for the array Rad, m symbols in the sliding window and at most m symbols in the queue; compare to 17 machine words per one frame in the Monte Carlo algorithms). So it makes direct sense to run Algorithm M and Algorithm E, both in \(\mathcal {O}(\log n)\) space, in parallel. Then either Algorithm E will give an exact answer (which happens with high probability if the input stream is a “typical” string) or both algorithms will produce approximations: one of fixed length and one with an approximation guarantee (modulo the hash collision).
Footnotes
 1.
If the maximum length of a palindrome in S is L, then the additive error E (resp., multiplicative error \((1+\varepsilon )\)) means that the algorithm must return a number \(\ell \ge LE\) (resp., \(\ell \ge L/(1+\varepsilon )\)) and the position of a palindrome of length \(\ell \).
Notes
References
 1.Apostolico, A., Breslauer, D., Galil, Z.: Parallel detection of all palindromes in a string. Theor. Comput. Sci. 141, 163–173 (1995)CrossRefzbMATHGoogle Scholar
 2.Berenbrink, P., Ergün, F., MallmannTrenn, F., Azer, E.S.: Palindrome recognition in the streaming model. In: STACS 2014, LIPIcs, vol. 25, pp. 149–161. SchlossDagstuhlLeibnizZentrum fuer Informatik, Dagstuhl Publishing, Germany (2014)Google Scholar
 3.Breslauer, D., Galil, Z.: Realtime streaming stringmatching. In: Combinatorial Pattern Matching. LNCS, vol. 6661, pp. 162–172. Springer, Berlin (2011)Google Scholar
 4.Clifford, R., Fontaine, A., Porat, E., Sach, B., Starikovskaya, T.A.: Dictionary matching in a stream. In: ESA 2015, LNCS, vol. 9294, pp. 361–372. Springer (2015)Google Scholar
 5.Clifford, R., Fontaine, A., Porat, E., Sach, B., Starikovskaya, T.A.: The kmismatch problem revisited. In: SODA 2016, pp. 2039–2052. SIAM (2016)Google Scholar
 6.Ergün, F., Jowhari, H., Saglam, M.: Periodicity in streams. In: RANDOM 2010, LNCS, vol. 6302, pp. 545–559. Springer (2010)Google Scholar
 7.Galil, Z.: Realtime algorithms for stringmatching and palindrome recognition. In: Proceedings of 8th annual ACM symposium on theory of computing (STOC’76), pp. 161–173. ACM, New York (1976)Google Scholar
 8.Galil, Z., Seiferas, J.: A lineartime online recognition algorithm for “Palstar”. J. ACM 25, 102–111 (1978)MathSciNetCrossRefzbMATHGoogle Scholar
 9.Gawrychowski, P., Manea, F., Nowotka, D.: Testing generalised freeness of words. In: STACS 2014, LIPIcs, vol. 25, pp. 337–349. Dagstuhl Publishing (2014)Google Scholar
 10.Gawrychowski, P., Merkurev, O., Shur, A.M., Uznanski, P.: Tight tradeoffs for realtime approximation of longest palindromes in streams. In: Proceedings CPM 2016, LIPIcs, vol. 54, pp. 18:1–18:13. Schloss Dagstuhl  LeibnizZentrum fuer Informatik (2016)Google Scholar
 11.Jalsenius, M., Porat, B., Sach, B.: Parameterized matching in the streaming model. In: STACS 2013, LIPIcs, vol. 20, pp. 400–411. Dagstuhl Publishing (2013)Google Scholar
 12.Karp, R., Rabin, M.: Efficient randomized pattern matching algorithms. IBM J. Res. Dev. 31, 249–260 (1987)MathSciNetCrossRefzbMATHGoogle Scholar
 13.Knuth, D.E., Morris, J., Pratt, V.: Fast pattern matching in strings. SIAM J. Comput. 6, 323–350 (1977)MathSciNetCrossRefzbMATHGoogle Scholar
 14.Kosolobov, D., Rubinchik, M., Shur, A.M.: Finding distinct subpalindromes online. In: Proceedings of Prague Stringology conference. PSC 2013, pp. 63–69. Czech Technical University in Prague (2013)Google Scholar
 15.Manacher, G.: A new lineartime online algorithm finding the smallest initial palindrome of a string. J. ACM 22(3), 346–351 (1975)CrossRefzbMATHGoogle Scholar
 16.Porat, B., Porat, E.: Exact and approximate pattern matching in the streaming model. In: FOCS 2009, pp. 315–323. IEEE Computer Society (2009)Google Scholar
 17.Rubinchik, M., Shur, A.M.: The number of distinct subpalindromes in random words. Fundam. Inform. 145, 371–384 (2016)MathSciNetCrossRefzbMATHGoogle Scholar
 18.Yao, A.C.C.: Probabilistic computations: toward a unified measure of complexity (extended abstract). In: FOCS 1977, pp. 222–227. IEEE Computer Society (1977)Google Scholar
Copyright information
Open AccessThis article is distributed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.