[Paper Review] Fast and Simple Computation of All Longest Common Subsequences
This paper presents a simple O(mn) algorithm to construct an all-prefixes-LCSs-graph that enables efficient enumeration of all longest common subsequence (LCS) embeddings for any pair of input sequences. By leveraging dynamic programming and contour-based linked lists, the method generates all distinct LCSs or all embeddings in time proportional to output size after linear-time preprocessing.
This paper shows that a simple algorithm produces the {\em all-prefixes-LCSs-graph} in $O(mn)$ time for two input sequences of size $m$ and $n$. Given any prefix $p$ of the first input sequence and any prefix $q$ of the second input sequence, all longest common subsequences (LCSs) of $p$ and $q$ can be generated in time proportional to the output size, once the all-prefixes-LCSs-graph has been constructed. The problem can be solved in the context of generating all the distinct character strings that represent an LCS or in the context of generating all ways of embedding an LCS in the two input strings.
Motivation & Objective
- Address the challenge of efficiently enumerating all distinct longest common subsequence (LCS) strings and their embeddings for two input sequences.
- Overcome the inefficiency of naive backtracking methods that generate duplicates and require post-processing to remove them.
- Develop a data structure—the all-prefixes-LCSs-graph—that supports fast, output-sensitive enumeration of LCSs and embeddings for any prefix pair.
- Provide a unified framework that handles both distinct LCS strings and multiple embeddings per LCS, with minimal overhead.
- Achieve optimal time complexity O(mn) for preprocessing and output-proportional time for enumeration, improving upon existing methods.
Proposed method
- Construct a dynamic programming table L[i,j] using the standard recurrence: L[i,j] = L[i-1,j-1]+1 if a_i = b_j, otherwise max(L[i-1,j], L[i,j-1]).
- Build an all-prefixes-LCSs-graph where each cell [i,j] maintains a linked list (head, tail, pretail) of matches with the same rank (L[i,j]) and earlier or equal indices.
- Use contour-based traversal: matches are grouped by rank and connected via zig-zag contours to preserve order and avoid duplication.
- Apply two-phase merging: for each [i,j], merge adjacency lists from [i-1,j] and [i,j-1] only if they have the same rank as L[i,j], ensuring no duplicate embeddings.
- Enforce antidominance and dominance conditions to eliminate redundant paths and ensure each LCS embedding is generated exactly once.
- Use self-pointers and linked list pointers (head, tail, pretail) to efficiently maintain and update adjacency lists during dynamic programming traversal.
Experimental results
Research questions
- RQ1Can a simple, efficient algorithm compute all distinct LCS strings and their embeddings without generating duplicates?
- RQ2Is it possible to construct a data structure that supports output-sensitive enumeration of all LCSs and embeddings for any prefix pair in O(mn) preprocessing time?
- RQ3How can the standard LCS dynamic programming table be augmented to support enumeration of all embeddings while avoiding exponential blowup?
- RQ4What structural properties of matches (e.g., dominance, contours) can be exploited to minimize redundant path generation?
- RQ5Can the enumeration of all LCS embeddings be achieved in time proportional to the output size after a linear-time preprocessing phase?
Key findings
- The all-prefixes-LCSs-graph can be constructed in O(mn) time using a simple dynamic programming approach with linked list augmentation.
- Once the graph is built, all distinct LCSs or all embeddings of LCSs for any prefix pair A_i and B_j can be enumerated in time proportional to the output size.
- The algorithm avoids duplicate enumeration by enforcing antidominance and dominance conditions during adjacency list construction.
- The method supports both the generation of distinct LCS strings and the enumeration of all embeddings of those strings, with no need for post-processing deduplication.
- A C implementation is provided that matches the output of the naive backtracking method followed by deduplication, confirming correctness.
- The use of contour-based linking and pretail pointers ensures that only relevant, non-reduundant paths are retained in the adjacency lists.
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.