Abstract
This paper introduces novel, high-efficiency algorithms for maintaining "all-scores matrices"—data structures that store alignment scores between various segments of two strings—specifically under the Longest Common Subsequence (LCS) metric. By leveraging the mathematical sparsity and Monge properties of these matrices, the authors achieve update complexities that scale with the LCS length ($L$) or the difference between string length and LCS ($\Delta$). These results represent a significant theoretical advancement over traditional methods that scale linearly with total string length, particularly in applications involving highly similar or highly divergent sequences.
Introduction
Sequence alignment is a fundamental operation in bioinformatics, natural language processing, and computer vision. While the global Longest Common Subsequence (LCS) score between two strings $A$ and $B$ is a well-understood problem, many modern applications require a more granular view. Specifically, they require "all-scores matrices," which provide alignment scores for every possible substring or suffix-prefix combination between the two strings.
In dynamic environments—such as real-time text editing or incremental genomic sequencing—these matrices must be updated as characters are added or removed. Traditional state-of-the-art algorithms typically require $O(n)$ or $O(m)$ time per update, where $n$ and $m$ are the lengths of the strings. This paper presents a breakthrough by utilizing "sparsity parameters" ($L$ and $\Delta$) that are often significantly smaller than the total string length in practical datasets.
Problem Formulation
The authors focus on two primary types of all-scores matrices:
- Matrix $\mathcal{K}$: Encodes the LCS score of every substring of string $B$ with the entirety of string $A$.
- Matrix $\mathcal{J}$: Encodes the LCS score of every suffix of $B$ with every prefix of $A$.
As shown in Figure 2, these problems can be modeled as finding optimal paths in a grid graph. The shaded nodes represent the boundaries of the substrings or prefixes being compared. The challenge lies in updating these paths efficiently when the underlying strings $A$ or $B$ are modified.
Algorithmic Innovation: Exploiting Sparsity
The core contribution of this work is the realization that these massive $n \times m$ matrices are "sub-unit Monge" (or anti-Monge). This mathematical property implies that the entire matrix can be uniquely represented by a sparse set of "pivotal points." These points correspond to the non-zero entries in the matrix's density map (the second-order difference of the matrix).
Key Technical Components:
- Sparsity-Aware Encoding: Instead of a full matrix, the algorithms store only pivotal points. For matrix $\mathcal{J}$, there are exactly $L$ pivotal points. For matrix $\mathcal{K}$, there are exactly $\Delta$ pivotal points (where $\Delta = |B| - L$).
- Step Indices: The algorithms track "step indices"—the specific locations where the LCS score increments. When a character is prepended or appended, the algorithm identifies how these indices shift and updates the pivotal points surgically.
- Efficient Sorting: To support two-sided updates (adding to either end of a string), the authors utilize specialized data structures, including Han’s $O(L \log \log L)$ deterministic sorting, to maintain the ordering of pivotal points.
Figure 6 illustrates this sparsity. While the score matrices (a and b) are dense, their corresponding density maps (c and d) contain very few non-zero entries (shaded cells). By operating only on these shaded cells, the algorithm bypasses the need to touch every entry in the score matrix.
Results and Complexity Analysis
The paper provides rigorous big-O complexity analysis, demonstrating significant improvements over previous theoretical bounds. The results are summarized in the table below:
| Matrix | Operation Type | Time Complexity | Space Complexity |
|---|---|---|---|
| $\mathcal{K}$ | 2-sided (prepend/append to $A$) | $O(\Delta)$ | $O(n)$ |
| $\mathcal{J}$ | 1-sided (prepend to $A$ OR append to $B$) | $O(L)$ | $O(n)$ or $O(m)$ |
| $\mathcal{J}$ | 2-sided (prepend to $A$ AND append to $B$) | $O(L \log \log L)$ | $O(m + n)$ |
These results are particularly impactful when sequences are highly similar (small $\Delta$) or relatively short common subsequences exist (small $L$). Notably, the $O(L)$ bound for matrix $\mathcal{J}$ is a worst-case guarantee, improving upon previous amortized results.
Discussion and Future Work
While the paper offers substantial speedups, it also identifies several constraints. The $O(\Delta)$ algorithm for matrix $\mathcal{K}$ currently only supports updates to string $A$; updating string $B$ remains a more complex challenge as it can dynamically increase the number of pivotal points. Additionally, the current analysis assumes a constant alphabet size; future research may explore the impact of large alphabets on these bounds.
Finally, while this work focuses on the LCS metric, the underlying Monge-based techniques may eventually be adaptable to more general weighted Edit Distance problems, provided similar sparsity properties can be identified.
Summary updated