Skip to main content
QUICK REVIEW

[Paper Review] Revisiting the tree edit distance and its backtracing: A tutorial

Benjamin Paaßen|arXiv (Cornell University)|May 17, 2018
Algorithms and Data CompressionComputer Science7 citations
TL;DR

This tutorial provides a comprehensive, accessible guide to the Zhang and Shasha tree edit distance (TED) algorithm, including efficient backtracing to reconstruct optimal edit scripts. It introduces generalized cost functions, proves metric properties, and presents novel algorithms to compute not only the TED but also the frequency of node mappings across all optimal edit sequences, enabling applications in metric learning and adaptive embeddings.

ABSTRACT

Almost 30 years ago, Zhang and Shasha (1989) published a seminal paper describing an efficient dynamic programming algorithm computing the tree edit distance, that is, the minimum number of node deletions, insertions, and replacements that are necessary to transform one tree into another. Since then, the tree edit distance has been widely applied, for example in biology and intelligent tutoring systems. However, the original paper of Zhang and Shasha can be challenging to read for newcomers and it does not describe how to efficiently infer the optimal edit script. In this contribution, we provide a comprehensive tutorial to the tree edit distance algorithm of Zhang and Shasha. We further prove metric properties of the tree edit distance, and describe efficient algorithms to infer the cheapest edit script, as well as a summary of all cheapest edit scripts between two trees.

Motivation & Objective

  • To provide a clear, accessible tutorial for the Zhang and Shasha tree edit distance (TED) algorithm, which is often treated as a black box in practice.
  • To address the lack of detailed guidance on reconstructing optimal edit scripts (backtracing), a critical but under-documented aspect of TED.
  • To generalize the TED framework with customizable edit costs to support application-specific adjustments.
  • To develop efficient algorithms for computing the number of co-optimal mappings and the frequency of node pairings across all optimal edit sequences.
  • To enable parameter learning for TED by expressing the distance as a linear function of mapping frequencies, facilitating metric learning approaches.

Proposed method

  • Introduces a generalized cost function over tree edits (insertions, deletions, replacements), allowing customization for domain-specific applications.
  • Defines tree mappings between subtrees as the core interface for dynamic programming, enabling recursive decomposition of the TED.
  • Presents a recursive backtracing algorithm (replacing a flawed iterative version) to reconstruct the optimal edit script from the dynamic programming table.
  • Proposes forward and backward path-counting algorithms (Algorithms 9 and 10) to compute the number of co-optimal paths in the edit graph.
  • Introduces a forward-backward algorithm (Algorithm 11) to compute the frequency matrix Γ, which counts how often each node pair appears in co-optimal mappings.
  • Derives a linear representation of the TED as a weighted sum over node pair frequencies (Pc(¯x, ¯y)), enabling parameter learning via linear models.

Experimental results

Research questions

  • RQ1How can the tree edit distance algorithm be made more accessible and implementable for researchers and practitioners unfamiliar with the original Zhang and Shasha paper?
  • RQ2What is an efficient and correct method to reconstruct the optimal edit script (i.e., the sequence of edits) from the dynamic programming table?
  • RQ3How can the frequency of node mappings across all co-optimal edit sequences be computed efficiently?
  • RQ4Can the tree edit distance be reformulated as a linear function of mapping frequencies to support parameter learning?
  • RQ5What metric properties does the tree edit distance satisfy, and how can they be formally proven?

Key findings

  • A corrected recursive backtracing algorithm is proposed to reliably reconstruct the optimal edit script, fixing a flaw in the prior iterative approach.
  • The forward and backward path-counting algorithms (Algorithms 9 and 10) efficiently compute the number of co-optimal paths in the edit graph.
  • The forward-backward algorithm (Algorithm 11) computes the frequency matrix Γ, which counts how many times each node pair appears in co-optimal mappings.
  • The tree edit distance can be expressed as a linear combination of node pair costs weighted by their co-occurrence frequencies in optimal mappings, enabling parameter learning.
  • The matrix Pc(¯x, ¯y) = 1/k · Γ represents the probability of node pairings in optimal mappings, and the TED equals the expected cost over these pairings.
  • The reference implementation at https://pypi.org/project/edist/ is consistent with the corrected recursive backtracing and supports all proposed algorithms.

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.