SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Proof: Suppose the claim fails. As  $d(x_{1},y) + d(x_{2},y) - d(x_{1},x_{2}) = M + M - d(x_{1},x_{2})$ , it suggests that one of three pair distances should have distortion at least  $\frac{1}{3} (2M - 2c - d(x_1,x_2))$ . This should not happen if  $M - c\gg \mathrm{AvgHyp}_q(d')\cdot f(2n)$ .
We will interpret the above claim as a structural property. Given a tree  $T$  which realizes the tree metric  $d_{T}$ , one can find a Steiner node  $w$  on  $x_{1}, x_{2}, y$ . Then we have  $d_{T}(w, y) = \frac{1}{2} [d_{T}(x_{1}, y) + d_{T}(x_{2}, y) - d_{T}(x_{1}, x_{2})] \geq c$ . Since it holds for any  $x_{1}, x_{2} \in X$ , it suggests that every geodesic segment  $[x, y]$  for fixed  $y \in Y$  should share their paths at least  $c$ . This observation allows a following uniformization on  $Y$ .
Claim: One can refine a tree metric so that  $d_{T}(y_{1}, y_{2}) = c$  for all  $y_{1}, y_{2} \in Y$  with  $\ell_{p}$  error nonincreasing.
Algorithm 6 Refine a tree fit on  $Z = X \cup Y$
procedure UNIFORMIZATION ON  $Y$   
2: Input: tree fit  $(T, d_{T})$  on  $Z = X \cup Y$ ,  $1 \leq p < \infty$   
Output: refined tree  $(T', d_{T'})$  on  $Z$   
4:  $d_{T'}(x_{1}, x_{2}) \gets d_{T}(x_{1}, x_{2}) \forall x_{1} \neq x_{2} \in X$ $d_{T'}(y_{1}, y_{2}) \gets c \forall y_{1} \neq y_{2} \in Y$   
6: Find  $y_{0} = \operatorname{argmin}_{y \in Y} \sum_{x \in X} |d_{T}(x, y) - M|^{p}$ $d_{T'}(x, y) \gets d_{T}(x, y_{0}) \forall x \in X, y \in Y$   
8: return  $d_{T'}$
Proof: Pick  $y_0 = \operatorname*{argmin}_{y \in Y} \sum_{x \in X} |d_T(x, y) - d(x, y)|^p$ . Then we will keep  $X \cup \{y_0\}$  with its tree structure and relocate all other  $y \neq y_0 \in Y$ . As every geodesic segments will share their paths at least  $c$ , we will pick a point  $z$  with  $d_T(y, z) = c/2$  on the segment, and draw edge  $(z, y)$  for all  $y \in Y$  with length  $c/2$ . Then  $d_T(y_1, y_2) = c$  as desired. Furthermore, as  $d_{T'}(x, y) = d_T(x, y_0)$  for any  $x \in X$  and  $y \in Y$ ,
$$
\begin{array}{l} \left\| d _ {T ^ {\prime}} - d \right\| _ {p} ^ {p} \\ = \sum_ {z, w \in \left( \begin{array}{c} Z \\ 2 \end{array} \right)} | d _ {T ^ {\prime}} (z, w) - d (z, w) | ^ {p} \\ = \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} | d _ {T ^ {\prime}} (x, x ^ {\prime}) - d (x, x ^ {\prime}) | ^ {p} + \sum_ {x \in X, y \in Y} | d _ {T ^ {\prime}} (x, y) - M | ^ {p} + \sum_ {y, y ^ {\prime} \in \left( \begin{array}{c} Y \\ 2 \end{array} \right)} | d _ {T ^ {\prime}} (y, y ^ {\prime}) - c | ^ {p} \\ \leq \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} | d _ {T} (x, x ^ {\prime}) - d (x, x ^ {\prime}) | ^ {p} + \sum_ {x \in X, y \in Y} | d _ {T} (x, y _ {0}) - M | ^ {p} + \sum_ {y, y ^ {\prime} \in \left( \begin{array}{c} Y \\ 2 \end{array} \right)} 0 \\ = \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} | d _ {T} (x, x ^ {\prime}) - d (x, x ^ {\prime}) | ^ {p} + \sum_ {y \in Y} \sum_ {x \in X} | d _ {T} (x, y _ {0}) - M | ^ {p} \\ \leq \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} | d _ {T} (x, x ^ {\prime}) - d (x, x ^ {\prime}) | ^ {p} + \sum_ {y \in Y} \sum_ {x \in X} | d _ {T} (x, y) - M | ^ {p} \leq \| d _ {T} - d \| _ {p} ^ {p}, \\ \end{array}
$$
Algorithm 7 Construction of a restricted tree with respect to given root  $r$
procedure RESTRICTTREE   
2: Input: Tree fitting  $(T,d_{T})$  on  $Z$  Output: Tree fitting  $d_{T}$  such that  $d_{T}(x,y) = M$  for all  $x\in X$  and  $y\in Y$    
4: for each  $x\in X$  if  $d_{T}(x,y_{0}) > M$  ..   
6: Relocate  $x$  to point on geodesic  $[x,y_0]$  so that  $d_{T}(x,y_{0}) = M$  else if  $d_{T}(x,y_{0}) <   M$  ..   
8: Add edge  $(x,x^{\prime})$  with length  $M - d_{T}(x,y_{0})$  and relocate  $x$  to  $x^{\prime}$  return  $(T,d_{T})$
Claim: One can refine a tree metric so that  $d_{T'}(x, y) = M$  for all  $x \in X$  and  $y \in Y$  with  $\ell_p$  error not greater than  $3^{(p-1)/p}$  times the original error. Furthermore, if we restrict  $d_{T'}$  on  $X$ , then it is an ultrametric.
Proof: We will use the algorithm RestrictTree to obtain the restricted tree as described. It is clear that such procedure will successfully return a tree metric  $d_{T}$  with  $d_{T}(x,y) = M$  for all  $x\in X$  and  $y\in Y$ . Furthermore, as Denote  $\epsilon \coloneqq d_T - d$ . Then for any pair  $x_{1},x_{2}\in X$ , its distortion does not increase greater than  $|\epsilon (x_1,y_0)| + |\epsilon (x_2,y_0)|$ , which is the amount of relocation. We can utilize this
Figure 2: This figure depicts how RESTRICTTREE works. The idea is we can relocate every vertices so that  $d(x, y_0) = d_T(x, y_0)$  holds for every  $x \in X$ .
fact by
$$
\begin{array}{l} \| d_{T^{\prime}} - d\|_{p}^{p} = \sum_{z,w\in \bigl( \begin{array}{c}z\\ 2 \end{array} \bigr)}|d_{T^{\prime}}(z,w) - d(z,w)|^{p} \\ = \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} | d _ {T ^ {\prime}} (x, x ^ {\prime}) - d (x, x ^ {\prime}) | ^ {p} + \sum_ {x \in X, y \in Y} | d _ {T ^ {\prime}} (x, y) - M | ^ {p} + \sum_ {y, y ^ {\prime} \in \left( \begin{array}{c} Y \\ 2 \end{array} \right)} | d _ {T ^ {\prime}} (y, y ^ {\prime}) - c | ^ {p} \\ = \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} | d _ {T ^ {\prime}} (x, x ^ {\prime}) - d (x, x ^ {\prime}) | ^ {p} \\ \leq \sum_ {x, x ^ {\prime} \in \left( \begin{array}{c} X \\ 2 \end{array} \right)} (| \epsilon (x, y _ {0}) | + | \epsilon (x, x ^ {\prime}) | + | \epsilon (x ^ {\prime}, y _ {0}) |) ^ {p} \\ \leq 3^{p - 1}\sum_{x,x^{\prime}\in \binom {X}{2}}(|\epsilon (x,y_{0})|^{p} + |\epsilon (x,x^{\prime})|^{p} + |\epsilon (x^{\prime},y_{0})|^{p}) \\ \leq 3 ^ {p - 1} \left(\sum_ {x, x ^ {\prime} \in \binom {X} {2}} | \epsilon (x, x ^ {\prime}) | ^ {p} + (n - 1) \sum_ {x \in X} | \epsilon (x, y _ {0}) | ^ {p}\right) \\ \leq 3^{p - 1}\left(\sum_{x,x^{\prime}\in \binom {X}{2}}|\epsilon (x,x^{\prime})|^{p} + n\sum_{x\in X}|\epsilon (x,y_{0})|^{p}\right) = 3^{p - 1}\| d_{T} - d\|_{p}^{p}, \\ \end{array}
$$
as desired. Then by the restriction,  $d_{T}(x,y_{0}) = M$  holds for all  $x\in X$ . Therefore,
$$
t p \left(d _ {T ^ {\prime}}; x _ {1}, x _ {2}, x _ {3}\right) = f p \left(d _ {T ^ {\prime}}; x _ {1}, x _ {2}, x _ {3}, y _ {0}\right) = 0
$$
holds for all  $x_{1}, x_{2}, x_{3} \in \binom{X}{3}$ , which shows that  $d_{T'}$  on  $X$  is an ultrametric.
Denote the restricted metric as  $d_U$  (on  $\binom{X}{2}$ ). Then we have
$$
\begin{array}{l} \left\| d _ {U} - d \right\| _ {p} = \left\| d _ {T ^ {\prime \prime}} - d ^ {\prime} \right\| _ {p} \leq 3 ^ {\frac {p - 1}{p}} \left\| d _ {T ^ {\prime}} - d ^ {\prime} \right\| _ {p} \leq 3 ^ {\frac {p - 1}{p}} \left\| d _ {T} - d ^ {\prime} \right\| _ {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), \\ \end{array}
$$
6.3 Self-contained proof of ultrametric fit to rooted tree fit
Choose any base point  $w \in X$  and run HCCROOTEDTREEFIT. Note that  $d + c_w = 2(M - gp_w)$ . Then by 3.4, we see that the output  $d_T$  satisfies
$$
\left\| d - d _ {T} \right\| _ {1} \leq 8 \left\| \boldsymbol {\Delta} \left(d + c _ {w}\right) \right\| _ {1} = 8 \left\| \boldsymbol {\Delta} \left(M - g p _ {w}\right) \right\| _ {1} = 8 \left\| \boldsymbol {\Delta} _ {w} (d) \right\| _ {1}.
$$
Although  $\| \Delta_w(d)\| _1$  itself does not satisfy the guaranteed bound, we know that
$$
\begin{array}{l} \sum_{w\in X}\| \boldsymbol{\Delta}_{w}(d)\|_{1} = \sum_{w\in X}\sum_{\substack{x,y,z\in \left(^{X\setminus \{w\}}_{3}\right)}}fp_{w}(d;x,y,z) \\ = 4\sum_{x,y,z,w\in \binom {X}{4}}fp(d;x,y,z,w) = 4\binom {n}{4}\operatorname {AvgHyp}(d) \\ \end{array}
$$
so there exists an output  $d_{T}$  (with appropriately chosen  $w$ ) with its  $\ell_1$  error bounded by  $8 \cdot \frac{4}{n}\binom{n}{4}\operatorname{AvgHyp}(d) = 8\binom{n-1}{3}\operatorname{AvgHyp}(d)$ . As we need to check every base point  $w \in X$ , this procedure runs in time  $O(n^{3}\log n)$ .
6.4 Proof of Theorem 3.3
We begin by recalling the definition of highly connectedness.
Definition 6.1. Given a graph  $G = (V, E)$  and two disjoint vertex sets  $X$  and  $Y$ , the pair  $(X, Y)$  is said to be highly connected if both
$$
\text {f o r a l l} x \in X, | \{y \in Y | (x, y) \in E \} | \geq \frac {| Y |}{2}, \text {a n d}
$$
$$
\text {f o r a l l} y \in Y, | \{x \in X | (y, x) \in E \} | \geq \frac {| X |}{2}
$$
Our first lemma shows that every clusters should contain reasonably many edges "within", so that the number of "false positive" edges can be bounded. Because highly connectedness determines whether at least half of the edges have been connected, we can expect that the degree of every node should be at least half of the size of clusters.
Lemma 6.2. For any  $C \in P_t$  with  $|C| \geq 2$  and  $x \in C$ ,  $|\{x' \in C | (x, x') \in E_t\}| \geq \frac{|C|}{2}$ .
Proof. We use induction on  $t$ . The lemma is obviously true when  $t = 0$ . Next, suppose we pick  $C \in P_t$  with  $|C| \geq 2$  and the cluster  $C$  is formed at step  $t_0 \leq t$ . If  $t_0 < t$ , since  $P_t$  is increasing, it is clear that
$$
\left| \left\{x ^ {\prime} \in C \mid \left(x, x ^ {\prime}\right) \in E _ {t} \right\} \right| \geq \left| \left\{x ^ {\prime} \in C \mid \left(x, x ^ {\prime}\right) \in E _ {t _ {0}} \right\} \right| \geq \frac {| C |}{2} \quad \text {f o r a l l} x \in C.
$$
Therefore, it is enough to check when  $t_0 = t$ , i.e.,  $C$  is the newly added cluster at step  $t$ .
Suppose  $C$  is achieved by merging  $C = C_{a} \cup C_{b}$ . We then have two cases to check, depending on the sizes of  $C_{a}$  and  $C_{b}$ .
Case 1:  $|C_a| = 1$  or  $|C_b| = 1$ : Without loss of generality, assume that  $|C_a| = 1$  and let  $C_a = \{a\}$ . If  $C_b$  is also a singleton, then there is nothing to prove. If not, then, we must have  $(a, y) \in E_t$  for all  $y \in C_b$  in order to be highly connected. And by the induction hypothesis,
$$
\left| \left\{y ^ {\prime} \in C _ {b} \right| \left(y, y ^ {\prime}\right) \in E _ {t} \right\} \mid \geq \left| \left\{y ^ {\prime} \in C _ {b} \right| \left(y, y ^ {\prime}\right) \in E _ {t - 1} \right\} \mid \geq \frac {\left| C _ {b} \right|}{2} \quad \text {f o r a l l} y \in C _ {b}.
$$
$$
\left| \left\{y ^ {\prime} \in C \mid \left(a, y ^ {\prime}\right) \in E _ {t} \right\} \right| = \left| C _ {b} \right| = | C | - 1 \geq \frac {| C |}{2}
$$
and for all  $y \in C_b$
$$
\left| \left\{y ^ {\prime} \in C \mid \left(y, y ^ {\prime}\right) \in E _ {t} \right\} \right| = \left| \left\{y ^ {\prime} \in C _ {b} \mid \left(y, y ^ {\prime}\right) \in E _ {t} \right\} \right| + 1 \geq \frac {\left| C _ {b} \right|}{2} + 1 > \frac {| C |}{2},
$$
which completes the proof of Case 1.
Case 2:  $|C_{a}| > 1$  and  $|C_{b}| > 1$ : By the induction hypothesis, we have
$$
\left| \left\{x ^ {\prime} \in C _ {a} \right| \left(x, x ^ {\prime}\right) \in E _ {t} \right\} \mid \geq \left| \left\{x ^ {\prime} \in C _ {a} \right| \left(x, x ^ {\prime}\right) \in E _ {t - 1} \right\} \mid \geq \frac {\left| C _ {a} \right|}{2} \quad \text {f o r a l l} x \in C _ {a},
$$
and similarly for  $C_b$ . As  $C_a$  and  $C_b$  are both highly connected, we have
$$
\left| \left\{y ^ {\prime} \in C _ {b} \right| \left(x, y ^ {\prime}\right) \in E _ {t} \right\} \mid \geq \frac {\left| C _ {b} \right|}{2} \quad \text {f o r a l l} x \in C _ {a},
$$
$$
| \{x ^ {\prime} \in C _ {b} | (y, x ^ {\prime}) \in E _ {t} \} | \geq \frac {| C _ {a} |}{2} \quad \text {f o r a l l} y \in C _ {b}.
$$
Therefore, for any  $x \in C_a$ ,
$$
\begin{array}{l} \left| \left\{z ^ {\prime} \in C \mid \left(x, z ^ {\prime}\right) \in E _ {t} \right\} \right| = \left| \left\{x ^ {\prime} \in C _ {a} \mid \left(x, x ^ {\prime}\right) \in E _ {t} \right\} \right| + \left| \left\{y ^ {\prime} \in C _ {b} \mid \left(x, y ^ {\prime}\right) \in E _ {t} \right\} \right| \\ \geq \frac {\left| C _ {a} \right|}{2} + \frac {\left| C _ {b} \right|}{2} = \frac {\left| C \right|}{2}, \\ \end{array}
$$
while each inequality comes from the induction hypothesis and the connectivity condition. We can similarly show the property for any  $y \in C_b$ , which completes the proof of Case 2.
Next, we prove the following isoperimetric property:
Lemma 6.3. For  $C \in P_t$  denote  $\partial X := \{(x, y) \in E_t | x \in X, y \in C \setminus X\}$  for  $X \subset C$ . Then for any proper  $X$ ,
$$
| \partial X | \geq \frac {| C |}{2}.
$$
Proof. Without loss of generality, assume that  $1 \leq |X| \leq \frac{|C|}{2}$ . Then for any  $x \in X$ , by 6.2, there are at least  $\frac{|C|}{2} - |X| + 1$  edges which connects  $x$  and other vertices not in  $X$ . Therefore, we have
$$
\left| \partial X \right| \geq | X | \left(\frac {| C |}{2} - | X | + 1\right) \geq \frac {| C |}{2}.
$$
As our version of the HCC problem bounds the number of edges in disagreement in terms of the bad triangles, with the next lemmas, we count the number of bad triangles  $|B(G_t)|$  and bound the number of edges in disagreement. Recall that a bad triangle is defined as a triplet of edges in which only two of the three possible edges belong to  $E_t$ . For each cluster  $C \in P_t$ , denote the number of bad triangles inside  $C$  as  $T_C$ . And for each cluster pair  $C, C' \in P_t$ , we count some of the bad triangles between  $C$  and  $C'$  as  $T_{C,C'}$ . More precisely,
Definition 6.4. Given a partition  $P_{t}$ , denote
$$
T _ {C} := \left\{(x, y, z) \mid x, y, z \in C \text {a n d} (x, y, z) \in B \left(G _ {t}\right) \right\} \quad \text {f o r} C \in P _ {t},
$$
$$
\begin{array}{l} T _ {(C, C ^ {\prime})} := \{(x, x ^ {\prime}, y) | x, x ^ {\prime} \in C, y \in C ^ {\prime} \text {a n d} (x, x ^ {\prime}), (x, y) \in E _ {t}, (x ^ {\prime}, y) \notin E _ {t} \} \\ \cup \left\{\left(x, y, y ^ {\prime}\right) | x \in C, y, y ^ {\prime} \in C ^ {\prime} \text {a n d} \left(y, y ^ {\prime}\right), \left(x, y\right) \in E _ {t}, \left(x, y ^ {\prime}\right) \notin E _ {t} \right\} \quad \text {f o r} \left(C, C ^ {\prime}\right) \in \left( \begin{array}{c} P _ {t} \\ 2 \end{array} \right). \\ \end{array}
$$
Note that  $T_{C,C'}$  does not count every bad triangle between  $C$  and  $C'$ , as there might be bad triangles in which the missing edge is inside the cluster. With these definitions, we have
$$
\sum_ {C \in P _ {t}} | T _ {C} | + \sum_ {(C, C ^ {\prime}) \in \left( \begin{array}{c} P _ {t} \\ 2 \end{array} \right)} | T _ {(C, C ^ {\prime})} | \leq | B (G _ {t}) |.
$$
Proposition 6.5. For any cluster  $C \in P_t$ , the number of edges not in  $C$  is bounded by  $|T_C|$ . That is,
$$
| \{(x, y) \notin E | x, y \in C \} | \leq | T _ {C} |.
$$
(In fact, it is bounded by  $|T_C| / 2$ .)
Proof. We will prove that for any  $e = (x,y) \notin E_t$  with  $x,y \in C$ , there exist at least two elements in  $T_C$  that contain  $e$ , which implies our result. If  $|C| = 1$ , then there is nothing to prove. For any  $|C| \geq 2$  and  $(x,y) \notin E_t$ , by Lemma 6.2, there are at least  $\frac{|C|}{2}$  neighbors of  $x$  and  $y$  (we will denote each as  $N_x$  and  $N_y$ , respectively). Since  $N_x,N_y \subset C \setminus \{x,y\}$ , we have
$$
| N _ {x} \cap N _ {y} | = | N _ {x} | + | N _ {y} | - | N _ {x} \cup N _ {y} | \geq \frac {| C |}{2} + \frac {| C |}{2} - (| C | - 2) = 2.
$$
For any  $z \in N_x \cap N_y$ ,  $(x, y, z) \in T_C$  by definition, which proves the assertion.
Lemma 6.6. For  $G = (V, E)$  and two disjoint subsets  $X, Y \subset V$ , suppose
$$
\left| \left\{x ^ {\prime} \in X \mid \left(x, x ^ {\prime}\right) \in E \right\} \right| \geq \frac {| X |}{2} \text {f o r a l l} x \in X \text {a n d} \left| \left\{y ^ {\prime} \in Y \mid \left(y, y ^ {\prime}\right) \in E \right\} \right| \geq \frac {| Y |}{2} \text {f o r a l l} y \in Y.
$$
We will further assume that  $X$  and  $Y$  are not highly connected. Then we have
$$
\begin{array}{l} \left. \left| \{(x, y) \in E | x \in X, y \in Y \} \right| \leq 4 \cdot \left(\left| \{(x, x ^ {\prime}, y) | x, x ^ {\prime} \in X, y \in Y \text {a n d} (x, x ^ {\prime}), (x, y) \in E, \left(x ^ {\prime}, y\right) \notin E \right. \right. \right\rvert \\ + \left|\left\{\left(x, y, y ^ {\prime}\right) \mid x \in X, y, y ^ {\prime} \in Y \text {a n d} \left(y, y ^ {\prime}\right), (x, y) \in E, \left(x, y ^ {\prime}\right) \notin E \right\}\right|\left. \right. \\ \end{array}
$$
Proof. The key argument here is to use Lemma 6.3 and count the boundary sets. Define  $N_{Y}(x) \coloneqq \{y \in Y | (x, y) \in E\}$  for  $x \in X$  (and  $N_{X}(y)$  for  $y \in Y$  respectively.) Then for any  $(y, y') \in \partial N_{Y}(x)$ ,  $(x, y, y')$  is a bad triangle and it contributes the right hand side. In other words, the right hand side of the above equation is upper bounded by
$$
(\star) = 4 \cdot \left(\sum_ {x \in X} | \partial N _ {Y} (x) | + \sum_ {y \in Y} | \partial N _ {X} (y) |\right).
$$
By 6.3, we know that for  $N_{Y}(x)\neq \emptyset$  or  $Y$ ,  $|\partial N_Y(x)|\geq \frac{|Y|}{2}$ . We will count such  $x\in X$  and  $y\in Y$  which its neighbor set is proper, in order to make a lower bound. We divide the rest of the analysis into three cases:
Case 1: There exists  $x_0 \in X$  such that  $N_Y(x_0) = \emptyset$ : then for any  $y \in Y$ ,  $x_0 \notin N_X(y)$  so that  $N_X(y)$  cannot be  $X$ . Thus,  $N_X(y) \neq \emptyset$  immediately leads that  $|\partial N_X(y)| \geq \frac{|X|}{2}$ . We have
$$
\begin{array}{l} \left| \left\{\left(x, y\right) \in E \mid x \in X, y \in Y \right\} \right| \leq | X | \cdot \left| \left\{y \in Y \mid N _ {X} (y) \neq \emptyset \right\} \right| \\ \leq \sum_ {y \in Y, N _ {X} (y) \neq \emptyset} | X | \\ \leq 2\sum_{y\in Y,N_{X}(y)\neq \emptyset}|\partial N_{X}(y)| \\ \leq (\star) \leq \mathrm {R H S}, \\ \end{array}
$$
Case 2: There exists  $y_0 \in Y$  such that  $N_X(y_0) = \emptyset$ : this case is proven as we did in Case 1.
Case 3: For any  $x \in X$  and  $y \in Y$ ,  $N_{Y}(x) \neq \emptyset$  and  $N_{X}(y) \neq \emptyset$ , we will use the assumption that  $X$  and  $Y$  are not highly connected. With this assumption, we can also assume without loss of generality that there is an  $x_0 \in X$  such that  $|N_{Y}(x_{0})| < \frac{|Y|}{2}$ . Then for any  $y \notin N_{Y}(x_{0})$ ,  $N_{X}(y) \neq \emptyset$  and  $N_{X}(y) \neq X$  (as  $x_0 \notin N_X(y)$ ). Thus, the boundary set exists and has at
least  $\frac{|X|}{2}$  elements. Therefore,
$$
\begin{array}{l} \mathrm {R H S} \geq (\star) \geq 4 \sum_ {y \in Y} | \partial N _ {X} (y) | \\ \geq 4 \sum_ {y \in Y, y \notin N _ {Y} \left(x _ {0}\right)} | \partial N _ {X} (y) | \\ \geq 4 \sum_ {y \in Y, y \notin N _ {Y} (x _ {0})} \frac {| X |}{2} \\ = 4 \cdot \frac {| X |}{2} \cdot \left(| Y | - | N _ {Y} (x _ {0}) |\right) \\ > 4 \cdot \frac {| X |}{2} \cdot \frac {| Y |}{2} = | X | \cdot | Y | \geq \mathrm {L H S}. \\ \end{array}
$$
Proposition 6.7. For any cluster pair  $(C, C') \in P_t$ , the number of edges between  $C$  and  $C'$  is bounded by  $4|T_{(C,C')}|$ . (i.e.,  $|\{(x,y) \in E | x \in C, y \in C' \} | \leq 4|T_{(C,C')}|$ .)
Proof. Here, we will use an induction on  $t$ . When  $t = 0$ , then there is nothing to prove. Suppose the induction hypothesis holds for  $t_0 < t$ .
Case 1:  $e_t$  does not connect two vertices between  $C$  and  $C'$  and  $C, C'$  are not added at step  $t$ : then by induction hypothesis, the proposition holds at step  $t - 1$ , which is also true at step  $t$  (As the left hand side is invariant and  $|T_{(C, C')}|$  is increasing).
Case 2:  $e_t = (x, y)$  for  $x \in C$  and  $y \in C'$ : then it follows that our algorithm decided not to merge two clusters, which means  $C$  and  $C'$  are not highly connected. Then by Lemma 6.6, the number of edges is bounded by  $4|T_{(C,C')} |$  as desired.
Case 3:  $e_t$  does not connect two vertices between  $C$  and  $C'$ , but  $C$  or  $C'$  is newly formed at step  $t$ : note that both clusters cannot be generated at the same time, so we assume without loss of generality that  $C$  is the new cluster and assume it is generated by  $C = C_a \cup C_b$ . Then by the induction hypothesis, we have
$$
\begin{array}{l} \{(x, y) \in E | x \in C, y \in C ^ {\prime} \} | = \{(x, y) \in E | x \in C _ {a}, y \in C ^ {\prime} \} | + \{(x, y) \in E | x \in C _ {b}, y \in C ^ {\prime} \} | \\ \leq 4 \left(\left| T _ {\left(C _ {a}, C ^ {\prime}\right)} \right| + \left| T _ {\left(C _ {b}, C ^ {\prime}\right)} \right|\right) \quad (\text {b y}) \\ \leq 4 \left| T _ {\left(C, C ^ {\prime}\right)} \right|. \\ \end{array}
$$
We are now ready to prove Theorem 3.3.
Proof of Theorem 3.3: For  $P_{t} = \{C_{1},C_{2},\dots ,C_{k}\}$  , denote
$$
e _ {i} := | \{(x, x ^ {\prime}) \notin E | x, x ^ {\prime} \in C _ {i} \} |,
$$
$$
e _ {i, j} := | \{(x, y) \in E | x \in C _ {i}, y \in C _ {j} \} |.
$$
Then by the above propositions, we have
$$
\begin{array}{l} | E _ {t} \Delta E (P _ {t}) | = \sum_ {i} e _ {i} + \sum_ {i <   j} e _ {i, j} \\ \leq \sum_ {i} T _ {C _ {i}} + \sum_ {i <   j} 4 T _ {(C _ {i}, C _ {j})} \\ \leq 4 \left(\sum_ {i} T _ {C _ {i}} + \sum_ {i <   j} T _ {(C _ {i}, C _ {j})}\right) \leq 4 \cdot | B (G _ {t}) |. \\ \end{array}
$$
6.5 Implementation details
To detail our implementation, we will introduce the following variables.
For  $x \in X$  and cluster  $C$ , denote  $D(x, C) := |\{y \in C | (x, y) \in E\}|$ . We further denote the connectivity condition  $H(x, C)$  as  $\mathrm{IF}(D(x, C) \geq \frac{|C|}{2})$ .
Also for given two clusters  $C_a$  and  $C_b$ , we will denote  $M(C_a, C_b) := |\{x \in C_a | H(x, C_b) = 1\}|$ .
We can easily check that two disjoint clusters  $C_a$  and  $C_b$  are highly connected if and only if
$$
M \left(C _ {a}, C _ {b}\right) + M \left(C _ {b}, C _ {a}\right) = \left| C _ {a} \right| + \left| C _ {b} \right|.
$$
Algorithm 8 HCCTRIANGLE: Actual Implementation
function HCCTRIANGLE   
Input:  $X = \{x_{1},\dots ,x_{n}\} ,\{e_{t}\}$    
Initialize  $D,H,M$  as 0 for vertex set  $X$    
Initialize  $\mathcal{P} = \{\{x_1\} ,\{x_2\} ,\dots ,\{x_n\} \} ,\mathcal{E} = \emptyset$    
For  $t\in \{1,2,\dots ,(^n)_2\}$ : Take  $e_t = (x,y)$  with  $x\in C_a$  and  $y\in C_b$  ( $C_a,C_b\in \mathcal{P}$ ) Add  $D(x,C_b),D(y,C_a)$  by 1 Update  $H(x,C_b)$  and  $H(y,C_a)$  If  $H$  has been updated, update  $M(C_a,C_b)$  and  $M(C_b,C_a)$  accordingly If  $C_a\neq C_b$  and  $M(C_a,C_b) + M(C_b,C_a) = |C_a| + |C_b|$ : Remove  $C_a,C_b$  and add  $C_{new}\coloneqq C_a\cup C_b$  in  $\mathcal{P}$ $D(:,C_{new})\gets D(:,C_a) + D(:,C_b)$  Compute  $H(:,C_{new})$  and  $M(:,C_{new})$  (by using  $D(:,C_{new})$  )  $M(C_{new},:) \leftarrow M(C_a,:) + M(C_b,:)$ $P_{t}\gets \mathcal{P}$    
return  $\{P_t\}$
One can observe that an iteration only takes  $O(1)$  when  $C_a$  and  $C_b$  are not merged. When we merge  $C_{new}$ , we need time  $O(n)$  to compute new information of  $C_{new}$ . Since such events occur exactly  $n - 1$  times, we can conclude that HCCTRIANGLE overall runs in time  $O(n^2)$ .
6.6 Asymptotic tightness of Gromov's distortion bound
While it is well-known that Gromov's result is asymptotically tight, we give a self-contained sketch of the proof and provide an example that witnesses the bound. We detail the construction given by [17]. Consider the Poincaré disk  $\mathbb{H}^2$  and its hyperbolic  $n = 4m$ -gon  $H_{n,r}$  as a set of equally spaced  $n$  points around the circle of radius  $r$  in  $\mathbb{H}^2$ . Label all the points as  $x_1, x_2, \ldots, x_{4m}$ , in the counterclockwise order, and define  $y = x_{3m}$ . Suppose  $d_T$  is a tree metric fit to  $d$  and denote the Gromov product with respect to  $y$  as  $g p_y$ . Then
$$
\begin{array}{l} g p _ {y} (x _ {0}, x _ {2 m}) \geq \min  (g p _ {y} (x _ {0}, x _ {1}), g p _ {y} (x _ {1}, x _ {2 m})) \geq \min  (g p _ {y} (x _ {0}, x _ {1}), \min  (g p _ {y} (x _ {1}, x _ {2}), g p _ {y} (x _ {2}, x _ {2 m})) \\ \geq \dots \\ \geq \min  _ {i \in \{0, 1, \dots , 2 m - 1 \}} g p _ {y} (x _ {i}, x _ {i + 1}). \\ \end{array}
$$
Therefore there exists an  $i$  such that
$$
d _ {T} (x _ {i}, y) + d _ {T} (x _ {i + 1}, y) - d _ {T} (x _ {i}, x _ {i + 1}) \leq d _ {T} (x _ {0}, y) + d _ {T} (x _ {2 m}, y) - d _ {T} (x _ {0}, x _ {2 m}).
$$