[Paper Review] Algorithms to Compute the Lyndon Array
This paper presents five algorithms to compute the Lyndon array of a string, including two novel $ϵ(n\log n)$-time methods that avoid global data structures like suffix arrays. The key contribution is a conjecture that a linear-time, elementary algorithm for the Lyndon array may exist, supported by experimental evidence showing most algorithms run in near-linear time in practice.
We first describe three algorithms for computing the Lyndon array that have been suggested in the literature, but for which no structured exposition has been given. Two of these algorithms execute in quadratic time in the worst case, the third achieves linear time, but at the expense of prior computation of both the suffix array and the inverse suffix array of x. We then go on to describe two variants of a new algorithm that avoids prior computation of global data structures and executes in worst-case n log n time. Experimental evidence suggests that all but one of these five algorithms require only linear execution time in practice, with the two new algorithms faster by a small factor. We conjecture that there exists a fast and worst-case linear-time algorithm to compute the Lyndon array that is also elementary (making no use of global data structures such as the suffix array).
Motivation & Objective
- To systematically analyze and present existing and new algorithms for computing the Lyndon array, which is crucial for efficiently computing runs in strings.
- To develop and evaluate algorithms that compute the Lyndon array without relying on heavy global data structures like suffix arrays.
- To investigate whether a linear-time, elementary algorithm for the Lyndon array exists, based on empirical performance and theoretical analysis.
- To compare the practical efficiency of different approaches, especially in terms of time complexity and constant factors across various string types.
- To provide a comprehensive exposition of algorithms previously described only informally or without structured analysis.
Proposed method
- Proposes three existing algorithms: two with $O(n^2)$ worst-case time, one using suffix and inverse suffix arrays for $O(n)$ time.
- Introduces two new variants of a novel algorithm, NSV$^*$, based on range comparison using Parikh vectors to enable $O(\sigma)$-time range comparisons.
- Employs Parikh vectors $P_r[1..\sigma]$ to represent range content, enabling lexicographic comparison of substrings in $O(\sigma)$ time instead of $O(\ell)$.
- Uses a stack-based active range tracking mechanism with $\text{nextequal}[j]$ to detect periodicities and avoid redundant comparisons.
- Implements two versions: NPNSV$^*$ (no Parikh vectors) and PNSV$^*$ (with Parikh vectors), both achieving $O(n\log n)$ worst-case time.
- Employs preprocessing to compute Parikh vectors in $O(n)$ time, enabling efficient range comparisons during the main computation phase.
Experimental results
Research questions
- RQ1Can the Lyndon array be computed in $O(n)$ time using only elementary data structures, without constructing suffix arrays?
- RQ2What is the practical performance of existing and new algorithms for Lyndon array computation across different string types, including random and periodic strings?
- RQ3How does the use of Parikh vectors affect the efficiency and worst-case complexity of Lyndon array computation algorithms?
- RQ4Is there a significant performance gap between algorithms that use suffix arrays and those that do not, particularly in terms of constant factors and cache behavior?
- RQ5Do the new $O(n\log n)$-time algorithms outperform existing $O(n^2)$-time methods in practice, especially on large inputs?
Key findings
- All but one of the five algorithms tested—specifically MaxLyn and the two new NSV$^*$ variants—exhibit near-linear time performance in practice, even though worst-case bounds vary.
- The PNSV$^*$ variant, which uses Parikh vectors, is approximately 10 times slower than MaxLyn on small binary strings, but remains competitive on longer strings.
- On random binary strings, PNSV$^*$ and NPNSV$^*$ are the fastest, achieving a 2–3x speedup over MaxLyn, indicating strong performance on average-case inputs.
- On highly periodic strings, MaxLyn outperforms the NSV$^*$ variants by a similar margin, suggesting that algorithm choice depends on input structure.
- The worst-case input for NSV$^*$ requires $O(n\log n)$ range matches, confirming the theoretical $O(n\log n)$ bound, and the Parikh-vector version inherits this complexity with an $O(\sigma)$ factor.
- Despite theoretical worst-case bounds, experimental results suggest that a linear-time, elementary algorithm for the Lyndon array may exist, leading to the authors' conjecture of such an algorithm's existence.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.