1. Introduction
Understanding the geometric properties of complex networks is a key issue in network analysis and geometry of graphs. One important such property is the negative curvature [27], causing the traffic between the vertices to pass through a relatively small core of the network – as if the shortest paths between them were curved inwards. It has been empirically observed, then formally proved [12], that such a phenomenon is related to the value of the Gromov hyperbolicity of the graph. In this paper, we propose exact and approximation algorithms to compute hyperbolicity of a graph and its relatives (the approximation algorithms can be applied to geodesic metric spaces as well).
A metric space is hyperbolic [3, 7, 24] if for any four points of , the two largest of the distance sums , , differ by at most . A graph endowed with its standard graphdistance is hyperbolic if the metric space is hyperbolic. In case of geodesic metric spaces and graphs, hyperbolicity can be defined in other equivalent ways, e.g., via thin or slim geodesic triangles. The hyperbolicity of a metric space is the smallest such that is hyperbolic. It can be viewed as a local measure of how close is to a tree: the smaller the hyperbolicity is, the closer the metrics of its point subspaces are close to treemetrics.
The study of hyperbolicity of graphs is motivated by the fact that many realworld graphs are treelike from a metric point of view [1, 2, 4] or have small hyperbolicity [26, 27, 30]. This is due to the fact that many of these graphs (including Internet application networks, web networks, collaboration networks, social networks, biological networks, and others) possess certain geometric and topological characteristics. Hence, for many applications, including the design of efficient algorithms (cf., e.g., [4, 9, 10, 11, 12, 13, 17, 20, 32]), it is useful to know an accurate approximation of the hyperbolicity of a graph .
Related work.
For an vertex graph , the definition of hyperbolicity directly implies a simple bruteforce algorithm to compute . This running time is too slow for computing the hyperbolicity of large graphs that occur in applications [1, 4, 5, 22]. On the theoretical side, it was shown that relying on matrix multiplication results, one can improve the upper bound on timecomplexity to [22]. Moreover, roughly quadratic lower bounds are known [5, 15, 22]. In practice, however, the best known algorithm still has an time worstcase bound but uses several clever tricks when compared to the bruteforce algorithm [4]. Based on empirical studies, an running time is claimed, where
is the number of edges in the graph. Furthermore, there are heuristics for computing the hyperbolicity of a given graph
[14], and there are investigations whether one can compute hyperbolicity in linear time when some graph parameters take small values [21, 16].Perhaps, it is interesting to notice that the first algorithms for testing graph hyperbolicity were designed for Cayley graphs of finitely generated groups (these are infinite vertextransitive graphs of uniformly bounded degrees). Gromov gave an algorithm to recognize Cayley graphs of hyperbolic groups and estimate the hyperbolicity constant . His algorithm is based on the theorem that in Cayley graphs, the hyperbolicity “propagates”, i.e., if balls of an appropriate fixed radius induce a hyperbolic space, then the whole space is hyperbolic for some (see [24], 6.6.F and [18]). Therefore, in order to check the hyperbolicity of a Cayley graph, it is enough to verify the hyperbolicity of a sufficiently big ball (all balls of a given radius in a Cayley graph are isomorphic to each other). For other algorithms deciding if the Cayley graph of a finitely generated group is hyperbolic, see [6, 28]. However, similar methods do not help when dealing with arbitrary graphs.
By a result of Gromov [24], if the fourpoint condition in the definition of hyperbolicity holds for a fixed basepoint and any triplet of , then the metric space is hyperbolic. This provides a factor 2 approximation of hyperbolicity of a metric space on points running in cubic time. Using fast algorithms for computing (max,min)matrix products, it was noticed in [22] that this 2approximation of hyperbolicity can be implemented in time. In the same paper, it was shown that any algorithm computing the hyperbolicity for a fixed basepoint in time would provide an algorithm for matrix multiplication faster than the existing ones. In [19], approximation algorithms are given to compute a approximation in time and a approximation in time. As a direct application of the characterization of hyperbolicity of graphs via a cop and robber game and dismantlability, [9] presents a simple constant factor approximation algorithm for hyperbolicity of running in optimal time. Its approximation ratio is huge (1569), however it is believed that its theoretical performance is much better and the factor of 1569 is mainly due to the use in the proof of the definition of hyperbolicity via linear isoperimetric inequality. This shows that the question of designing fast and (theoretically certified) accurate algorithms for approximating graph hyperbolicity is still an important and open question.
Our contribution.
In this paper, we tackle this open question and propose a very simple (and thus practical) factor 8 algorithm for approximating the hyperbolicity of an vertex graph running in optimal time. As in several previous algorithms, we assume that the input is the distance matrix of the graph . Our algorithm picks a basepoint , a BreadthFirstSearch tree rooted at , and considers only geodesic triangles of with one vertex at and two sides on . For all such sides in , it computes the maximum over all distances between the two preimages of the centers of the respective tripods. This maximum can be easily computed in time and provides an 8approximation for . If the graph is given by its adjacency list, then we show that can be computed in time and linear space. For geodesic spaces endowed with a geodesic spanning tree we show that the same relationships between and the hyperbolicity of hold, thus providing a new characterization of hyperbolicity. En passant, we show that any complete geodesic space always has such a geodesic spanning tree. Perhaps, it is surprising that hyperbolicity that is originally defined via quadruplets and can be 2approximated via triplets (i.e., via pointed hyperbolicity), can be finally defined and approximated only via pairs (and an arbitrary fixed BFStree). We hope that this new characterization can be useful in establishing that graphs and simplicial complexes occurring in geometry and in network analysis are hyperbolic.
The way is computed is closely related to how hyperbolicity is defined via slimness, thinness, and insize of its geodesic triangles. Similarly to the hyperbolicity , one can define slimness , thinness , and insize of a graph . As a direct consequence of our algorithm for approximating and the relationships between and , we obtain constant factor time algorithms for approximating these parameters. On the other hand, an exact computation, in polynomial time, of these geometric parameters has long stayed elusive. This is due to the fact that are defined as minima of some functions over all the geodesic triangles of , and that there may be exponentially many such triangles. In this paper we provide the first polynomial time algorithms for computing and . Namely, we show that the thinness and the insize of can be computed in time and the slimness of can be computed in time^{1}^{1}1The notation hides polyloglog factors.. However, we show that the minimum value of over all basepoints and all BFStrees cannot be approximated in polynomial time with a factor strictly better than 2 unless P = NP.
2. Gromov hyperbolicity and its relatives
2.1. Gromov hyperbolicity
Let be a metric space and . The Gromov product^{2}^{2}2Informally, can be viewed as half the detour you make, when going over to get from to of with respect to is A metric space is hyperbolic [24] for if for all . Equivalently, is hyperbolic if for any , the two largest of the sums , , differ by at most . A metric space is said to be hyperbolic with respect to a basepoint if for all .
Proposition 2.1.
Let be a metric space. An geodesic is a (continuous) map from the segment of to such that and for all A geodesic segment with endpoints and is the image of the map (when it is clear from the context, by a geodesic we mean a geodesic segment and we denote it by ). A metric space is geodesic if every pair of points in can be joined by a geodesic. A real tree (or an tree) [7, p.186] is a geodesic metric space such that

