Õ(n+poly(k))-time Algorithm for Bounded Tree Edit Distance

Debarati Das, Jacob Gilbert, MohammadTaghi Hajiaghayi, Tomasz Kociumaka, Barna Saha, Hamed SalehFOCS 2022

Abstract

Computing the edit distance between two trees is a fundamental problem in combinatorial optimization with applications ranging from computational biology to NoSQL database management. While string edit distance has long enjoyed algorithms with additive complexity in terms of the sequence length $n$ and the distance $k$, tree edit distance (TED) has historically been constrained by multiplicative $nk$ bottlenecks. This paper presents a randomized algorithm that achieves $\tilde{O}(n + \text{poly}(k))$ time, effectively breaking the cubic barrier and resolving a long-standing open question in the field.

Introduction

Tree Edit Distance (TED) measures the minimum cost to transform one rooted, ordered, labeled tree into another via node insertions, deletions, and relabelings. It serves as a natural generalization of the classic string edit distance. In modern contexts, TED is increasingly relevant for comparing hierarchical data structures like JSON documents in MongoDB or XML files.

For decades, the computational complexity of TED remained a challenge. While string edit distance can be solved in $O(n + k^2)$ time, the best algorithms for trees were $O(n^3)$ for general cases. Even when the distance $k$ was known to be small, state-of-the-art methods required $\tilde{O}(nk^2)$ time. The goal has been to find an algorithm where the dependency on $n$ is near-linear and decoupled from $k$. This paper achieves that milestone by providing the first $\tilde{O}(n + \text{poly}(k))$ result.

Methodology: Beyond Dynamic Programming

The core innovation of this work lies in moving away from standard dynamic programming toward a greedy matching strategy. However, greedy matching in trees is non-trivial because local matches do not necessarily lead to global optima. The authors overcome this through three primary technical pillars:

1. Look-Ahead Labeling and Fingerprinting

To facilitate greedy matching, the algorithm must quickly identify identical subtrees. The authors employ Karp-Rabin fingerprints to generate "look-ahead labels." These labels encode the structural and label information of an entire subtree into a compact hash, allowing for $O(1)$ time identity checks during the matching process.

2. Periodicity Reduction

Periodicity is a well-understood phenomenon in strings (e.g., "ababab"), but it is significantly more complex in trees. The authors identify two distinct types of tree periodicity:

  • Horizontal Periodicity: A sequence of sibling subtrees repeats.
  • Vertical Periodicity: A structural pattern repeats along a path from root to leaf. By developing a preprocessing step to identify and "compress" these periodic structures, the algorithm prevents the greedy matcher from being misled by local repetitions, ensuring that identical subtrees can be matched without sacrificing optimality.

3. Randomized Level Sampling

To handle the depth of trees, the algorithm utilizes a randomized sampling technique. By marking nodes at specific random depths and applying a "Partial Forest Matching" algorithm, the researchers can effectively hit all long paths in the tree. This reduces the problem into a set of "shallow" trees or a "residual" instance of size $\text{poly}(k)$, which can then be solved using traditional, albeit slower, methods.

Key Results

The primary contribution is a randomized algorithm that computes the bounded tree edit distance in $O(n \log n + k^{15} \log k \log n)$ time. This result is significant for several reasons:

  • Complexity Breakthrough: It is the first algorithm to achieve $\tilde{O}(n + \text{poly}(k))$ complexity, proving that the $nk$ bottleneck is not an inherent requirement for the problem.
  • Correctness: The algorithm provides a "high probability" guarantee of correctness, a standard for randomized algorithms utilizing hashing and sampling.
  • Theoretical Foundation: The framework for handling two-dimensional periodicity in trees provides a new toolkit for other hierarchical data problems.

Discussion and Limitations

While the algorithm is a theoretical triumph, it faces practical hurdles. The $k^{15}$ term, while constant relative to $n$, grows extremely fast. For practical applications where $k$ might be in the dozens, the constant factor becomes prohibitive.

Future research directions include:

  • Exponent Reduction: Optimizing the $\text{poly}(k)$ term to a more manageable power, such as $k^2$ or $k^3$.
  • Weighted Operations: Extending the algorithm to handle non-uniform costs for different edit operations, as this paper assumes unit costs.
  • Derandomization: Developing a deterministic version of the algorithm that does not rely on Karp-Rabin hashing or random level sampling.

In conclusion, this work marks a definitive step forward in our understanding of hierarchical data comparison, shifting the boundary of what is computationally feasible for tree-structured data.

Summary updated

BibTeX
@inproceedings{das2022o,
  author = {Debarati Das and Jacob Gilbert and MohammadTaghi Hajiaghayi and Tomasz Kociumaka and Barna Saha and Hamed Saleh},
  title = {{Õ(n+poly(k))-time Algorithm for Bounded Tree Edit Distance}},
  booktitle = {FOCS},
  year = {2022},
  url = {https://openreview.net/forum?id=NC8UW420oA},
}
Figure