🤖 AI Summary
This work addresses the efficient enumeration of closed substrings and their maximal variants (maximal closed substrings, MCSs) in a string. We present the first algorithm achieving $O(n log n)$ time and space complexity for enumerating all $Theta(n^2)$ closed substrings. For MCS extraction, we propose a lightweight method based on the suffix array and LCP array, ensuring both theoretical optimality and practical efficiency. To mitigate output explosion, we introduce a compact representation that significantly reduces output size. Furthermore, we fully characterize the asymptotic behavior of MCS counts in Fibonacci words, deriving the exact asymptotic formula $sim 1.382,F_n$. This constitutes the first near-linear-time algorithm for complete closed substring enumeration.
📝 Abstract
A closed string $u$ is either of length one or contains a border that occurs only as a prefix and as a suffix in $u$ and nowhere else within $u$. In this paper, we present a fast and practical $O(nlog n)$ time algorithm to compute all $Theta(n^2)$ closed substrings by introducing a compact representation for all closed substrings of a string $ w[1..n]$, using only $O(n log n)$ space. We also present a simple and space-efficient solution to compute all maximal closed substrings (MCSs) using the suffix array ($mathsf{SA}$) and the longest common prefix ($mathsf{LCP}$) array of $w[1..n]$. Finally, we show that the exact number of MCSs ($M(f_n)$) in a Fibonacci word $ f_n $, for $n geq 5$, is $approx left(1 + frac{1}{phi^2}
ight) F_n approx 1.382 F_n$, where $ phi $ is the golden ratio.