there is a unique geodesic joining each pair of points ;

if , then
Let be a geodesic metric space. A geodesic triangle with is the union of three geodesics connecting these points. A geodesic triangle is called slim if for any point on the side the distance from to is at most . Let be the point of located at distance from Then, is located at distance from because . Analogously, define the points and both located at distance from see Fig. 1 for an illustration. We define a tripod consisting of three solid segments and of lengths and respectively. The function mapping the vertices of to the respective leaves of extends uniquely to a function such that the restriction of on each side of is an isometry. This function maps the points and to the center of . Any other point of is the image of exactly two points of . A geodesic triangle is called thin if for all points implies The insize of is the diameter of the preimage of the center of the tripod . Below, we remind that the hyperbolicity of a geodesic space can be approximated by the maximum thinness and slimness of its geodesic triangles.
For a geodesic metric space , one can define the following parameters:

hyperbolicity

pointed hyperbolicity

slimness

thinness

insize
2.2. Hyperbolicity of graphs
All graphs occurring in this paper are undirected and connected, but not necessarily finite (in algorithmic results they will be supposed to be finite). For any two vertices the distance is the minimum number of edges in a path between and Let denote a shortest path connecting vertices and in ; we call a geodesic between and . The interval consists of all vertices on geodesics. There is a strong analogy between the metric properties of graphs and geodesic metric spaces, due to their uniform local structure. Any graph gives rise to a geodesic space (into which isometrically embeds) obtained by replacing each edge of by a segment isometric to with ends at and . is called a metric graph. Conversely, by [7, Proposition 8.45], any geodesic metric space is (3,1)quasiisometric to a graph . This graph is constructed in the following way: let be an open maximal packing of , i.e., for any (that exists by Zorn’s lemma). Then two points are adjacent in if and only if . Since hyperbolicity is preserved (up to a constant factor) by quasiisometries, this reduces the computation of hyperbolicity for geodesic spaces to the case of graphs.
The notions of geodesic triangles, insize, slim and thin triangles can also be defined in case of graphs with the single difference that for graphs, the center of the tripod is not necessarily the image of any vertex on the sides of For graphs, we “discretize” the notion of thin triangles in the following way. We say that a geodesic triangle of a graph is thin if for any and vertices and (, and are pairwise different), implies . A graph is thin, if all geodesic triangles in are thin. Given a geodesic triangle in , let and be the vertices of and , respectively, both at distance from . Similarly, one can define vertices and vertices see Fig. 1. The insize of is defined as . An interval is said to be thin if for all with The smallest for which all intervals of are thin is called the interval thinness of and denoted by . Denote also by , , , , and respectively the hyperbolicity, the pointed hyperbolicity with respect to a basepoint , the slimness, the thinness, and the insize of a graph .
3. Auxiliary results
We will need the following inequalities between , , , and . They are known to be true for all geodesic spaces (see [3, 7, 24, 23, 31]). We present graphtheoretic proofs in case of graphs for completeness (and due to slight modifications in their definitions for graphs).
Proposition 3.1.
, , , and .
The fact that is a result of Soto [31, Proposition II.20]. For our convenience, we reformulate and prove the other results in four lemmas, plus one auxiliary lemma.
Lemma 3.2.
.
Proof.
By the definitions of , , and , we need only to show that .
Let . Pick an arbitrary geodesic triangle of formed by shortest paths , , and . By induction on , we show that holds for every pair of vertices with . Let be the neighbor of on . Consider a geodesic triangle formed by shortest paths , and , where is an arbitrary shortest path connecting with . Since , we have , where . Now, for every pair of vertices with , holds by induction. For a pair with , holds since the insize of is at most (note that, if such and exist then ). Thus, we conclude that .
Let . Pick any geodesic triangle of formed by shortest paths , , and . Consider the vertices as defined in Subsection 2.2. It suffices to show that . Since , there is a vertex such that . If , then necessarily (as and are shortest paths) and hence . So, we may assume that belongs to . If , then . That is, , implying and . If , then , implying . Hence, and .
By symmetry, also for vertex , we can get or . Therefore, if , then must hold. Thus, . ∎
Lemma 3.3.
Let be a graph with and be arbitrary vertices of . Then, for every shortest path connecting with , holds.
Proof.
Consider in a geodesic triangle formed by and two arbitrary shortest paths and . Let be a vertex on at distance from . We have .
If , then . Therefore, . As , we get .
If , then . Therefore, . As , we get . ∎
Lemma 3.4.
and .
Proof.
Let . Pick a geodesic triangle of formed by shortest paths , , and . Pick also the vertices and Evidently, . We also have . That is, . Consequently, holds, implying .
To prove , where , consider a geodesic triangle formed by shortest paths , and and let be an arbitrary vertex from . Without loss of generality, suppose that . Since is on a shortest path between and , we have , i.e., By Lemma 3.3, ∎
Lemma 3.5.
.
Proof.
Let . Consider four vertices and assume without loss of generality that . Pick a geodesic triangle of formed by three arbitrary shortest paths , , and . Pick a geodesic triangle of formed by the shortest path and two arbitrary shortest paths .
Without loss of generality, assume that . Let and be respectively the vertices of and at distance from . Let be the vertex of at distance from . Since and , by the triangle inequality, we have:
This establishes the fourpoint condition for , and consequently . ∎
Lemma 3.6.
.
Proof.
Let be two arbitrary vertices of and let such that . Since , we have and consequently, . Thus . Let be any shortest path passing via and be two arbitrary shortest  and paths. Consider the geodesic triangle . We have . Hence, if is thin, then . That is, . If is slim, then there is a vertex such that . Necessarily, as well, implying . Thus, . ∎
4. Geodesic spanning trees
In this section, we prove that any complete geodesic metric space has a geodesic spanning tree rooted at any basepoint . We hope that this general result will be useful in other contexts. For graphs this is wellknown and simple, and such trees can be constructed in various ways, for example via BreadthFirstSearch. The existence of BFStrees in infinite graphs has been established by Polat [29, Lemma 3.6]. However for geodesic spaces this result seems to be new (and not completely trivial) and we consider it as one of the main results of the paper. A geodesic spanning tree rooted at a point (a GStree for short) of a geodesic space is a union of geodesics with one end at such that implies that . Then is the union of the images of the geodesics of and one can show that there exists a real tree such that any is the geodesic of . Finally recall that a metric space is called complete if every Cauchy sequence of has a limit in .
Theorem 4.1.
For any complete geodesic metric space and for any basepoint one can define a geodesic spanning tree rooted at and a real tree such that any is the unique geodesic of .
The first assertion of the theorem immediately follows from the following proposition:
Proposition 4.2.
For any complete geodesic metric space , for any pair of points one can define an geodesic such that for all and for all , we have .
Proof.
Let be a wellorder on . For any we define inductively two sets and for any :
We set .
Claim 1.
For all and for any ,

there exists an geodesic such that ,

there exists an geodesic such that ,

there exists an geodesic such that .
Proof.
We prove the claim by transfinite induction on the wellorder .
To (1): Assume that for any , there exists an geodesic such that . If (this happens in particular if is the least element of for ), then let be any geodesic. If there exists such that , then let .
Suppose now that and that for any , . Note that for , we have , and for any , .
Let . Note that is a closed subset of and that for any , . We define in two steps: we first define on and then we extend it to the whole segment .
For any , there exists a sequence such that for every , , . Set . For any , let and note that . Consequently,