Skip to main content
QUICK REVIEW

[Paper Review] Fast and simple algorithms for computing both $LCS_{k}$ and $LCS_{k+}$

Filip Pavetić, Ivan Katanić|arXiv (Cornell University)|May 20, 2017
Algorithms and Data CompressionComputer Science4 references4 citations
TL;DR

This paper presents a single, efficient algorithm that computes both $LCS_k$ and $LCS_{k+}$ with improved runtime complexity, achieving $Ó(\min(r\log l, r + ml))$ time and avoiding complex data structures. It introduces a memory-optimized reconstruction heuristic that reduces memory usage by up to 1000x on human genome data, with open-source C++ code provided for broader adoption.

ABSTRACT

Longest Common Subsequence ($LCS$) deals with the problem of measuring similarity of two strings. While this problem has been analyzed for decades, the recent interest stems from a practical observation that considering single characters is often too simplistic. Therefore, recent works introduce the variants of $LCS$ based on shared substrings of length exactly or at least $k$ ($LCS_k$ and $LCS_{k+}$ respectively). The main drawback of the state-of-the-art algorithms for computing $LCS_k$ and $LCS_{k+}$ is that they work well only in a limited setting: they either solve the average case well while being suboptimal in the pathological situations or they achieve a good worst-case performance, but fail to exploit the input data properties to speed up the computation. Furthermore, these algorithms are based on non-trivial data structures which is not ideal from a practitioner's point of view. We present a single algorithm to compute both $LCS_k$ and $LCS_{k+}$ which outperforms the state-of-the art algorithms in terms of runtime complexity and requires only basic data structures. In addition, we implement an algorithm to reconstruct the solution which offers significant improvement in terms of memory consumption. Our empirical validation shows that we save several orders of magnitude of memory on human genome data. The C++ implementation of our algorithms is made available at: https://github.com/google/fast-simple-lcsk

Motivation & Objective

  • To address the inefficiency of existing $LCS_k$ and $LCS_{k+}$ algorithms that either underperform in pathological cases or rely on complex data structures.
  • To unify the computation of both $LCS_k$ and $LCS_{k+}$ under a single, simple algorithm.
  • To significantly reduce memory consumption during solution reconstruction, especially for large-scale genomic data.
  • To provide a practical, accessible implementation to accelerate research and application in bioinformatics and string similarity.

Proposed method

  • The algorithm uses a dynamic programming approach based on matching substrings of length $k$, leveraging a sweep-line technique over sorted match pairs.
  • It maintains a set of active match pairs and uses a priority queue to efficiently extend the longest common subsequence during processing.
  • The same core logic is adapted for $LCS_{k+}$ by considering all substrings of length $\geq k$ instead of exactly $k$, enabling unified computation.
  • A reference-counting mechanism with shared pointers is used to dynamically manage reconstruction paths, deallocating unused match pairs as soon as they are no longer needed.
  • The algorithm avoids persistent or augmented data structures like red-black trees or Fenwick trees, relying only on basic data structures for simplicity and efficiency.
  • The implementation uses standard C++ with std::shared_ptr for automatic memory management of reconstruction chains, enabling significant space savings.

Experimental results

Research questions

  • RQ1Can a single, simple algorithm efficiently compute both $LCS_k$ and $LCS_{k+}$ with better asymptotic performance than existing methods?
  • RQ2Is it possible to achieve optimal or near-optimal runtime complexity without relying on complex data structures such as persistent red-black trees or Fenwick trees?
  • RQ3How can memory usage for reconstructing the actual subsequence be reduced in practice, especially for large inputs like human genome sequences?
  • RQ4Can the memory optimization technique based on reference counting and dynamic deallocation be generalized to other dynamic programming problems with similar reconstruction overhead?

Key findings

  • The proposed algorithm achieves a runtime complexity of $\mathcal{O}(\min(r\log l, r + ml))$, outperforming prior approaches in both average and worst-case scenarios.
  • The same algorithm computes both $LCS_k$ and $LCS_{k+}$, unifying two previously distinct problems under a single framework.
  • The memory-optimized reconstruction method reduces peak memory usage by up to 1000x on human genome data, with observed compression factors of 700–1000x across multiple chromosomes and $k$ values.
  • The implementation, available at https://github.com/google/fast-simple-lcsk, is the first widely accessible open-source codebase for $LCS_k$ and $LCS_{k+}$, enabling reproducibility and further research.
  • Experiments show that memory savings increase with the number of match pairs, indicating strong scalability on large biological datasets.
  • The algorithm avoids complex data structures, making it easier to implement and maintain compared to prior solutions relying on persistent or augmented trees.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.