Does preprocessing help in fast sequence comparisons?

Elazar Goldenberg, Aviad Rubinstein, Barna Saha

TL;DR

Computing the edit distance between long sequences is notoriously slow, bottlenecking applications like genomics and document analysis. This paper introduces a "preprocessing" model where strings are processed independently upfront, unlocking dramatically faster query times for exact and approximate sequence comparisons—and surprisingly yielding a new state-of-the-art algorithm for standard edit distance without preprocessing.

What Problem Does This Paper Address?

Edit distance (or Levenshtein distance) and Longest Common Subsequence (LCS) are fundamental metrics for measuring how similar two strings are. However, the standard dynamic programming algorithm to compute them takes quadratic time, $O(n^2)$. When dealing with massive datasets—like comparing thousands of long DNA sequences or clustering massive text corpora—quadratic time is completely unaffordable.

While researchers have developed faster sub-linear or near-linear time algorithms, they usually come with severe trade-offs: they either only work when strings are nearly identical, or they provide highly inaccurate approximations.

The authors tackle this by asking a highly practical question: What if we allow the algorithm to preprocess each string independently before comparing them? In real-world scenarios like database joins, strings are drawn from a known pool. If we can preprocess a string once upon ingestion, can we make subsequent pairwise comparisons significantly faster?

Methods

The paper introduces a two-phase model:

  1. Preprocessing Phase: Each string is processed independently to create a specialized data structure (like a sketch or hash table).
  2. Query Phase: The algorithm takes the preprocessed data of two strings and computes their alignment.

To achieve their speedups, the authors employ several clever techniques:

  • Independent Rolling Hashes: Classic fast algorithms for small edit distances rely on building a joint suffix tree of both strings. The authors replace this by computing rolling hashes for each string independently at multiple scales. During the query phase, they use binary search over these hashes to find matching substrings in $O(\log n)$ time.
  • Density-Based Windowing: For general approximate edit distance, the algorithm divides strings into variable-sized contiguous blocks called "windows." It dynamically estimates the "degree" of each window (how many similar windows exist in the other string).
  • Triangle Inequality for Dense Graphs: Windows are classified as "dense" (many similar neighbors) or "sparse" (few neighbors). The algorithm uses the triangle inequality to cheaply infer distances for dense windows, while using recursive narrowing to handle sparse windows.

Datasets

Not discussed in the paper. As a theoretical computer science paper, the focus is on mathematical proofs, algorithmic complexity, and asymptotic bounds rather than empirical benchmarks on specific datasets.

Key Insights and Ideas

  • Preprocessing is practically "free" in databases: If preprocessing takes near-linear time (e.g., $O(n \log n)$), it is barely more expensive than simply reading and storing the string in the first place. Yet, it pays massive dividends during the query phase.
  • Simulating joint data structures: A major conceptual leap is showing that you don't need to look at two strings simultaneously to build a fast index for comparing them. Independent hash tables can effectively simulate the behavior of combined suffix trees.
  • A surprising "boomerang" effect: The techniques developed specifically for the preprocessing model turned out to be so efficient that the authors were able to adapt them back into the standard model. By applying their windowing technique on the fly, they improved the state-of-the-art for approximate edit distance without any preprocessing.
  • Theoretical limits still apply: Using fine-grained complexity (specifically, the BP-SETH hypothesis), the authors prove that even with unlimited polynomial-time preprocessing, computing the exact edit distance for general strings still requires near-quadratic query time. Preprocessing helps immensely, but it isn't magic.

Key Results

The paper delivers several massive improvements over the state-of-the-art:

  • Permutation-LCS: If the LCS of two permutations has length $n-k$, it can be computed exactly with $O(n \log n)$ preprocessing and just $O(k \log n)$ query time.
  • Small Edit Distance: If the edit distance between two general strings is at most $k$, it can be computed exactly with $O(n \log n)$ preprocessing and $O(k^2 \log n)$ query time.
  • Approximate Edit Distance: For general strings, the algorithm achieves a $(7+\epsilon)$-approximation with $\tilde{O}(n^2)$ preprocessing and $\tilde{O}(n^{1.5})$ query time.
  • No Preprocessing Bonus: Adapting their methods yields the fastest known $(3+\epsilon)$-approximation algorithm for edit distance without preprocessing, running in $\tilde{O}(n^{1.6})$ time (beating the previous $\tilde{O}(n^{1.69})$ record).

Limitations and Future Work

  • Single-String Preprocessing: The authors explored a variant where only one string is preprocessed (highly relevant for comparing a single reference genome against many reads). While they achieved some sub-linear speedups for small edit distances, they note that obtaining significant improvements for approximate edit distance in this single-string model remains an open question.
  • Sub-linear Approximation for Small Distances: The authors suggest future work could combine their exact $O(k^2)$ algorithm with their $O(n^{1.5})$ approximation to achieve truly sub-$k^2$ time for small edit distances.
  • Beyond String Alignment: The authors propose looking for other classic algorithmic problems where independent preprocessing is natural and could yield similar theoretical breakthroughs.

Summary updated

BibTeX
@inproceedings{goldenberg2020does,
  author = {Elazar Goldenberg and Aviad Rubinstein and Barna Saha},
  title = {{Does preprocessing help in fast sequence comparisons?}},
  booktitle = {STOC},
  year = {2020},
  doi = {10.1145/3357713.3384300},
}

Loading related content...

Figure