I need to calculate the edit distance between many pairs of binary trees. Unfortunately this is computationally expensive.
The trees are stored as a flattened list of indices into node and terminal lookup tables. The particular flattening structure is the pre-order encoding format (pseudo code: flat(tree) = [id(root)] + flat(left) + flat(right)
).
If I calculate the Levenshtein distance between the flattened trees, rather than between trees:
- How big will my error be? (Difference to tree based distance)
- Would other flat structures be more accurate?
1 2 .. n
. There are $2^{n-1}$ fitting trees from linear chains alone (attach left or right) and many others. $\endgroup$trees = {[1,3,4], [2,3,4], [1,2,3,4,3]}, bins=[1,2], terms=[3,4]
wherebins
tells us which indices represent binary branching and 'terms' indicate leaf nodes. The first two have the same structure but with different roots. The third has two nodes and three terminals. $\endgroup$