A Practical Algorithm for (Geometry-Aware) Interleavings Between Merge Trees
Abstract
Merge trees are a popular topological descriptor for scalar field data. A common measure to compare two merge trees is the interleaving distance, which relies on a mapping between the two merge trees, also referred to as an interleaving. Despite its desirable properties, the interleaving distance has not been used much in practice, largely due to the fact that computing the exact interleaving distance is NP-hard. In this paper, we show that the exact interleaving distance can be computed efficiently for merge trees encountered in practice: we present the first implementation of the exact fixed-parameter tractable (FPT) algorithm by Touli and Wang [17]. This algorithm uses a dynamic program to test if a specific interleaving distance is feasible. They bound the running time using a parameter that captures the number of mapping options between the two merge trees for the output distance . Our experiments show that, even though can become quite large for real-world merge trees, the running time of our implementation does not depend very heavily on . Furthermore, we modify the FPT algorithm into a sweepline algorithm that runs much faster in practice. Finally, we introduce a natural restriction for the interleaving distance capturing the geometric similarity between the underlying scalar fields. This restricted interleaving distance can be computed more efficiently and can, in some settings, also result in more meaningful interleavings. We extend our implementations to support these restrictions and demonstrate their effect on the running time of the algorithms.
Keywords and phrases:
interleaving distance, geometry-aware, exact algorithm, implementationFunding:
Thijs Beurskens: Supported by the Dutch Research Council (NWO) under project no. OCENW.M20.089.Copyright and License:
2012 ACM Subject Classification:
Theory of computation Computational geometry ; Theory of computation Fixed parameter tractabilityEditors:
Martin Aumüller and Irene FinocchiSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Scalar fields are a common model to represent physical phenomena, such as temperature or air pressure, for computational purposes. They assign a numerical value to every point in a domain; when the data is geographic, then we also speak about terrains. Most scalar fields are too large to be used directly in computations. We hence use tools from topological data analysis, such as topological descriptors, to summarize, abstract, or reduce scalar fields, which in turn enables analysis and visualization of their salient features. One popular topological descriptor are merge trees which encode how connected components of sub- or superlevel sets in the scalar field evolve (see Figure 1a). As such, they provide a compact abstraction of the hierarchy of critical points of a scalar field. Merge trees have been used to represent scalar fields in diverse research areas such as material science [15], meteorology [18], and uncertainty visualization [21].
If the data represented by a scalar field varies over time, then we want to quantify the rate of change. That is, we need comparative measures, both on the scalar fields themselves and on their topological descriptor [20]. One of the most studied distance measures for merge trees is the interleaving distance [11]. Intuitively, it measures how far two merge trees are from being “isometric” using structure-preserving maps between the trees. The interleaving distance has favorable theoretical guarantees, but computing it is NP-hard [1]. Touli and Wang [17] described an exact fixed-parameter tractable algorithm which uses a dynamic program. To the best of our knowledge, this algorithm is the only exact algorithm and until now it has not been implemented and tested in practice111The authors of [17] confirmed via personal communication that they did not implement their algorithm..
As a consequence, practical applications of the interleaving distance usually rely on heuristic algorithms. For example, Pegoraro [13] formulated an integer linear program to obtain upper and lower bounds for the interleaving distance. In practice, these bounds often coincide for trees with a small number of leaves (), but the approach becomes computationally impracticable for larger instances. An alternative definition of the interleaving distance in terms of labelings [7, 12] has inspired several heuristics to estimate optimal labelings. In particular, Curry et al. [6] use the Gromov-Wasserstein framework to find good labelings, while Yan et al. [19, 20] use the underlying scalar fields to obtain geometry-aware labelings.
Contributions.
Our main contribution is the first implementation for computing the interleaving distance between two merge trees exactly. More precisely, we implement (1) the fixed-parameter tractable algorithm of Touli and Wang [17], and (2) a modification of their approach that replaces the dynamic program with a sweepline algorithm through the trees. Additionally, inspired by recent geometry-aware approaches [3, 19], we propose a novel heuristic: the restricted interleaving distance. More precisely, we use the geometry of the underlying scalar fields to impose additional geometry-aware restrictions on the allowed maps. We integrate these restrictions in both the dynamic program and the sweepline algorithm. We evaluate the runtime of our implementation through an experimental study on real-world data, and we study the effect the restrictions have on the interleaving distance.
We first give the necessary definitions in Section 2. In the same section we also give a detailed description of the algorithm by Touli and Wang. In Section 3, we describe our sweepline algorithm and show that it correctly computes the interleaving distance. Next, in Section 4, we define the restricted interleaving distance and we propose concrete geometry-aware restrictions based on the underlying scalar fields. Lastly, in Section 5, we discuss our experimental evaluation. Omitted proofs can be found in the appendix.
2 Preliminaries
Let be a rooted tree, that is, a tree with one vertex identified as the root. We identify with a topological realization: the disjoint union of unit intervals that each represent an edge of , whose endpoints are connected according to the adjacencies of . Intuitively we think of as a topological space; we refer to elements of as points.
Definition 1.
A merge tree is a pair , where is a rooted tree and is a continuous height function defined on the topological realisation of such that (i) it is strictly increasing towards the root, and (ii) if and only if is the root.
We refer to the highest non-root vertex in as the top vertex in . For two points and of , we say is a descendant of if there is an -monotonically increasing path from to . If moreover , we say is a strict descendant of . Correspondingly, is called a (strict) ancestor of . For a point of at height , and some , we say the -ancestor of is the ancestor of at height . For a set of points of , we use to denote the lowest common ancestor of all points in . Note that if all have the same height , then has a common -ancestor if and only if has height at most . For a point of , we use to denote the subtree of rooted at (i.e., consisting of all descendants of ); for a finite set of points of , we write for the union of all subtrees for . We define the depth of as the maximum height difference between and any point in the subtree . See Figure 1 for examples.
Scalar field-based merge trees.
Merge trees are typically used to analyze and study scalar fields, that is, a connected domain together with a function that assigns to every point a numeric value. Formally, let be a compact manifold and let be a Morse function on . Two points of are equivalent with respect to , written , if (1) they have the same height value , and (2) they belong to the same connected component of the sublevel (superlevel) set at height . The merge tree based on is the quotient space , that is, the space that arises when we “glue” together all points that are equivalent under . In literature [5, 19], a merge tree defined on sublevel sets is typically referred to as a join tree, and a merge tree defined on superlevel sets is typically referred to as a split tree. The vertices of a scalar field-based merge tree correspond to extrema in the scalar field; the root at represents the entire scalar field.
2.1 Interleaving distance
Consider two merge trees and . The interleaving distance between and was originally defined in terms of two maps, one from to , and one from to [11]. We use an equivalent definition [7] in terms of a single map from to (see Figure 2):
Definition 2 (adapted from [7, Definition 10]).
Given and two merge trees and , a continuous map from to is a -good map if
-
P1.
for all we have ,
-
P2.
for all with , we have for all ,
-
P3.
for all , the depth of is at most .
Touli and Wang [17] describe a decision procedure to determine if a -good map333We note that Definition 2 slightly differs from the one given in [17]. A proof that these definitions are equivalent can be found in [7, Appendix A]. exists for a given value . We sketch this procedure below; see the original paper for a full description. To compute the interleaving distance, they search on a finite set of candidate values. In particular, it has been shown [1, 17] that is always present in the set that contains (1) all height differences between a vertex in and a vertex in , and (2) all height differences, divided by 2, between vertex pairs in the same tree.
Consider a pair , where is a set of points of , all at the same height , and is a single point of at height . A continuous map from to is a partial -good map if P1–P3 hold for all points of and . Note that for P2, we still determine the lowest common ancestor in the complete tree . We say is feasible if a partial -good map from to exists. Touli and Wang [17, Claim 2] show that a -good map between the complete trees and exists if and only if there is a feasible pair for which and both lie above the top vertices in their respective trees.
Decision procedure.
To decide whether a -good map exists, Touli and Wang describe a dynamic program (DP) that computes, for each level, which pairs are feasible. A level is a set of points of at a height and a set of points of at height (see Figure 3a). They consider only levels that contain a vertex in either tree; this results in a discrete set of levels in increasing height order. To compute the set of feasible pairs at some level , the algorithm first determines all sets of points of in that have a common -ancestor (see Figure 3b). Then, for all combinations (“valid pairs”) of such a subset and a point of in , the algorithm determines whether it is feasible:
-
(1)
If is a leaf, then is feasible if and only if consists of only leaves.
-
(2)
Else, let be the descendants of in level . Now is feasible iff the descendants of in level can be partitioned into sets , s.t. for all :
-
(a)
if is not empty, then is feasible,
-
(b)
if is empty, then all leaves in are at most below the height of .
-
(a)
Note that the first level contains only leaves, so the separate base case in [17] is unnecessary.
Touli and Wang show that this decision procedure is fixed-parameter tractable for a parameter . Specifically, for any , they consider connected parts of and of height , and define to be the maximum sum of degrees over these parts:
Now, , where is the interleaving distance between the trees. Touli and Wang bound the running time of the decision procedure by [17, Theorem 2], where is the sum of the number of vertices in both trees.
Search procedure.
Given the -good map decision procedure and the candidate set , we compute the interleaving distance by finding the smallest candidate for which the decision procedure returns yes. The simplest way to do this is via a linear search, resulting in a running time bound of [17, Theorem 4]. Alternatively, we can also use an exponential search on . We can compute for each candidate ; note that monotonically increases for increasing . We then perform an exponential search over the set of possible values for , to find the first for which a -good map exists. Lastly, we perform a binary search to find the exact . This results in a running time bound of [17, Theorem 5]. This improves the dependency on by a factor over linear search, but deteriorates the dependency on by a large exponential factor. As can be relatively large in practice, this is a poor tradeoff to make; for this reason we have not implemented this method and will not report on it in the remainder of this paper.
We propose another simple search procedure that avoids the need to evaluate every single candidate, but still tries to avoid overshooting too much. We first perform an exponential search to upper bound , and then binary search to find the exact interleaving distance. Because in our experiments the decision procedure tends to take significantly longer as increases (see Section 5), instead of simply doubling , we take as the new upper bound the highest candidate that is still within a factor of of the previously established lower bound.
3 Sweepline decision procedure
We can interpret the decision procedure described in Section 2 as a sweepline algorithm: two coordinated sweeplines sweep up through and , where the height of the sweepline in always stays exactly above the one in (see Figure 4a). Whenever either of the sweeplines hits a vertex, an event occurs, and the set of feasible pairs for the corresponding level is computed. We propose an alternative decision procedure that uses this sweepline interpretation: instead of computing all feasible pairs when an event happens, we update only the ones affected by the event. As opposed to the DP, we generally do not need to enumerate all valid pairs. In many cases, the set of feasible pairs is (much) smaller than the set of valid pairs, resulting in a speedup. To compute the interleaving distance, we use the same search procedures described above, but replace the DP by our sweepline procedure.
To simplify the exposition, we assume that the vertices are in general position: every internal vertex has exactly two children, and no two vertices are hit simultaneously by the sweepline. We justify this assumption in Section 3.3: for any merge tree and any , we can construct a merge tree within interleaving distance that satisfies the assumption.
3.1 Event handling
We maintain for each point of on the sweepline, all non-empty sets of points of on the sweepline such that is feasible. Let and be the number of leaves in and , respectively. We assume the leaves in each tree are indexed from left to right in such a way that the indices of the set of leaves in a subtree always form an integer interval; this can be achieved using an in-order tree walk on the input. We index each point on the sweepline by the lowest-index leaf in its subtree (see Figure 4b); when we discuss points on the sweepline, we write “vertex in ” instead of “vertex in with index ”. If an internal vertex is on the sweepline, its two descendants just below the sweepline have indices and , where . We refer to and as the children of .
We maintain the set of feasible pairs in a list of elements. Consider an index from . If no point of on the sweepline has index , then . Otherwise, if there is a point , then represents all non-empty sets of points of on the sweepline such that is feasible. We store every such set as the corresponding set of indices (see Figure 4c). When the sweepline hits a vertex, an event happens and we need to update :
-
(a)
Leaf in : Initialize .
-
(b)
Internal vertex in : Let be the children of . Set . For each and , add to if and only if and (i) have the same -ancestor, and (ii) are disjoint (see Figure 5). Additionally, if the depth of the left (right) subtree is at most , add all elements of () to . Finally, set and .
-
(c)
Leaf in : For each index from on the sweepline: (1) for each set in , add the set to if and only if and have the same -ancestor, and (2) if the depth of the point of on the sweepline with index is at most , add to .
-
(d)
Internal vertex in : Let be the children of . For each index from on the sweepline, for each set in , if contains exactly one of and , delete from ; if contains both, replace by .
The sweepline terminates after handling the last event, that is, when the top vertices of both and have been handled. Consider the set after the sweepline terminates. Let be the top vertex in . By construction, has index . We conclude that a -good map exists if and only if (a) the depth of is at most , or (b) contains at least one element.
To prove that our sweep is correct, we make two observations. Consider a partial -good map from to , for some set of points of and a point of . Then we can extend until we hit an internal vertex: let be the ancestors of points in at a fixed height, and assume that there are no internal vertices between points in and their ancestor in . We define the extension of to : for every point of that is not in , let be the ancestor of at height . We set . Since there are no new internal vertices in , the extension is well-defined for all points of . Moreover, is continuous and satisfies P1–P3.
Observation 3.
Let be a partial -good map. Any extension of that does not extend above an internal vertex is a partial -good map.
On the other hand, we can also restrict such that its image remains a subtree of . The resulting map is again a partial -good map: P1–P3 follow directly.
Observation 4.
Let be a partial -good map from to , and let be a set of points in with the same image. Then restricted to is a partial -good map.
We are now ready to prove that the sweepline maintains all non-empty feasible pairs.
Lemma 5.
Assume and are in general position. After handling any event, the set correctly represents all non-empty feasible pairs at the height of that event.
3.2 Data structure
For efficient event handling, we store in a suitable data structure. Specifically, we store each (non-nil) element in a balanced binary search tree, such as a red–black tree, which allows efficient searches, insertions, and deletions. When storing some in the tree, we use the lowest-indexed element of as its key. This way, the sets in are always ordered by their lowest-indexed element, which allows us to efficiently handle the -ancestor check in (b) events as follows.
Event (b) asks us to try all combinations of and and see if they have the same -ancestor. Instead, we check for each potential -ancestor which sets and descend from it, and only try these combinations. Let be the (ordered) sequence of indices of at height above the sweepline, that is, is the sequence of potential -ancestors of and . The problem boils down to finding, for a given ancestor , the subset of that have as its -ancestor. This is the subset of all for which the lowest-indexed element of is between (inclusive) and (exclusive). As is sorted on the lowest-indexed element, this subset of elements is a contiguous range, which we can delineate by searching in the binary search tree for and .
We note that this data structure admits an easy and efficient implementation in practice if we represent each set as a bit string of which the -th bit is set if and only if . Such a representation not only allows us to compute unions and intersections efficiently, but also sorting the bit strings lexicographically ensures that they are sorted by their lowest-indexed element.
3.3 General position
Let be a merge tree, and let such that is smaller than the height difference between any two adjacent vertices in . A merge tree is an -perturbation of if there is a homeomorphism from to such that for all points of (see Figure 6a). It is not hard to show that the interleaving distance between and an -perturbation is at most .
Lemma 6.
Let be a merge tree and let be any -perturbation for sufficiently small . Then .
Suppose has a vertex that has children . We expand into distinct vertices such that each vertex has two children: and (see Figure 6b). We define the expansion of by expanding all vertices in , together with the height function that assigns to each new vertex the same height as . An extension is not a merge tree; however, for any value there does exists an -perturbation of that is a merge tree. We define the interleaving distance between two expansions and as the limit of the interleaving distance between such -perturbed merge trees and :
Corollary 7.
The interleaving distance between any two merge trees is equal to the interleaving distance between their expansions.
In the algorithm we handle expansions by placing the expanded vertices on exactly the same height, and separating them symbolically. That is, the vertices all lie on the same level, and when we process that level, we handle them one by one.
4 Restrictions
We consider a generalization of the interleaving distance that imposes additional restrictions on the allowed -good maps. Intuitively, each restriction specifies for some leaf in all points of that are “reachable” by . Formally, let be a merge tree. A subset of points of is called a pruning of if it is a merge tree again, that is, it is connected and contains the root of (see Figure 7a). For two merge trees and , a restriction from to is a set of prunings for each leaf in . In other words, if a point of is reachable by , then all ancestors of are also reachable by . This condition ensures that a -good map that respects the restriction always exists. If for each leaf in , we recover the unrestricted interleaving distance.
Definition 8.
Given two merge trees and and a restriction from to , a -good map from to is -restricted if
-
P4.
for all leaves we have .
The -restricted interleaving distance between and is defined as the infimum for which there exists an -restricted -good map from to .
Analogous to the unrestricted setting, we define a partial -restricted -good map as a partial -good map that additionally satisfies P4. A pair is -feasible if there exists a partial -restricted -good map from to . We show that the value is always in a finite set that consists of (1) all values in , and (2) the height differences between a leaf in and a leaf in .
Lemma 9.
.
The proof of Lemma 9 directly implies that the infimum in Definition 8 can be replaced by a minimum: for any , if an -restricted -good map exists then there also exists an -restricted -good map with and such that .
Corollary 10.
For any two merge trees and and any restriction from to , there exists a -restricted -good map from to with .
4.1 Computing the restricted interleaving distance
We compute the -restricted interleaving distance between and using a similar approach as for computing the unrestricted interleaving distance. More precisely, we can still search on the set of candidate values, but instead of searching over all values in , we search over all values in . Moreover, to decide for a given value whether an -restricted -good map exists, we use a modified version of either the DP as described in Section 2, or the sweepline algorithm as described in Section 3.
Recall that and denote the number of leaves in and , respectively. We represent a restriction using a matrix of size . Consider a leaf in with index , and a leaf in with index . The entry stores the height of the lowest ancestor of that is in the pruning . We refer to as the restriction matrix of (see Figure 7b).
Sweepline decision procedure.
Intuitively, we only need to verify that when we add a pair for which contains a leaf in , that . It suffices to modify event (c):
-
(c’)
Leaf in : Let be the height of the sweepline within . For each index from on the sweepline with : (1) for each set in , add the set to if and only if and have the same -ancestor, and (2) if the depth of the point of on the sweepline with index is at most , add to .
The sweepline terminates after handling the last event, that is, when the top vertices of both and have been handled. Consider the set after the sweepline terminates and let be the top vertex in . Analogous to the unrestricted setting, we conclude that a -restricted -good map exists if and only if (a) the depth of is at most , or (b) contains at least one element.
Lemma 11.
Assume and are in general position. After handling any event, the set correctly represents all non-empty feasible pairs at the height of that event.
DP decision procedure.
We need a similar modification of the dynamic program: if we consider a pair for which contains a leaf in , we need to verify that additionally . We can perform this check when computing all valid pairs. The proof that this computes the restricted interleaving distance is analogous to the proof of Lemma 11.
4.2 Geometry-aware restrictions
Consider a (finite) sequence of scalar fields , that is, a 2D or 3D domain whose height function changes over time. Let denote the distance between points of . Fix two instances and , and let and be the corresponding scalar field-based merge trees. Without loss of generality, assume and are based on sublevel sets; their leaves correspond to minima in their respective scalar fields. Intuitively, assuming the two instances are not too far apart and the scalar field evolves smoothly over time, we do not expect big changes in the geometry of the extrema: each minimum in has a corresponding minimum in close by. We use this to define a restriction from to : a leaf in is allowed to map to a point of if the corresponding minima are not “too far” apart. Formally, we define a restriction , where is a threshold variable that captures how far is too far. Let be a leaf in . Then corresponds to a minimum in ; let be the point of where the minimum lies. Similarly, each point of corresponds to a sublevel set component; let denote the sublevel set component that contains . We define if and only if . This defines a pruning: if , then the sublevel set component of any ancestor of contains , so .
Observation 12.
For any leaf in and any value , the set is a pruning.
Our idea of a geometry-aware heuristic is inspired by a heuristic by Yan et al. [19]. Specifically, they also use the geometry of the underlying scalar fields as a heuristic to compute the interleaving distance. However, their method uses a matching between extrema of the scalar fields to compute a labeling on the merge trees; the resulting interleaving distance is then the labeled interleaving distance for that specific labeling. Our method is more general: each leaf is allowed to map to more than one point. In particular, if we set , then for each leaf in and we recover the unrestricted interleaving distance.
5 Experimental evaluation
We implemented the algorithms described above and ran them on two different datasets. In this paper, we study only the running time of our implementation; we do not study the quality of the resulting interleavings for the analysis of scalar fields.
Datasets.
We used two datasets that Yan et al. [19] also used to evaluate their methods. For both datasets, we used the Topology Toolkit (TTK) [4, 10, 16] to generate split trees. The HeatedFlow444https://cgl.ethz.ch/research/visualization/data.php dataset comes from a simulation of a 2D flow generated by a heated cylinder [8, 14]. The RedSea555https://kaust-vislab.github.io/SciVis2020/ dataset was used in the 2020 SciVis Contest [9, 22, 23]. For both datasets, we used the same preprocessing steps as Yan et al. [19], except that we did not use persistence simplification to prune the merge trees, as we want to demonstrate the running times on larger merge trees.
To create pairs and corresponding restrictions to run the algorithm on, we selected sets of frames from both datasets (frames for HeatedFlow and frames for RedSea) and considered all pairs of frames (where always corresponds to the earlier frame). This resulted in 66 instances for HeatedFlow, and 78 instances for RedSea. The number of leaves per tree instances ranges from 83 to 108 (average 96.4) for HeatedFlow and from 39 to 57 (average 46.9) for RedSea. For each instance, we generated geometry-aware restriction matrices , where for HeatedFlow and for RedSea (measured in pixels). Recall that represents the unrestricted interleaving distance.
Implementation details.
We implemented the algorithm in C++ and ran all experiments on a workstation with an AMD Ryzen 9 9950X CPU and 64 GB RAM running Ubuntu 25.10. Although the CPU has 16 cores, we ran the experiments single-threaded to be able to measure the running times as accurately as possible. For the decision procedure, we implemented both the DP and the sweepline variants. For the search procedure, we implemented both linear search and the -exponential/binary search (referred to as “exponential search” in the remainder) as described at the end of Section 2.1.
While implementing, we noticed that a naive implementation of the algorithm can be sensitive to floating-point rounding errors. In particular, if is the interleaving distance between and , there exists a -good map from to ; however, if we call the decision procedure with exactly, it may fail to find this -good map due to rounding errors. This may lead the search procedure to output an incorrect interleaving distance. We alleviate this problem by calling the decision procedure for values between the candidates, instead of for the candidates themselves. Specifically, let be the sorted candidate list. We then perform the search procedure on the list . Given an outcome that a -good map exists but a -good map does not, we can conclude that the true interleaving distance must be .
Furthermore, in our implementation we optimized the size of the candidate set . Recall that contains (1) all height differences between a vertex in and a vertex in , and (2) all height differences, divided by 2, between vertex pairs in the same tree. However, it turns out that the interleaving distance is always realized by a subset of these values, that contains (1) all height differences between a leaf in and a leaf in (or, in the restricted setting, in its pruning), (2) all height differences between an internal vertex in and an internal vertex in , and (3) all height differences, divided by 2, between a leaf and an ancestor vertex in the same tree. Note that it is possible for to contain (nearly) as many candidates as the full set , so this optimization does not affect a worst-case running time analysis. However, it could save some time in practice by reducing the number of binary search steps needed.
| dataset | HeatedFlow | RedSea | |||||
|---|---|---|---|---|---|---|---|
| restriction radius | 10 | 0 | 25 | 10 | 0 | ||
| avg. interleaving distance | 0.1172 | 0.4710 | 0.5717 | 0.1657 | 0.1766 | 0.2200 | 0.3216 |
| total time DP (s) | 4453 | 3706 | 3054 | 7.752 | 6.866 | 6.550 | 5.937 |
| total time sweepline (s) | 652.2 | 154.4 | 144.9 | 2.425 | 2.308 | 2.426 | 2.391 |
5.1 Results
We ran our algorithm on all instances of HeatedFlow and RedSea. We used only the exponential search procedure, as running the linear search procedure was exceedingly slow and did not finish in a reasonable amount of time. We also set a timeout at 300 seconds for each run. The DP procedure reached the timeout 5 times for HeatedFlow, while the sweepline procedure never reached the timeout. We summarize the accumulated results in Table 1; in this table we count timeouts as contributing just 300 seconds to the total time.
Decision procedure.
The results clearly show that, in practice, the sweepline decision procedure is much faster than the DP decision procedure. For both datasets and for each restriction radius , the total running time using the DP procedure is – higher than the total running time using the sweepline procedure. Due to the algorithm hitting timeouts with the DP procedure, the “true” total time for DP would have been even higher.
To investigate the variation in running time between instances of the same dataset, we show the running time of every HeatedFlow instance with in Figure 8a. We observe that the sweepline procedure outperforms the DP procedure on every single instance.
Restrictions.
For HeatedFlow, the running time of both procedures decreases if we choose a smaller restriction radius ; for the sweepline decision procedure this decrease (a factor ) is more significant than for the DP procedure. However, this comes at a cost: choosing a smaller restriction radius results in a distance that is significantly larger (a factor ) than the unrestricted interleaving distance. These results raise the question of how accurately the interleaving distance between two scalar field based merge trees reflects the similarity of the scalar fields. After all, if the restrictions increase this much, apparently the lower interleaving distances observed in the unrestricted case match critical points that lie far apart in the scalar fields. We leave this question for future research.
For RedSea, the distance results are slightly better. In fact, for they are similar to the actual distance. However, in this dataset the running times do not decrease significantly; this is likely due to the fact that these instances are smaller than the HeatedFlow instances, and therefore a larger fraction of the running time is spent on preprocessing.
Search procedure.
The theoretical running time analysis by Touli and Wang [17] (see Section 2.1) indicates that the running time is highly exponential in . Because increases as a function of , this suggests that overshooting could be detrimental for performance. Linear search is a way to avoid overshooting and hence could be a sensible search strategy.
However, in practice it turns out linear search is overwhelmingly much slower than exponential search, so much so that it did not complete in a reasonable time for many instances, while exponential search is often very fast. To investigate this behavior, we plotted (see Figure 8b) for one of the instances in the RedSea dataset (frames 15–30, no restrictions) for which linear search was feasible, how long the DP and sweepline decision procedures took for all candidate values (also the candidate values higher than ). It is clear that the running time does in fact not at all increase monotonically as a function of or (see also Figure 8c), so overshooting is not inherently a problem.
In addition to , we consider a second parameter . For a point of or , consider the number of descendants of that lie exactly below . We define to be this number, maximized over all points of and . Although does not increase monotonically in , we observe a correlation between the running times and the , see Figure 8b–c.
6 Conclusion
We have presented the (to the best of our knowledge) first implementation for computing the exact interleaving distance between merge trees, and thereby demonstrated that computing the exact interleaving distance is feasible for many instances in practice, especially when using our sweepline procedure. We see this implementation as a starting point for further algorithm engineering on computing the (exact) interleaving distance. Our (geometry-aware) restrictions are a step in this direction and do indeed result in speedups, specifically for larger instances. However, the interleaving distance also significantly increases with restrictions; future research should determine whether these restrictions are too restrictive or if the restricted interleavings better reflect the similarity between the underlying scalar fields.
References
- [1] P.K. Agarwal, K. Fox, A. Nath, A. Sidiropoulos, and Y. Wang. Computing the Gromov-Hausdorff distance for metric trees. ACM Transactions on Algorithms, 14(2):1–20, 2018. doi:10.1145/3185466.
- [2] T. Beurskens, T. Ophelders, B. Speckmann, and K. Verbeek. Locally correct interleavings between merge trees. arXiv:2512.16474.
- [3] T. Beurskens, T. Ophelders, B. Speckmann, and K. Verbeek. Relating interleaving and Fréchet distances via ordered merge trees. In Proc. ACM-SIAM Symposium on Discrete Algorithms (SODA25), pages 5027–5050. Society for Industrial and Applied Mathematics, 2025. doi:10.1137/1.9781611978322.170.
- [4] T. Bin Masood, J. Budin, M. Falk, G. Favelier, C. Garth, C. Gueunet, P. Guillou, L. Hofmann, P. Hristov, A. Kamakshidasan, C. Kappe, P. Klacansky, P. Laurin, J.A. Levine, J. Lukasczyk, D. Sakurai, M. Soler, T. Steneteg, J. Tierny, W. Usher, J Vidal, and M. Wozniak. An overview of the topology toolkit. Topological Methods in Data Analysis and Visualization VI: Theory, Applications, and Software, pages 327–342, 2021. doi:10.1007/978-3-030-83500-2_16.
- [5] H. Carr, J. Snoeyink, and U. Axen. Computing contour trees in all dimensions. Computational Geometry, 24(2):75–94, 2003. doi:10.1016/S0925-7721(02)00093-7.
- [6] J. Curry, H. Hang, W. Mio, T. Needham, and O. B. Okutan. Decorated merge trees for persistent topology. Journal of Applied and Computational Topology, 6(3):371–428, February 2022. doi:10.1007/s41468-022-00089-3.
- [7] E. Gasparovic, E. Munch, S. Oudot, K. Turner, B. Wang, and Y. Wang. Intrinsic interleaving distance for merge trees. La Matematica, 4(1):40–65, 2025. doi:10.1007/s44007-024-00143-9.
- [8] T. Günther, M. Gross, and H. Theisel. Generic objective vortices for flow visualization. ACM Transactions on Graphics, 36(4):141:1–141:11, 2017. doi:10.1145/3072959.307368.
- [9] I. Hoteit, X. Luo, M. Bocquet, A. Kohl, and B. Ait-El-Fquih. Data assimilation in oceanography: Current status and new directions. New frontiers in operational oceanography, pages 465–512, 2018. doi:10.17125/gov2018.ch17.
- [10] E. Le Guillou, M. Will, P. Guillou, P. Lukasczyk, P. Fortin, C. Garth, and J. Tierny. TTK is Getting MPI-Ready. IEEE Transactions on Visualization and Computer Graphics, 2024.
- [11] D. Morozov, K. Beketayev, and G. Weber. Interleaving distance between merge trees. Manuscript (accessed on 06-03-2025), 2013. URL: https://mrzv.org/publications/interleaving-distance-merge-trees/manuscript/.
- [12] E. Munch and A. Stefanou. The -Cophenetic metric for phylogenetic trees as an interleaving distance. In Research in Data Science, volume 17 of Association for Women in Mathematics Series, pages 109–127. Springer International Publishing, 2019. doi:10.1007/978-3-030-11566-1_5.
- [13] M. Pegoraro. A graph-matching formulation of the interleaving distance between merge trees. AIMS Mathematics, 10(6):13025–13081, 2025. doi:10.3934/math.2025586.
- [14] S. Popinet. Free computational fluid dynamics. ClusterWorld, 2(6), 2004. URL: http://gfs.sf.net/.
- [15] S.S. Thygesen, A.I. Abrikosov, P. Steneteg, T.B. Masood, and I. Hotz. Level of detail visual analysis of structures in solid-state materials. In EuroVis (Short Papers), pages 55–59, 2023. doi:10.2312/evs.20231043.
- [16] J. Tierny, G. Favelier, J.A. Levine, C. Gueunet, and Michaux M. The Topology ToolKit. IEEE Transactions on Visualization and Computer Graphics, 1, 2017. doi:10.1109/TVCG.2017.2743938.
- [17] E.F. Touli and Y. Wang. FPT-algorithms for computing the Gromov-Hausdorff and interleaving distances between trees. Journal of Computational Geometry, 13:89–124, 2022. doi:10.20382/jocg.v13i1a4.
- [18] A.A. Valsangkar, J.M. Monteiro, V. Narayanan, I. Hotz, and V. Natarajan. An exploratory framework for cyclone identification and tracking. IEEE Transactions on Visualization and Computer Graphics, 25(3):1460–1473, March 2019. doi:10.1109/TVCG.2018.2810068.
- [19] L. Yan, T. B. Masood, F. Rasheed, I. Hotz, and B. Wang. Geometry aware merge tree comparisons for time-varying data with interleaving distances. IEEE Transactions on Visualization and Computer Graphics, 29(8):3489–3506, 2022. doi:10.1109/TVCG.2022.3163349.
- [20] L. Yan, T. B. Masood, R. Sridharamurthy, F. Rasheed, V. Natarajan, I. Hotz, and B. Wang. Scalar field comparison with topological descriptors: Properties and applications for scientific visualization. Computer Graphics Forum, 40(3):599–633, 2021. doi:10.1111/cgf.14331.
- [21] L. Yan, Y. Wang, E. Munch, E. Gasparovich, and B. Wang. A structural average of labeled merge trees for uncertainty visualisation. IEEE Transactions on Visualization and Computer Graphics, 26(1):832–842, 2020. doi:10.1109/TVCG.2019.2934242.
- [22] P. Zhan, G. Krokos, D. Guo, and I. Hoteit. Three-dimensional signature of the Red Sea eddies and eddy-induced transport. Geophysical Research Letters, 46(4):2167–2177, 2019. doi:10.1029/2018GL081387.
- [23] P. Zhan, A.C. Subramanian, F. Yao, and I. Hoteit. Eddies in the Red Sea: A statistical and dynamical study. Journal of Geophysical Research: Oceans, 119(6):3909–3925, 2014. doi:10.1002/2013JC009563.
Appendix A Omitted proofs
Lemma 5. [Restated, see original statement.]
Assume and are in general position. After handling any event, the set correctly represents all non-empty feasible pairs at the height of that event.
Proof.
We prove by induction on the number of events. After the first event there are no non-empty feasible pairs, which the algorithm correctly determines. Assume that the sweepline is at the -th event; the induction hypothesis (IH) states that the set after handling the -st event correctly represents all non-empty feasible pairs. Consider a non-empty set of points of on the sweepline and a single point of on the sweepline. We refer to the descendants of and on the sweepline at the -st event as the children of and , respectively. Let be the indices of points in , and let be the index of . We need to show that is feasible if and only if .
If does not contain any vertex in and is not a vertex in , then then let be the children of , and let be the child of . By construction, the points in and the point are indexed the same as the points in and the point , respectively. We do not address in between these events, so if and only if . Similarly, the pair is feasible if and only if is feasible: any partial -good map can be extended or restricted. By the IH, we know that is feasible if and only if . Combining: is feasible if and only if . It remains to show the case that either contains a vertex, or is a vertex. We distinguish four cases. In each case, if is feasible, denotes a partial -good map from to .
is a leaf – (a)
The only valid map from to takes each point of to . By assumption, the set is non-empty. As no two events happen simultaneously, the subtree must contain points below the sweepline. In other words, there cannot be a partial -good map from to , and hence is not feasible. The procedure correctly determines that is empty; in particular, .
is an internal vertex – (b)
Let be the children of and let be the children of . By construction, the indices of the children of are and ; without loss of generality assume has index and has index . As no two events happen simultaneously, all indices in are on the sweepline at the previous event. Suppose is feasible. By P2, all points in have the same -ancestor. Let and . By Observation 4, the restrictions of to and are both partial -good maps. Let and be the sets of indices of and , respectively. If is non-empty, then by the IH, it follows that . Similarly, if is non-empty, then . By definition, and are disjoint and their union is equal to . If is empty, then by P3, the depth of the left subtree at is at most , and symmetrically, if is empty, the depth of the right subtree at is at most . In all cases, we get .
For the other direction, suppose . One of three cases must be true: (i) there are disjoint non-empty sets and such that , (ii) and the depth of the right subtree at is at most , or (iii) and the depth of the left subtree at is at most . In case (i), by the IH, there exist partial -good maps from to and from to . Their extensions to the height of the sweepline do not extend above any vertices of , so by Observation 3 they are again partial -good maps. Together, they map each point of to , so their combination is a partial -good map from to . Hence, is feasible. It remains to show case (ii); case (iii) is symmetric. Since , by the IH, there is a partial -good map from to . The extension of is a partial -good map from to : P1 and P2 are trivially satisfied, and since the depth of the right subtree is at most , P3 is also satisfied. So, the pair is feasible.
contains a leaf – (c)
Let denote the children of , and let denote the set of indices of . Suppose is feasible. If is empty, then by P3, it follows that the depth of is at most , and after handling the event we have . If is not empty, then as no two events happen simultaneously, all points of have the same image. Hence, the restriction of to is a partial -good map (by Observation 4). By the IH, it follows that . Moreover, by P2, all points of have the same -ancestor, so .
To show the other direction, suppose . If is empty, then the depth of is at most . In other words, the map with is a partial -good map from to . So the pair is feasible. Otherwise, if is not empty, we know that and that the ancestors of on the sweepline have the same -ancestor as . By the IH, there exists a partial -good map from to , where is the child of . By Observation 3, the extension of to the sweepline is again a partial -good map. If we moreover set we do not violate P1–P3, so the new map is a partial -good map from to . So, the pair is feasible.
contains an internal vertex – (d)
Let be the children of , with indices and . Without loss of generality, assume ; by construction, has index , so . Let denote the children of with indices . Suppose is feasible. By Observation 4, the restriction of to is a partial -good map. So, it follows by the IH that . The set contains both and , so the algorithm correctly determines .
For the other direction, suppose . Then the set must be in . By the IH there is a partial -good map from to , where is the child of . The extension of to is a partial -good map, so is feasible.
Lemma 6. [Restated, see original statement.]
Let be a merge tree and let be any -perturbation for sufficiently small . Then .
Proof.
Let be a homeomorphism from to that satisfies . We define a map from to as follows. For each point of , the height of is at most . Hence, the ancestor of at height is well-defined. We define . By construction, the map satisfies P1. Moreover, since is a homeomorphism and we only take ancestors at a fixed height, the map is continuous.
It remains to show that satisfies P2 and P3. Consider a point of . If , let and be distinct points in , and let be the lowest common ancestor of and . We have , so and lie on distinct edges. Since is a homeomorphism, the points and also lie on distinct edges, so the lowest common ancestor of and must be a descendant of . Both and are vertices, so by choice of , we get and . In particular, it follows that . So P2 holds.
If , then let be the point of such that ; then . Let , which must be an ancestor of in the image of . By construction, . We obtain ; this shows P3.
Lemma 9. [Restated, see original statement.]
.
Proof.
Let be an -restricted -good map, for some , and let be the largest value in such that . We show that there always exists an -restricted -good map ; this directly implies the lemma. If we are immediately done, so assume . We define the lower endpoint of a point of as the lower endpoint of the edge in that contains ; if is a vertex, then the lower endpoint of is itself. We use a similar shorthand for points of . For each point of , let be the lower endpoint of . Similarly, let be the lower endpoint of . Both and are vertices, so the value . By choice of , it then follows that . Therefore, there exists an ancestor of at height . We define .
To show that is continuous, it suffices to show that is a descendant of . Let be points of such that is a descendant of . Let and be the lower endpoints of and , respectively, and let and be the lower endpoints of and , respectively. We directly obtain that is a descendant of . Since is continuous, the point is a descendant of , and as a result is a descendant of . It follows that is a descendant of . So, is continuous.
It remains to show that satisfies P1–P3. By construction, P1 directly holds. To see that P2 holds, we first observe that is a descendant of for all points of : since is continuous, we know that is a descendant of , where is the lower endpoint of . Since is an ancestor of , it follows that lies on the path between and ; so indeed, is a descendant of . Consider two points and of with , and let , and denote the lower endpoints of , and , respectively. Without loss of generality, we assume that . Let be the maximum of and , and let and denote the ancestors of and at height ; note that by construction the point lies on the edge between and (and similarly lies between and ), and that . The points and are both ancestors of and hence lie on the same edge as . As is continuous, it follows that . By P2, we thus obtain . If , then both and are vertices in , so by choice of it follows that . In particular, this means that . Otherwise, if , then since both and are vertices we know that . By choice of , it then follows that . Moreover, by construction of , we know that . Together, we obtain . So, satisfies P2.
Recall that for each point , the point is a descendant of . As a result, if is in the image of , then it is also in the image of . It directly follows that satisfies P3. Lastly, consider a leaf in . The map is -restricted, so . In particular, let be any leaf in that is a descendant of . Then the height difference between and is at most . Moreover, . Hence, by choice of , we know that . It follows that , so P4 holds.
Lemma 11. [Restated, see original statement.]
Assume and are in general position. After handling any event, the set correctly represents all non-empty feasible pairs at the height of that event.
Proof.
We use an analogous proof as for Lemma 5, but we need additional arguments for handling (c) events. More precisely, consider a set of points of on the sweepline, and a point of on the sweepline, and let and denote the set of indices of and the index of , respectively. If does not contain a leaf, then is -feasible if and only if is feasible, and is feasible if and only if . It remains to show that if contains a leaf, then is feasible if and only if after handling the corresponding event. We note here that Observations 3 and 4 hold also for -restricted -good maps.
contains a leaf – (c’)
Let denote the children of , and let denote the set of indices of . By construction, we have , where is the index of . Moreover, let be the height of the sweepline within , that is, . Suppose is feasible, that is, there exists an -restricted partial -good map from to . In particular, this means that . In other words, we have . If is empty, then by P3, it follows that the depth of is at most , and hence . If is not empty, then as no two events happen simultaneously, all points of have the same image. Hence, the restriction of to is an -restricted partial -good map. By the IH, it follows that . Moreover, by P2, all points of have the same -ancestor: we obtain .
To show the other direction, suppose . Then , so . If is empty, the depth of is at most . Then, the map defined by is an -restricted -good map from to . In other words, is -feasible. Otherwise, if is not empty, we know that and that the ancestors of on the sweepline and have the same -ancestor. By the IH, there exists an -restricted partial -good map from to , where is the child of . By Observation 3, the extension of to the sweepline is again an -restricted partial -good map, and extending it by setting does not affect P1–P3. So, is feasible.
