English

Edit Distance between Unrooted Trees in Cubic Time

Data Structures and Algorithms 2018-04-27 v1

Abstract

Edit distance between trees is a natural generalization of the classical edit distance between strings, in which the allowed elementary operations are contraction, uncontraction and relabeling of an edge. Demaine et al. [ACM Trans. on Algorithms, 6(1), 2009] showed how to compute the edit distance between rooted trees on nn nodes in O(n3)\mathcal{O}(n^{3}) time. However, generalizing their method to unrooted trees seems quite problematic, and the most efficient known solution remains to be the previous O(n3logn)\mathcal{O}(n^{3}\log n) time algorithm by Klein [ESA 1998]. Given the lack of progress on improving this complexity, it might appear that unrooted trees are simply more difficult than rooted trees. We show that this is, in fact, not the case, and edit distance between unrooted trees on nn nodes can be computed in O(n3)\mathcal{O}(n^{3}) time. A significantly faster solution is unlikely to exist, as Bringmann et al. [SODA 2018] proved that the complexity of computing the edit distance between rooted trees cannot be decreased to O(n3ϵ)\mathcal{O}(n^{3-\epsilon}) unless some popular conjecture fails, and the lower bound easily extends to unrooted trees. We also show that for two unrooted trees of size mm and nn, where mnm\le n, our algorithm can be modified to run in O(nm2(1+lognm))\mathcal{O}(nm^2(1+\log\frac nm)). This, again, matches the complexity achieved by Demaine et al. for rooted trees, who also showed that this is optimal if we restrict ourselves to the so-called decomposition algorithms.

Keywords

Cite

@article{arxiv.1804.10186,
  title  = {Edit Distance between Unrooted Trees in Cubic Time},
  author = {Bartłomiej Dudek and Paweł Gawrychowski},
  journal= {arXiv preprint arXiv:1804.10186},
  year   = {2018}
}
R2 v1 2026-06-23T01:37:17.366Z