SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Fitting trees to  $\ell_1$ -hyperbolic distances
Joon-Hyeok Yim Anna C. Gilbert
Building trees to represent or to fit distances is a critical component of phylogenetic analysis, metric embeddings, approximation algorithms, geometric graph neural nets, and the analysis of hierarchical data. Much of the previous algorithmic work, however, has focused on generic metric spaces (i.e., those with no a priori constraints). Leveraging several ideas from the mathematical analysis of hyperbolic geometry and geometric group theory, we study the tree fitting problem as finding the relation between the hyperbolicity (ultrametricity) vector and the error of tree (ultrametric) embedding. That is, we define a vector of hyperbolicity (ultrametric) values over all triples of points and compare the  $\ell_p$  norms of this vector with the  $\ell_q$  norm of the distortion of the best tree fit to the distances. This formulation allows us to define the average hyperbolicity (ultrametricity) in terms of a normalized  $\ell_1$  norm of the hyperbolicity vector. Furthermore, we can interpret the classical tree fitting result of Gromov as a  $p = q = \infty$  result. We present an algorithm HCCROOTEDTREEFIT such that the  $\ell_1$  error of the output embedding is analytically bounded in terms of the  $\ell_1$  norm of the hyperbolicity vector (i.e.,  $p = q = 1$ ) and that this result is tight. Furthermore, this algorithm has significantly different theoretical and empirical performance as compared to Gromov's result and related algorithms. Finally, we show using HCCROOTEDTREEFIT and related tree fitting algorithms, that supposedly standard data sets for hierarchical data analysis and geometric graph neural networks have radically different tree fits than those of synthetic, truly tree-like data sets, suggesting that a much more refined analysis of these standard data sets is called for.
Constructing trees or ultrametrics to fit given data are both problems of great interest in scientific applications (e.g., phylogeny), algorithmic applications (optimal transport and Wasserstein distances are easier, for example, to compute quickly on trees), data visualization and analysis, and geometric machine learning. An ultrametric space is one in which the usual triangle inequality has been strengthened to  $d(x,y) \leq \max \{d(x,z), d(y,z)\}$ . A hyperbolic metric space is one in which the metric relations amongst any four points are the same as they would be in a tree, up to the additive constant  $\delta$ . More generally, any finite subset of a hyperbolic space "looks like" a finite tree.
There has been a concerted effort to solve both of these problems in the algorithmic and machine learning communities, including [1]–[5] among many others. Indeed, the motivation for embedding into hyperbolic space or into trees was at the heart of the recent explosion in geometric graph neural networks [6].
As an optimization problem, finding the tree metric that minimizes the  $\ell_p$  norm of the difference between the original distances and those on the tree (i.e., the distortion) is known to be NP-hard for most formulations. [7] showed that it is APX-hard under the  $\ell_{\infty}$  norm. The first positive result also came from [7], which provided a 3-approximation algorithm and introduced a reduction technique from a tree metric to an ultrametric (a now widely used technique). The current best known result is an  $O((\log n\log \log n)^{1 / p})$  approximation for  $1 < p < \infty$  [2], and  $O(1)$  approximation for  $p = 1$ ,
Hyperbolicity measure	Value	Distortion
Gromov's δ-hyperbolicity	δ = ||Δx||∞	||d - dT||∞ = O(δ log n) = O(||Δx||∞ log n)
Average hyperbolicity	δ = 1/(n-1/3) ||Δx||1	||d - dT||1 = O(δn3) = O(||Δx||1)
Table 1: Connection between  $\delta$  -hyperbolicity and average hyperbolicity and how these quantities determine the distortion of the resulting tree metric.
recently shown by [1]. Both papers exploit the hierarchical correlation clustering reduction method and its LP relaxation to derive an approximation algorithm.
While these approximation results are fruitful, they are not so practical (the LP result uses an enormous number of variables and constraints). On the more practical side, [8] provided a robust method, commonly known as Neighbor Join (which can be computed in  $O(n^3)$  time), for constructing a tree. Recently, [9] proposed an  $O(n^2)$  method known as TreeRep for constructing a tree. Unfortunately, neither algorithm provides a guaranteed bound on the distortion.
The main drawback with all of these results is that they assume almost nothing about the underlying discrete point set, when, in fact, many real application data sets are close to hierarchical or nearly so. After all, why fit a tree to generic data only to get a bad approximation? In fact, perhaps with some geometric assumptions on our data set, we can fit a better tree metric or ultrametric, perhaps even more efficiently than for a general data set.
Motivated by both Gromov's  $\delta$ -hyperbolicity [4] and the work of Chatterjee and Slonam [10] on average hyperbolicity, we define proxy measures of how tree-like a data set is. We note that [4], [11] provide a simple algorithm and analysis to find a tree approximation for which the maximum distortion  $(\ell_{\infty}$  norm) is bounded by  $O(\delta \log n)$ , where  $\delta$  is the hyperbolicity constant. Moreover, this bound turns out to be the best order we can have. In this paper, we go beyond the simple notion of  $\delta$ -hyperbolicity to define a vector of hyperbolicity values  $\Delta(d)$  for a set of distance values. The various  $\ell_p$  norms of this vector capture how tree-like a data set is. Then, we show that the  $\ell_q$  norm of the distortion of the best fit tree and ultrametrics can be bounded in terms of this tree proxy. Thus, we give a new perspective on the tree fitting problem, use the geometric nature of the data set, and arrive at, hopefully, better and more efficient tree representations. The table below captures the relationship between the different hyperbolicity measures and the tree fit distortion. We note the striking symmetry in the tradeoffs.
Our main theoretical result can be summarized as
There is an algorithm which runs in time  $O(n^{3} \log n)$  which returns a tree metric  $d_{T}$  with distortion bounded by the average (or  $\ell_1$ ) hyperbolicity of the distances; i.e.,
$$
\| d - d _ {T} \| _ {1} \leq 8 \| \boldsymbol {\Delta} _ {x} (d) \| _ {1} \leq 8 \binom {n - 1} {3} \operatorname {A v g H y p} (d).
$$
Additionally, the performance of HCCROTTEDTREEFIT and other standard tree fitting algorithms on commonly used data sets (especially in geometric graph neural nets) shows that they are quite far from tree-like and are not well-represented by trees, especially when compared with synthetic data sets. This suggests that we need considerably more refined geometric notions for learning tasks with these data sets.
2.1 Basic definitions
To set the stage, we work with a finite metric space  $(X,d)$  and we set  $|X| = n$ , the number of triples in  $X$  as  $\binom{n}{3}=\ell$ , and  $r=\binom{n}{4}$  the number of quadruples of points in  $X$ . In somewhat an abuse of notation, we let  $\binom{X}{3}$  denote the set of all triples chosen from  $X$  (and, similarly, for all quadruples of points). Next, we recall the notion of hyperbolicity, which is defined via the Gromov product [4]. Given a metric space  $(X,d)$ , the Gromov product of two points  $x,y\in X$  with respect to a base point
$w\in X$  is defined as
$$
g p _ {w} (x, y) := \frac {1}{2} \left(d (x, w) + d (y, w) - d (x, y)\right).
$$
We use the definition of the Gromov product on two points with respect to a third to establish the four point condition and define
$$
f p _ {w} (d; x, y, z) := \max  _ {\pi \text {p e r m}} [ \min  (g p _ {w} (\pi x, \pi z), g p _ {w} (\pi y, \pi z)) - g p _ {w} (\pi x, \pi y) ]
$$
where the maximum is taken over all permutations  $\pi$  of the labels of the four points. Since  $fp_w(d;x,y,z) = fp_x(d;y,z,w) = fp_y(d;x,z,w) = fp_z(d;x,y,w)$ , we sometimes denote the four point condition as  $fp(d;x,y,z,w)$ . Similarly, we define the three point condition as
$$
t p (d; x, y, z) := \max  _ {\pi \text {p e r m}} [ d (\pi x, \pi z) - \max  (d (\pi x, \pi y), d (\pi y, \pi z)) ]
$$
which we use to define ultrametricity.
Following a standard definition of Gromov, a metric space  $(X,d)$  is said to be  $\delta$ -hyperbolic with respect to the base point  $w\in X$ , if for any  $x,y,z\in X$ , the following holds:
$$
g p _ {w} (x, y) \geq \min  \left(g p _ {w} (y, z), g p _ {w} (x, z)\right) - \delta .
$$
We denote  $\mathrm{Hyp}(d) = \delta$ , the usual hyperbolicity constant (similarly,  $\mathrm{UM}(d)$ , is the usual ultrametricity constant). We note that this measure of hyperbolicity is a worst case measure and, as such, it may give a distorted sense of the geometry of the space. A graph which consists of a tree and a single cycle, for instance, is quite different from a single cycle alone but with a worst case measure, we will not be able to distinguish between those two spaces.
In order to disambiguate different spaces, we define the hyperbolicity vector as the  $\ell$ -dimensional vector of all four point conditions with respect to  $d$ :
$$
\Delta_ {w} (d) = \left[ f p (d; x, y, z, w) \right] \text {f o r a l l} x, y, z \in \left( \begin{array}{c} X \\ 3 \end{array} \right).
$$
Similarly, we define the ultrametricity vector as the  $\ell$ -dimensional vector of all three point conditions with respect to  $d$ :
$$
\boldsymbol {\Delta} (d) = [ t p (d; x, y, z) ] \text {f o r a l l} x, y, z \in \left( \begin{array}{c} X \\ 3 \end{array} \right).
$$
We use the hyperbolicity and ultrametricity vectors to express more refined geometric notions.
We define  $p$ -average hyperbolicity and  $p$ -average ultrametricity.
$$
\operatorname {A v g H y p} _ {p} (d) = \left(\frac {1}{r} \sum_ {x, y, z, w \in \binom {X} {4}} f p (d; x, y, z, w) ^ {p}\right) ^ {1 / p} \text {a n d}
$$
$$
\operatorname {AvgUM}_{p}(d) = \left(\frac{1}{\ell}\sum_{x,y,z\in \binom {X}{3}  }tp(d;x,y,z)^{p}\right)^{1 / p}
$$
If  $p = 1$ , then the notions are simply the average (and we will call them so). Also, for clarity, note the usual hyperbolicity and ultrametricity constants  $\mathrm{Hyp}(d)$  and  $\mathrm{UM}(d)$  are the  $p = \infty$  case.
Proposition 2.1. We have the simple relations:
(a)  $\mathrm{Hyp}(d) = \max_{x\in X}\| \pmb{\Delta}_x(d)\|_\infty \geq \| \pmb{\Delta}_x(d)\|_\infty$  for any  $x\in X$
(b)  $\mathrm{UM}(d) = \| \pmb {\Delta}(d)\|_{\infty}$
In the discussion of hierarchical correlation clustering in Section 2.4 and in the analysis of our algorithms in Section 3, we construct multiple graphs using the points of  $X$  as vertices and derived edges. Of importance to our analysis is the following combinatorial object which consists of the set of bad triangles in a graph (i.e., those triples of vertices in the graph for which exactly two edges, rather than three, are in the edge set). Given a graph  $G = (V, E)$ , denote  $B(G)$ , the set of bad triangles in  $G$ , as
$$
B (G) := \left\{(x, y, z) \in \left( \begin{array}{c} V \\ 3 \end{array} \right) |   | \{(x, y), (y, z), (z, x) \} \cap E | = 2 \right\}.
$$
2.2 Problem formulation
First, we formulate the tree fitting problem. Given a finite, discrete metric space  $(X,d)$  and the distance  $d(x_{i},x_{j})$  between any two points  $x_{i},x_{j}\in X$ , find a tree metric  $(T,d_T)$  in which the points in  $X$  are among the nodes of the tree  $T$  and the tree distance  $d_{T}(x_{i},x_{j})$  is "close" to the original distance  $d(x_{i},x_{j})$ .
While there are many choices to measure how close  $d_{T}$  and  $d$  are, in this paper, we focus on the  $\ell_p$  error; i.e.,  $\| d_{T} - d\|_{p}$ , for  $1\leq p\leq \infty$ . This definition is itself a shorthand notation for the following. Order the pairs of points  $(x_{i},x_{j}),i < j$  lexicographically and write  $d$  (overloading the symbol  $d$ ) for the vector of pairwise distances  $d(x_i,x_j)$ . Then, we seek a tree distance function  $d_{T}$  whose vector of pairwise tree distances is close in  $\ell_p$  norm to the original vector of distances. For example, if  $p = \infty$  we wish to bound the maximum distortion between any pairs on  $X$ . If  $p = 1$ , we wish to bound the total error over all pairs. Similarly, we define the ultrametric fitting problem.
We also introduce the rooted tree fitting problem. Given a finite, discrete metric space  $(X,d)$  and the distance  $d(x_{i},x_{j})$  between any two points  $x_{i},x_{j}\in X$ , and a distinguished point  $w\in X$ , find a tree metric  $(T,d_T)$  such that  $\| d - d_T\| _p$  is small and  $d_{T}(w,x) = d(w,x)$  for all  $x\in X$ . Although the rooted tree fitting problem has more constraints, previous work (such as [7]) shows that by choosing the base point  $w$  appropriately, the optimal error of the rooted tree embedding is bounded by a constant times the optimal error of the tree embedding. Also, the rooted tree fitting problem is closely connected to the ultrametric fitting problem.
Putting these pieces together, we observe that while considerable attention has been paid to the  $\ell_q$  tree fitting problem for generic distances with only mild attention paid to the assumptions on the input distances. No one has considered both restrictions on the distances and more sophisticated measures of distortion. We define the  $\ell_p / \ell_q$  tree (ultrametric) fitting problem as follows.
Definition 2.2 ( $\ell_{\mathbf{p}} / \ell_{\mathbf{q}}$  tree (ultrametric) fitting problem). Given  $(X, d)$  with hyperbolicity vector  $\Delta_x(d)$  and  $\mathrm{AvgHyp}_q(d)$  (ultrametricity vector  $\Delta(d)$  and  $\mathrm{AvgUM}_q(d)$ ), find the tree metric  $(T, d_T)$  (ultrametric  $(X, d_U)$ ) with distortion
$$
\left\| d - d _ {T} \right\| _ {p} \leq \operatorname {A v g H y p} _ {q} (d) \cdot f (n) \text {o r} \left\| d - d _ {U} \right\| _ {p} \leq \operatorname {A v g U M} _ {q} (d) \cdot f (n)
$$
for a growth function  $f(n)$  that is as small as possible. (Indeed,  $f(n)$  might be simply a constant.)
2.3 Previous results
Next, we detail Gromov's classic theorem on tree fitting, using our notation above.
Theorem 2.3. [4] Given a  $\delta$ -hyperbolic metric space  $(X,d)$  and a reference point  $x\in X$ , there exists a tree structure  $T$  and its metric  $d_{T}$  such that
1.  $T$  is  $x$ -restricted, i.e.,  $d(x,y) = d_T(x,y)$  for all  $y \in X$ .
2.  $\| d - d_T\|_{\infty}\leq 2\| \pmb {\Delta}_x(d)\|_{\infty}\lceil \log_2(n - 2)\rceil$
In other words, we can bound the maximum distortion of tree metric in terms of the hyperbolicity constant  $\mathrm{Hyp}(d) = \delta$  and the size of our input space  $X$ .
2.4 (Hierarchical) Correlation clustering and ultrametric fitting
Several earlier works ([2], [12]) connected the correlation clustering problem to that of tree and ultrametric fitting and, in order to achieve our results, we do the same. In the correlation clustering problem, we are given a graph  $G = (V,E)$  whose edges are labeled “+” (similar) or “-” (different) and we seek a clustering of the vertices into two clusters so as to minimize the number of pairs incorrectly classified with respect to the input labeling. In other words, minimize the number of “-” edges within clusters plus the number of “+” edges between clusters. When the graph  $G$  is complete, correlation clustering is equivalent to the problem of finding an optimal ultrametric fit under the  $\ell_1$  norm when the input distances are restricted to the values of 1 and 2.
Hierarchical correlation clustering is a generalization of correlation clustering that is also implicitly connected to ultrametric and tree fitting (see [1], [2], [12], [13]). In this problem, we are given a set of non-negativeweights and a set of edge sets. We seek a partition of vertices that is both hierarchical and
minimizes the weighted sum of incorrectly classified pairs of vertices. It is a (weighted) combination of correlation clustering problems.
More precisely, given a graph  $G = (V,E)$  with  $k + 1$  edge sets  $G_{t} = (V,E_{t})$ , and  $k + 1$  weights  $\delta_t\geq 0$  for  $0\leq t\leq k$ , we seek a hierarchical partition  $P_{t}$  that minimizes the  $\ell_1$  objective function,  $\sum \delta_t|E_t\Delta E(P_t)|$ . It is hierarchical in that for each  $t$ ,  $P_{t}$  subdivides  $P_{t + 1}$ .
Chowdury, et al. [13] observed that the Single Linkage Hierarchical Clustering algorithm (SLHC) whose output can be modified to produce an ultrametric that is designed to fit a given metric satisfies a similar property to that of Gromov's tree fitting result. In this case, the distortion bound between the ultrametric and the input distances is a function of the ultrametricity of the metric space.
Theorem 2.4. Given  $(X,d)$  and the output of SLHC in the form of an ultrametric  $d_{U}$ , we have
$$
\left\| d - d _ {U} \right\| _ {\infty} \leq \left\| \boldsymbol {\Delta} (d) \right\| _ {\infty} \lceil \log_ {2} (n - 1) \rceil .
$$
2.5 Reductions and equivalent bounds
Finally, we articulate precisely how the tree and ultrametric fitting problems are related through the following reductions. We note that the proof of this theorem uses known techniques from [2] and [1] although the specific results are novel. First, an ultrametric fitting algorithm yields a tree fitting algorithm.
Theorem 2.5. Given  $1 \leq p < \infty$  and  $1 \leq q \leq \infty$ . Suppose we have an ultrametric fitting algorithm such that for any distance function  $d$  on  $X$  (with  $|X| = n$ ), the output  $d_U$  satisfies
$$
\| d - d _ {U} \| _ {p} \leq \operatorname {A v g U M} _ {q} (d) \cdot f (n) \text {f o r s o m e g r o w t h f u n c t i o n} f (n).
$$
Then there exists a tree fitting algorithm (using the above) such that given an input  $d$  on  $X$  (with  $|X| = n$ ), the output  $d_{T}$  satisfies
$$
\| d - d _ {T} \| _ {p} \leq 2 \left(\frac {n - 3}{n}\right) ^ {1 / q} \operatorname {A v g H y p} _ {q} (d) \cdot f (n) f o r s a m e g r o w t h f u n c t i o n f (n).
$$
Conversely, a tree fitting algorithm yields an ultrametric fitting algorithm. From which we conclude that both problems should have the same asymptotic bound, which justifies our problem formulation.
Theorem 2.6. Given  $1 \leq p < \infty$  and  $1 \leq q \leq \infty$ . Suppose that we have a tree fitting algorithm such that for any distance function  $d$  on  $X$  (with  $|X| = n$ ), the output  $d_{T}$  satisfies
$$
\| d - d _ {T} \| _ {p} \leq \operatorname {A v g H y p} _ {q} (d) \cdot f (n) \text {f o r s o m e g r o w t h f u n c t i o n} f (n).
$$
Then there exists an ultrametric fitting algorithm (using the above) such that given an input  $d$  on  $X$  (with  $|X| = n$ ), the output  $d_{T}$  satisfies
$$
\| d - d _ {U} \| _ {p} \leq 3 ^ {\frac {p - 1}{p}} \left(\frac {1}{4} + 2 ^ {q - 4}\right) ^ {1 / q} \cdot \operatorname {A v g U M} _ {q} (d) \cdot f (2 n) \text {f o r s a m e g r o w t h f u n c t i o n} f (n).
$$
Proofs of both theorems can be found in the Appendix 6.1 6.2.
3 Tree and ultrametric fitting: Algorithm and analysis
In this section, we present an algorithm for the  $p = q = 1$  ultrametric fitting problem. We also present the proof of upper bound and present an example that shows this bound is asymptotically tight (despite our empirical evidence to the contrary). Then, using our reduction from Section 2, we produce a tree fitting result.
3.1 HCC Problem
As we detailed in Section 2, correlation clustering is connected with tree and ultrametric fitting and in this section, we present a hierarchical correlation clustering (HCC) algorithm which bounds the number of disagreement edges by constant factor of number of bad triangles. We follow with a proposition that shows the connection between bad triangle objectives and the  $\ell_1$  ultrametricity vector.
Definition 3.1 (HCC with triangle objectives). Given a vertex set  $V$  and  $k + 1$  edge sets, set  $G_{t} = (V,E_{t})$  for  $0\leq t\leq k$ . The edge sets are hierarchical so that  $E_{t}\subseteq E_{t + 1}$  for each  $t$ . We seek a hierarchical partition  $P_{t}$  so that for each  $t$ ,  $P_{t}$  subdivides  $P_{t + 1}$  and the number of disagreement edges  $|E_t\Delta E(P_t)|$  is bounded by  $C\cdot |B(G_t)|$  (where  $B$  denotes the set of bad triangles) for some constant  $C > 0$ .
Note that this problem does not include the weight sequence  $\{\delta_t\}$ , as the desired output will also guarantee an upper bound on  $\sum \delta_t |E_t \Delta E(P_t)|$ , the usual  $\ell_1$  objective.
This proposition relates the  $\ell_1$  vector norm of  $\pmb{\Delta}(d)$ , the average ultrametricity of the distances, and the bad triangles in the derived graph. This result is why we adapt the hierarchical correlation clustering problem to include triangle objectives.
Proposition 3.2. Given distance function  $d$  on  $\binom{X}{2}$  (with  $|X| = n$ ) and  $s > 0$ , consider the  $s$ -neighbor graph  $G_{s} = (X, E_{s})$  where  $E_{s}$  denotes  $\{(x, y) \in \binom{X}{2} | d(x, y) \leq s\}$ . Then we have
$$
\| \boldsymbol {\Delta} (d) \| _ {1} = \ell \cdot \operatorname {A v g U M} (d) = \int_ {0} ^ {\infty} | B (G _ {s}) | d s.
$$
3.2 Main results
Our main contribution is that the HCCTRIANGLE algorithm detailed in Section 3.3 solves our modified HCC problem and its output partition behaves "reasonably" on every level. From this partition, we can construct a good ultrametric fit which we then leverage for a good (rooted) tree fit (using the reduction from Section 2.
Theorem 3.3. HCCTRIANGLE outputs a hierarchical partition  $P_{t}$  where  $|E_{t}\Delta E(P_{t})|\leq 4\cdot |B(G_{t})|$  holds for every  $0\leq t\leq \binom{n}{2} = k$ . Furthermore, the algorithm runs in time  $O(n^{2})$ .
By Proposition 3.2 and Theorem 3.3, we can find an ultrametric fit using the HCCTRIANGLE subroutine to cluster our points. This algorithm we refer to as HCCULTRAFIT. Using Theorem 3.3, we have following  $\ell_1$  bound.
Theorem 3.4. Given  $d$ , HCCULTRAFIT outputs an ultrametric  $d_U$  with  $\| d - d_U \|_1 \leq 4 \| \Delta \|_1 = 4\ell \cdot \mathrm{AvgUM}_1(d)$ . The algorithm runs in time  $O(n^2 \log n)$ .
In other words, HCCULTRAFIT solves the HCC Problem 3.1 with constant  $C = 4$ . The following proof shows why adapting HCCTRIANGLE as a subroutine is successful.
Proof of Theorem 3.4 from Theorem 3.3: Suppose the outputs of HCCTRIANGLE and HCCULTRAFIT are  $\{P_t\}$  and  $d_U$ , respectively. Denote  $d_i \coloneqq d(e_i)$  ( $d_0 = 0, d_{k+1} = \infty$ ) and, for any  $s > 0$ , set
$$
G _ {s} = \left(X, E _ {t}\right), P _ {s} = P _ {t} \text {f o r} d _ {t} \leq s <   d _ {t + 1}.
$$
Then, for any  $x,y\in \binom{X}{2}$ , we see that
$$
(x, y) \in E _ {s} \Delta E (P _ {s}) \quad \Longleftrightarrow \quad d (x, y) \leq s <   d _ {U} (x, y) \text {o r} d _ {U} (x, y) \leq s <   d (x, y).
$$
Again, we use the integral notion from Proposition 3.2. Every edge  $(x,y)$  will contribute  $|E_s\Delta E(P_s)|$  with amount exactly  $|d_U(x,y) - d(x,y)|$ . Then, by Theorem 3.3,
$$
\begin{array}{l} \left\| d - d _ {U} \right\| _ {1} = \int_ {0} ^ {\infty} \left| E _ {s} \Delta E (P _ {s}) \right| d s \\ \leq 4 \int_ {0} ^ {\infty} | B (G _ {s}) | d s = 4 \| \boldsymbol {\Delta} (d) \| _ {1}, \\ \end{array}
$$
as desired. Assuming that HCCTRIANGLE runs in time  $O(n^{2})$ , HCCULTRAFIT runs in time  $O(n^{2}\log n)$  as the initial step of sorting over all pairs is needed. Thus ends the proof.
By the reduction argument we discussed in Section 2, we can put all of these pieces together to conclude the following:
Theorem 3.5. Given  $(X,d)$ , we can find two tree fits with the following guarantees:
- Given a base point point  $x \in X$ , HCCROOTEDTREEFIT outputs a tree fit  $d_{T}$  with  $\| d - d_{T} \|_{1} \leq 8 \| \Delta_{x}(d) \|_{1}$ . The algorithm runs in  $O(n^{2} \log n)$ .
- There exists  $x \in X$  where  $\| \Delta_x(d) \|_1 \leq \binom{n-1}{3} \operatorname{AvgHyp}_1(d)$ . Therefore, given  $(X, d)$ , one can find a (rooted) tree metric  $d_T$  with  $\| d - d_T \|_1 \leq 8 \binom{n-1}{3} \operatorname{AvgHyp}_1(d)$  in time  $O(n^3 \log n)$ .
3.3 Algorithm and analysis