Faster approximation algorithms for computing shortest cycles on weighted graphs

Given an $n$-vertex $m$-edge graph $G$ with non negative edge-weights, the girth of $G$ is the weight of a shortest cycle in $G$. For any graph $G$ with polynomially bounded integer weights, we present a deterministic algorithm that computes, in $\tilde{\cal O}(n^{5/3}+m)$-time, a cycle of weight at most twice the girth of $G$. Our approach combines some new insights on the previous approximation algorithms for this problem (Lingas and Lundell, IPL'09; Roditty and Tov, TALG'13) with Hitting Set based methods that are used for approximate distance oracles and date back from (Thorup and Zwick, JACM'05). Then, we turn our algorithm into a deterministic $(2+\varepsilon)$-approximation for graphs with arbitrary non negative edge-weights, at the price of a slightly worse running-time in $\tilde{\cal O}(n^{5/3}\log^{{\cal O}(1)}{(1/\varepsilon)}+m)$. Finally, if we insist in removing the dependency in the number $m$ of edges, we can transform our algorithms into an $\tilde{\cal O}(n^{5/3})$-time randomized $4$-approximation for the graphs with non negative edge-weights -- assuming the adjacency lists are sorted. Combined with the aforementioned Hitting Set based methods, this algorithm can be derandomized, thereby yielding an $\tilde{\cal O}(n^{5/3})$-time deterministic $4$-approximation for the graphs with polynomially bounded integer weights, and an $\tilde{\cal O}(n^{5/3}\log^{{\cal O}(1)}{(1/\varepsilon)})$-time deterministic $(4+\varepsilon)$-approximation for the graphs with non negative edge-weights. To the best of our knowledge, these are the first known subquadratic-time approximation algorithms for computing the girth of weighted graphs.


Introduction
The exciting program of "Hardness in P" aims at proving (under plausible complexity theoretic conjectures) the exact time-complexity of fundamental, polynomial-time solvable problems in computer science. As for graph problems, most papers in this area either deal with the dense case (m = Ω(n 2 ) edges) [2,26,29], or the sparse case (m = O(n) edges) [3,1,6]. -A finer-grained classification of such problems that depends on both n and m has been started only recently [4,18] -. In this paper, we consider the Girth problem on edge-weighted undirected graphs, for which almost all what is known in terms of finer-grained complexity only holds for the dense case. We recall that the girth of a given graph G is the minimum weight of a cycle in G -with the weight of a cycle being defined as the sum of the weights on its edges (see Sec. 2 for any undefined terminology in this introduction). Orlin and Sedeño-Noda showed that this parameter can be computed in O(nm)-time [20]. For dense graphs that is in O(n 3 ), and Vassilevska Williams and Williams [29] proved a bunch of combinatorial subcubic equivalences between Girth and other path and matrix problems. In particular, for every ε > 0, there cannot exist any combinatorial (4/3 − ε)-approximation algorithm for Girth that runs in truly subcubic time unless there exists a subcubic combinatorial algorithm for multiplying two boolean matrices. Roditty and Tov completed this above hardness result with anÕ(n 2 /ε)-time (4/3 + ε)-approximation algorithm [25], thereby essentially completing the picture for combinatorial algorithms on dense graphs.
However, the story does not end here for at least two reasons. The first one is that, as the graphs considered get sparser, the complexity for computing their girth falls down to O(n 2 ). In fact, when the edge-weights are integers bounded by some constant M , there is a non combinatorial algorithm for computing the girth of any n-vertex graph G in timeÕ(M n ω ) where ω stands for the the exponent of square matrix multiplication over a ring [26]. It is widely believed that ω = 2 [23], and if true, that would imply we can compute the exact value of the girth in quasi quadratic time -at least when edge-weights are bounded. So far, all the approximation algorithms for Girth on weighted graphs run inΩ(n 2 )-time. This leads us to the following, natural research question: Does there exist a subquadratic approximation algorithm for Girth on weighted graphs?
In this paper, we answer to this above question in the affirmative.

Our contributions
We present new approximation algorithms for the girth of graphs with non negative real edgeweights. These are the first algorithms to break the quadratic barrier for this problem -at the price of a slightly worse approximation factor compared to the state of the art [25]. Of particular importance is the subcase of graphs with positive integer weights, as we can reduce the general case to it. Our first result is obtained for the graphs with bounded integer edge-weights. Our starting point for Theorem 1 is a previous 2-approximation algorithm from Lingas and Lundell [19], that runs in quadratic time. Specifically, these two authors introduced anÕ(n log M )time procedure that takes as entry a specified vertex of the graph and needs to be applied to every vertex in order to obtain the desired 2-approximation of the girth. Inspired by the techniques used for approximate distance oracles [28] we informally modify their algorithm as follows. We only apply their procedure to the vertices in a random subset S: where each vertex is present with equal probability n −1/3 (we can derandomize our approach by using known techniques from the litterature [24]). Furthermore, for the vertices not in S, we rather apply a modified version of their procedure that is restricted to a small subgraph -induced by some ball of expected size O(n 1/3 ). A careful analysis shows this is a 2-approximation.
The reason why this above approach works is that, when we run the procedure of Lingas and Lundell at some arbitrary vertex s, it will always detect a short cycle if there is one passing close to s (but not necessarily passing through s itself). This nice property has been noticed and exploited for related algorithms on unweighted graphs [19]. However, we think we are the first to prove such a property in the weighted case. We note that one of the two algorithms proposed by Roditty and Tov in [25] also satisfies such a property. We did not find a way to exploit their algorithm in order to improve our approximation factor.
By using a considerably more complex machinery, we finally generalize Theorem 1 to the graphs with arbitrary non negative edge-weights -up to an additional polylogarithmic dependency in some error parameter ε in the complexity of the algorithm. This is the second main result of this paper: Theorem 2. For every ε > 0 and G = (V, E, w) with non negative edge-weights, we can compute a deterministic (2 + ε)-approximation for Girth in timeÕ(n 5/3 polylog1/ε + m).
Theorem 2 implies Theorem 1 for some ε = O(1/(M n)) sufficiently small. Nevertheless, we chose to present Theorem 1 first as the passing from bounded integer-weights to arbitrary weights is not straightforward. In [25], Roditty and Tov introduced a nice technique -that we partly reuse in this paper -in order to do just that. However, we face several new difficulties, not encountered in [25], due to the need to perform all the intermediate operations in subquadratic time. This leads us to an interesting side contribution of this work, namely, the design of an n O(1) -approximation algorithm for the girth.
Our algorithms are subquadratic in the size of the graph, but they may be quadratic in its order n if there are m = Θ(n 2 ) edges. By a celebrated result of Bondy and Simonovits, any unweighted graph with m ≥ 100ℓn 1+ 1 ℓ edges has girth at most 2ℓ [8], and so, we can always output a constant upper-bound on the girth of moderately dense graphs. It implies that the dependency on m can always be removed in the running-time of approximation algorithms for the girth of unweighted graphs. However, elementary arguments show this additional dependency in the number of edges to be necessary for weighted graphs, at least if we do not assume any particular order on the adjacency lists. For instance, given G = (V, E, w) with integer weights, add a fresh new vertex u / ∈ V and the edges vu, v ∈ V with (unit) weight w uv = 1. Then, the girth of this new graph G ′ is exactly 2 + w min where w min denotes the minimum edge-weight in G. Since any constantfactor approximation algorithm for computing w min essentially requires time Ω(m), so does any constant-factor approximation algorithm for the girth of weighted graphs.
However, one may ask what happens if we now assume sorted adjacency lists -a very natural and common assumption in the field. As our third main result in the paper, we show that in this case, the dependency on m can be removed: 2. If all edge-weights are non negative then, we can compute a randomized 4-approximation for Girth in timeÕ(n 5/3 ). For every ε > 0, we can also compute a deterministic (4 + ε)approximation for Girth in timeÕ(n 5/3 polylog1/ε).
We observe that even assuming sorted adjacency lists, it is not clear whether the algorithm of Theorem 1 can be implemented to run in timeÕ(n 5/3 polylogM ). Indeed, this algorithm requires to build several induced subgraphs in time roughly proportional to their size, that requires a different preprocessing on the adjacency lists. We prove that we do not need to construct these induced subgraphs entirely in order to derive a constant-factor approximation of the girth.
Similarly, for the graphs with non negative edge-weights we need to modify the algorithm of Theorem 2. In particular, we cannot use our polynomial-factor approximation algorithm for the girth directly, as it needs to enumerate all edges in the graph. We overcome this difficulty through the help of a classical density result for the C 4 -free unweighted graphs [10].

Related work
Approximation algorithms. Itai and Rodeh were the first to study the Girth problem for unweighted graphs [16]. Among other results, they showed how to compute an additive +1approximation of the girth in time O(n 2 ). This was later completed by Lingas and Lundell [19], who proposed a randomized quasi 2-approximation algorithm for this problem that runs in time O(n 3/2 √ log n). In [27], Roditty and Vassilevska Williams presented the first deterministic approximation algorithm for the girth of unweighted graphs. Specifically, they obtained a 2-approximation algorithm in timeÕ(n 5/3 ), and they conjectured that there does not exist any subquadratic (2 − ε)approximation for Girth. We obtain the same approximation factor for weighted graphs, and we almost match their running time up to polylog factors and to an additional term inÕ(m). It would be interesting to know whether in our case, this dependency on m can be removed while preserving the approximation factor 2. Very recently, new subquadratic-time approximation algorithms were proposed for Girth in unweighted graphs (see [14]). It is open whether one can achieve a constant-factor approximation for the girth in, say,Õ(n 1+o(1) )-time.
Much less is known about the girth of weighted graphs. The first known subcubic approximation was the one of Lingas and Lundell [19], that only applies to the graphs with bounded integer edgeweights. Their work somewhat generalizes the algorithm of Itai and Rodeh for unweighted graphs. The approximation factor was later improved to 4/3 by Roditty and Tov, still for the graphs with bounded integer weights, and to 4/3 + ε for the graphs with arbitrary weights [25]. Our algorithms in this paper are faster than these two previous algorithms, but they use the latter as a routine to be applied on several subgraphs of sublinear size. Therefore, the approximation factors that we obtain cannot outperform those obtained in [19,25].
More recently, a breakthrough logarithmic approximation of the girth of directed weighted graphs was obtained in [21].
FPT in P. A nascent branch of the "Hardness in P" program aims at obtaining faster exact algorithms for polynomial-time solvable problems assuming some parameter of the instance is bounded (e.g., see [3,15]). This has been done for Girth in [17] and (only for unweighted graphs) in [13], where the authors obtained quasi linear-time algorithms parameterized by treewidth and cliquewidth, respectively. We stress that a natural parameterization of the problem by the actual value of the girth does not look that promising, given that Triangle Detection in unweighted graphs is already a hard problem on its own.
Approximate distances. Finally, approximation algorithms for the girth are tightly related to the computation of approximate distances in weighted graphs. In a seminal paper [28], Thorup and Zwick showed that we can compute in expected time O(n 1/k m) an approximate distance oracle: that can answer any distance query in time O(k) with a multiplicative stretch at most 2k − 1. This has been improved in several follow-ups [7,11,22,24,30]. However, the construction of most oracles already takes (super)quadratic time for moderately dense graphs. Our key observation in this paper is that we do not need to construct these oracles entirely if we just want to approximate the girth. This allows us to avoid a great deal of distance computations, and so, to lower the running time.

Organization of the paper
We start gathering in Section 2 some known results from the literature that we will use for our algorithm. Then, in Section 3, we give some new insights on the algorithm of Lingas and Lundell [19] before presenting our main result (Theorem 1). Our algorithm is generalized to graphs with arbitrary weights in Section 4. Finally, we remove the dependency on the number of edges in the time complexity of our algorithms in Section 5. We conclude this paper with some open perspectives (Section 6).

Preliminaries
We refer to [9] for any undefined graph terminology. Graphs in this study are finite, simple (hence, without any loop nor multiple edges), connected and edge-weighted. Specifically, we denote a weighted graph by a triple G = (V, E, w) where w : E → R + is the edge-weight function of G. The weight of a subgraph H ⊆ G, denoted w(H) := e∈E(H) w e , is the sum of the weights on its edges. In particular, the girth of G is the minimum weight of a cycle in G. The distance dist G (u, v) between any two vertices u, v ∈ V is the minimum weight of an uv-path in G. By extension, for every v ∈ V and S ⊆ V we define dist G (v, S) := min u∈S dist G (u, v). -We will sometimes omit the subscript if no ambiguity on the graph G can occur. -For any v ∈ V and r ≥ 0, we also define the ball B G (v, r) := {u ∈ V | dist G (u, v) ≤ r}. Finally, an r-nearest set for v is any r-set N r (v) such that, for any x ∈ N r (v) and y / ∈ N r (v), we have dist G (v, x) ≤ dist G (v, y).
} be totally ordered. We call it a sorted adjacency list if edges incident to v are ordered by increasing weight, i.e., Q v = (vu 1 , vu 2 , . . . , vu dv ) and w vu i ≤ w vu i+1 for every i < d v . However, we call it an ordered adjacency list if, given some fixed total ordering ≺ over V the neighbours of v are ordered according to ≺ (i.e., u i ≺ u i+1 for every i < d v ). Throughout the rest of the paper we will assume that each vertex has access to two copies of its adjacency list: one being sorted and the other being ordered. The latter can always be ensured up to anÕ(m)-time preprocessing.

The Hitting Set method
We gather many well-known facts in the literature, that can be found, e.g., in [24,28,5,12]. All these facts are combined in order to prove the following useful result for our algorithms:

and for every
It is well-known that a set S as requested by Proposition 1 can be constructed randomly as follows: every vertex in V is added in S with equal probability n −1/3 [28]. We can compute such a set S deterministically by combining the following two lemmata: ). For every G = (V, E, w), v ∈ V and r ≥ 0, we can compute an r-nearest set for v in time O(r 2 ) (assuming sorted adjacency lists). Furthermore, all the vertices in this set can be labeled with their distance to v within the same amount of time.
. Given n sets of size r over a universe of size s, a set S of size O(n/r log n) hitting all n sets in at least one element can be found deterministically in time O(s + nr).
Proof of Proposition 1. Set r = n 1/3 . We compute an r-nearest set N r (v) for every vertex v ∈ V , that can be done in total time O(n * n 2/3 ) = O(n 5/3 ) by Lemma 1. By Lemma 2 (applied for s = n) we can compute in time O(n + n * n 1/3 ) = O(n 4/3 ) a set S of sizeÕ(n 2/3 ) that intersects all the nearest sets N r (v). Since, for every v ∈ V , we have B S (v) ⊆ N r (v) by construction, we can compute this ball in time O(r) simply by scanning the r-nearest set, and so, we can compute all the balls In what follows we will not only need the balls B S (v) for every vertex v, but also the subgraphs these balls induce in G. Next, we observe that all these subgraphs can be obtained almost for free. Namely: Proof. For every x, y ∈ U we search whether yx is present in the adjacency list of y. Since the adjacency lists are ordered, this can be done in time O(log n) by using a dichotomic search.

Case of graphs with bounded integer weights
This section is devoted to the proof of Theorem 1. We start presenting some new properties of a previous approximation algorithm for the girth of weighted graphs (Section 3.1) as we will need to use them in our own algorithm. Then, we prove our main result for graphs with bounded integer weights in Section 3.2.

Reporting a close short cycle
We propose a deeper analysis of an existing approximation algorithm for Girth on weighted graphs [19]. Roughly, this algorithm applies a same procedure to every vertex of the graph. In order to derive the approximation factor of their algorithm, the authors in [19] were considering a run that takes as entry some vertex on a shortest cycle. This is in contrast with the classical algorithm from Itai and Rodeh on unweighted graphs [16], that also offers provable guarantees on the length of the output assuming there is a shortest cycle passing close to the source (but not necessarily passing by this vertex); see [19,Lemma 2]. We revisit the analysis of the algorithm in [19] for weighted graphs, and we prove that this algorithm also satisfies such a "closeness property".
The HBD-algorithm from [19]. Given G = (V, E, w), s ∈ V and t ≥ 0, the algorithm HBD(G, s, t) is a relaxed version of Dijkstra's single-source shortest-path algorithm. We are only interested in computing the ball of radius t around s, and so, we stop if there is no more unvisited vertex at a distance ≤ t from s. Furthermore, whenever we visit a vertex u ∈ B G (s, t), we only relax edges e = {u, v} such that dist(s, u) + w e ≤ t. Then, a cycle is detected if we already inferred that dist(s, v) ≤ t (i.e., using another neighbour of v than u). Overall, the algorithm stops as soon as it encounters a cycle, or all the vertices in B G (s, t) were visited. Assuming sorted adjacency lists, each call to this algorithm runs inÕ(n)-time [19].
We now complete the analysis of the HBD-algorithm in order to derive a generalization of [19, Lemma 2] to weighted graphs. Assuming no cycle has been detected, we first gain more insights on the structure of the ball of radius t centered at s. Specifically, what the following lemma just says is that the set of all edges relaxed by the algorithm induces a spanning tree of the subgraph that is induced by B G (s, t).
Proof. Suppose for the sake of contradiction that there exist P 1 , and so, the edge x i j x i j+1 is relaxed. Overall, all the edges of E(P 1 ) ∪ E(P 2 ) are relaxed, and we claim that it contradicts our assumption that no cycle has been detected. Indeed, since P 1 , P 2 are different and they have the same ends, there exists a cycle C such that E(C) ⊆ E(P 1 ) ∪ E(P 2 ) (e.g., see [27,Lemma 2.5.]). Let e = xy ∈ E(C) be the last edge relaxed on the cycle. As x and y are each incident to other edges of E(C) that are already relaxed, we have at this step d(x) = ∞ and d(y) = ∞, thereby proving the claim.
Based on Lemma 5, we state some bounds on the weight of the cycle detected using HBD.
Proof. Fix x, y ∈ V (C) and partition the cycle C into the two xy-paths P 1 , P 2 . By the contrapositive of Lemma 5, a cycle is detected if t ≥ min{dist(s, x), dist(s, y)} + max{w(P 1 ), w(P 2 )}. Indeed, in this situation there exist two different paths of length ≤ t between s and one of x or y. In particular, set dist(s, x) = dist(s, C) and let y ∈ V (C)\{x} be arbitrary. We have t 0 ≤ dist(s, C)+ max{w(P 1 ), w(P 2 )} ≤ dist(s, C) + w(C).
We end up improving the bound of Corollary 1 in some particular cases of interest. The following refined upper-bound will play a key role in the analysis of our algorithm in the next sections.
. We can bipartition E(C) in two edge-disjoint xy-paths P 1 and P 2 , with P 1 being the xy-subpath passing by vz (and so, P 2 is the other xy-subpath passing by uy).

Subquadratic-time approximation
We are now ready to prove our first main result in this section. Proof. We analyse the following Subquadratic-Approx algorithm: such that: HBD(G, s, t) detects a cycle. 2: Let C s be the shortest cycle we so computed. 3: return C s .
The algorithm starts precomputing a set S ⊆ V and the open balls (B S (v)) v∈S as described in Proposition 1. This takes timeÕ(n 5/3 ), plus an additional preprocessing time inÕ(m) for sorting the adjacency lists. Then, we process the vertices in S and those in V \ S separately: • For every s ∈ S, we compute the smallest t s ∈ [3; M n] such that HBD(G, s, t s ) detects a cycle by using a dichotomic search (procedure Approx-Short-Close-Cycle(G, s, M )). We store the cycle C s outputted by HBD(G, s, t s ). Since each test we perform during the dichotomic search consists in a call to the HBD-algorithm, this takes timeÕ(n log M ) per vertex in S, and so,Õ(n|S| log M ) =Õ(n 5/3 log M ) in total.
• We now consider the vertices v ∈ V \ S sequentially. Let G ′ v be the subgraph of G induced by the open ball B S (v). By Lemma 3, this subgraph can be computed in timeÕ(|B S (v)| 2 ) = O(n 2/3 ) -assuming a preprocessing of the graph in time O(m) for ordering the adjacency lists. We apply the same procedure as for the vertices in S but, we restrict ourselves to the ball B S (v). That is, we call Approx-Short-Close-Cycle(G ′ v , v, M ), and we denote by C v the cycle outputted by this algorithm. Since we restrict ourselves to a subgraph of order O(n 1/3 ), this takes total timeÕ(n * (n 2/3 + n 1/3 log M )) =Õ(n 5/3 log M ).
Let C ∈ {C v | v ∈ V } be of minimum weight. We claim that w(C) is a 2-approximation of the girth of G, that will end proving the theorem. In order to prove this claim, we apply the following case analysis to some arbitrary shortest cycle C 0 of G.
• If V (C 0 ) ∩ S = ∅ then, let C S be a shortest cycle among {C s | s ∈ S}. We prove as a subclaim that w(C S ) is at most twice the weight of a shortest cycle intersecting S. In order to prove this subclaim, it suffices to prove that for every s ∈ S, we compute a cycle C s of weight no more than twice the weight of a shortest cycle passing by s. By Corollary 1, if t s is the smallest t such that HBD(G, s, t) detects a cycle then, a shortest cycle C passing by s must have weight ≥ t s . Furthermore, by Lemma 4 we get w(C s ) ≤ 2t s , thereby proving the subclaim. Thus, • From now on we assume V (C 0 ) ∩ S = ∅. Let v ∈ V (C 0 ) be arbitrary. There are two subcases: . This implies that we have: Furthermore, let s ∈ S minimize dist G (s, v). Then, by Corollary 2, the smallest t s such that HBD(G, s, t s ) detects a cycle satisfies t s ≤ w(C 0 ). As a result, by Lemma 4 Summarizing, w(C) ≤ 2w(C 0 ) in all the cases.

Generalization to unbounded weights
In [25], Roditty and Tov first proposed a 4/3-approximation for Girth in graphs with bounded integer weights. Then, they showed how to turn their algorithm into a (4/3 + ε)-approximation for graphs with arbitrary non negative real weights. We build on their approach in order to derive Theorem 2. In particular, we will use their main result as a subroutine: Theorem 4 ( [25]). For every G = (V, E, w) with arbitrary non negative edge-weights, we can compute a (4/3 + ε)-approximation for Girth in timeÕ(n 2 /ε).
The remaining of this section is divided into three parts. In Section 4.1, we reduce the general problem to the subcase of graphs with positive integer weights. Although strictly speaking, this part is not necessary in order to prove our results, it helps in simplifying some arguments and may be of independent interest for the further investigations on the girth. Furthermore, our reduction from non negative weights to positive weights is a gentle introduction to the technique that we exploit in the second part of this section for the design of a polynomial-factor approximation of the girth in subquadratic time. This part is new compared to [25] and the techniques used are interesting in their own right. Then, based on a clever technique from [25], we end up refining this rough estimate of the girth until we obtain a constant-factor approximation.

Reduction to positive integer weights
In what follows are some reductions from the graphs with arbitrary non negative real weights to the graphs with positive integer (unbounded) weights. First we assume all the weights to be positive (we will show how to deal with the edges of weight 0 at the end of this section). Recall that an (α, β)-approximation algorithm for the girth is one returning a cycle of weight no more than α · g * + β for any graph with girth ≤ g * . Our first observation is that since we are dealing with weighted graphs, given an (α, β)-approximation algorithm for the girth we can always scale the weights in order to obtain an (α + o(1))-approximation. Proof. Given G = (V, E, w), let w min := min{w e | e ∈ E} (computable in time O(m)). We multiply all the edge-weights by β/(3εw min ). In doing so, the girth must be at least g(G) ≥ 3 × β/(3ε) = (1/ε)β, and so, we have α · g(G) + β ≤ (α + ε)g(G).
In [14], Dahlgaard et al. presented various subquadratic (1 + ε, O(1))-approximation algorithms for the girth of unweighted graphs, for every ε > 0. We recall that 4/3 is, under some complexity theoretic assumptions, the best possible approximation factor that one can get using a subcubic combinatorial algorithm [25]. Therefore by Lemma 6 such combinatorial algorithms are unlikely to generalize to weighted graphs.
Another more straightforward consequence of Lemma 6 is that we can always assume the weights to be (possibly very large) integers. This might be useful for the further investigations on the girth. Proof. Replace every edge-weight w e , e ∈ E by ⌈w e ⌉. Since w e ≤ ⌈w e ⌉ ≤ w e + 1, the girth is increased by at most n. In particular, using an α-approximation algorithm for the graphs with integer weights, we output a cycle of weight at most α · g(G) + αn, with g(G) being the girth of G. We can use Lemma 6 in order to turn this result into an (α + ε)-approximation for every ε > 0.
Finally, we reduce the general case of graphs with non negative weights to the subcase of graphs with positive weights (and so, also to the subcase of graphs with positive integer weights). The technique that we use for that will be also used, in a more complicated way, in order to prove Proposition 2 in the next section. Proof. Let G = (V, E, w) with non negative real edge-weights, and let E 0 = {e ∈ E | w e = 0}. If the (unweighted) graph G 0 := (V, E 0 ) contains a cycle C, then w(C) = 0 is minimized and we can output C. Otherwise, G 0 is a forest, and let V 1 , V 2 , . . . , V p be its connected components. We consider the following three different cases: 1. First we scan all the edges in E \ E 0 in order to find, for any component V i , the minimum weight of an edge with its two ends in V i (if any). It takes time O(m). Furthermore, note that given e ∈ E \ E 0 with its two ends in V i , there is a cycle of weight exactly w e . Let C 0 be the minimum-weight cycle we so computed during this step.
2. In the same way, we can easily find a cycle C 1 of minimum weight that only intersects two components: for that, we scan all the edges in E \ E 0 in order to find, for any two distinct V i , V j , the at most two edges of minimum-weight with one end in V i and the other end in V j . It takes time O(m).

3.
We are now left with approximating the short cycles that intersect at least three components of G 0 . For that, let G ′ be obtained from G by contracting each component V j into one vertex; for every distinct V i , V j , if there exists an edge e ∈ E ∩ (V i × V j ) then, we choose e minimizing w e and we set w ′ v i v j = w e in G ′ . We observe that if there exists a shortest cycle C of G that intersects at least three components V j then, C ∩ V i is either empty or induces a path in G 0 [V i ] for every i (otherwise, there would be two vertices in V i that are connected in C by two subpaths of positive weight, and so, we could obtain a cycle of smaller weight than C by replacing any of these subpaths with any path in G 0 [V i ]). In particular, it corresponds to C a cycle C ′ in G ′ such that w(C ′ ) ≤ w(C). Conversely, to any cycle C ′ in G, it corresponds a cycle C in G such that w(C) ≤ w(C ′ ) (obtained by uncontracting the connected components of G 0 ). Let C ′ 2 be a cycle of weight at most α times the girth of G ′ , and let C 2 be a corresponding cycle in G.
Then, by outputting a cycle among C 0 , C 1 , C 2 that is of minimum weight, one obtains an αapproximation for the girth of G.

A polynomial-factor approximation.
We now obtain an approximation of the girth that only depends on the order of the graph. Since we consider weighted graphs, this is already a non trivial and interesting achievement. Proof. Let S be as in Proposition 1. We show a significantly more elaborate method that uses S in order to approximate the girth. We divide this method into five main steps.
Step 1: check the small balls. For every v / ∈ S, let G ′ v be the subgraph induced by the open ball B S (v). As before, we first estimate the girth of G ′ v . Since this subgraph has order O(n 1/3 ), by Theorem 4 we can compute a constant-factor approximation for its girth in timeÕ(n 2/3 ) (say, a 2-approximation). Overall, this step takes total timeÕ(n 5/3 ). Furthermore, after completing this step the following property (also used in Theorem 1) becomes true: Proof. This is trivial if v ∈ S. Otherwise by the hypothesis, , and so, we outputted a cycle of weight ≤ 2w(C v ) for this subgraph. ⋄ We will use Property 1 repeatedly throughout the next steps.
Step 2: partitioning into (shortest path) subtrees. Intuitively, what we try to do next is to approximate the weight of a shortest cycle passing close to S. The difference with Theorem 1 is that we cannot use directly the algorithm of Roditty and Tov for that. Indeed, their algorithm has some global steps (e.g., the approximate computation of the girth of some sparse spanner) that we currently do not know how to do in subquadratic time. So, we need to find some new techniques. Specifically, we partition the vertex-set V into shortest-path subtrees (T s ) s∈S such that, for every s ∈ S and v ∈ V (T s ) we have dist(v, s) = dist(v, S). As noted, e.g., in [28], a simple way to do that is to add a dummy vertex x S / ∈ V , edges sx S for every s ∈ S with weight 0, then to compute a shortest-path tree rooted at x S in timeÕ(m). See Fig. 3 for an example. In what follows, we show how to use this tree structure in order to compute short cycles. Step 3: finding short cycles in a subtree. Let s ∈ S be fixed. Informally, we try to estimate the weight of a shortest cycle in V (T s ). Note that every such a cycle has an edge that is not contained in T s . So, we consider all the edges e = uv such that u, v ∈ V (T s ) but e / ∈ E(T s ). Adding this edge in T s closes a cycle. Let C e,s be an (unknown) shortest cycle passing by e and contained in V (T s ). We output dist(s, u) + w e + dist(v, s) as a rough estimate of w(C e,s ). Indeed, the latter is a straightforward upper-bound on w(C e,s ), and this bound is reached if s ∈ {u, v}. Overall, this step takes total time O(m).

Property 2. Let C *
s be a shortest cycle contained in V (T s ). After Steps 1-3, we computed a cycle of weight ≤ 2w(C * s ). Proof. Let e = uv ∈ E(C * s ) \ E(T s ). We also define C u , C v shortest cycles passing by u and v, respectively. By Property 1, either we computed at Step 1 a cycle of weight ≤ 2w(C u ) ≤ 2w(C * s ) (a cycle of weight ≤ 2w(C v )) ≤ 2w(C * s ), resp.), or we know for sure that w(C * , s), resp.). In the latter case, dist(s, u) + w e + dist(v, s) is a 2-approximation of w(C * s ). ⋄ The proof for the next step is quite similar. The approximation factor we get is slightly worse, but it is still a constant.
Step 4: finding short cycles in two subtrees. We now want to estimate the weight of a shortest cycle in V (T s ) ∪ V (T s ′ ), for some distinct s, s ′ ∈ S. There are three cases: either (a) such a cycle is fully contained in V (T s ); or (b) it is fully contained in V (T s ′ ); or (c) it must contain two edges e, e ′ with an end in V (T s ) and the other end in V (T s ′ ). Cases (a) and (b) have already been considered at Step 3. So, we only consider Case (c), and we proceed as follows: 1. We scan all the edges e = uv ∈ E such that u and v are not in a same subtree. Let s u , s v ∈ S such that u ∈ V (T su ), v ∈ V (T sv ). We set ℓ(e) = dist(s u , u) + w e + dist(v, s v ).
2. Group all these above edges with their two ends in the same two subtrees. It takes time O(m + |S|) = O(m + n 2/3 ) by using, say, a linear-time sorting algorithm.
3. Finally, for every distinct s, s ′ ∈ S, let E(s, s ′ ) contain all the edges with one end in T s and the other end in T s ′ . If |E(s, s ′ )| ≥ 2 then, we pick e, e ′ minimizing ℓ(·) and we output ℓ(e) + ℓ(e ′ ).
Overall, since the sets E(s, s ′ ) partition the edges of G, this last phase also takes time O(m).
To prove correctness of this step, let s, s ′ ∈ S be distinct and fixed. We prove the following result: then, we are done by Property 2. Otherwise, let e = uv ′ , e ′ = vu ′ ∈ E(s, s ′ ) ∩ E(C * s,s ′ ) such that u, v ∈ V (T s ) and u ′ , v ′ ∈ V (T s ′ ). Choosing the uv-path in T s and the u ′ v ′ -path in T s ′ , one obtains that w(C * s,s ′ ) ≤ ℓ(e) + ℓ(e ′ ). Furthermore, let C u be a shortest cycle passing by u. By Property 1, either we computed at Step 1 a cycle of weight ≤ 2w(C u ) ≤ 2w(C * s,s ′ ), or we know for sure that w(C * s,s ′ ) ≥ w(C u ) ≥ 2dist(u, S) = 2dist(u, s). We obtain similar results for v, u ′ , v ′ . As a result, and unless we found a better estimate of the girth during Step 1, we have ℓ(e) + ℓ(e ′ ) ≤ 2w(C * s,s ′ ) + w e + w e ′ ≤ 3w(C * s,s ′ ). ⋄ Step 5: the general case. We end up defining a weighted graph H S = (S, E S , w S ), where: and for every ss ′ ∈ E S : We can construct H S simply by scanning all the sets E(s, s ′ ) (computed during Step 4). Overall, since the sets E(s, s ′ ) partition the edges of G, this takes total time O(m + |S|) = O(m + n 2/3 ). Furthermore, by Theorem 4 we can compute a constant-factor approximation of the girth of H S in timeÕ(|S| 2 ) =Õ(n 4/3 ).
The graph H S is not a subgraph of G. However, given a cycle C H for H S , we can compute a cycle C * H of G as follows. For every s ∈ V (C H ) let s ′ , s ′′ ∈ V (C H ) be its two neighbours. By construction, there exist e = uv ∈ E(s ′ , s) and e ′ = xy ∈ E(s, s ′′ ) such that the edges ss ′ and ss ′′ in H S have weights dist(s ′ , u) + w e + dist(v, s) and dist(s, x) + w e ′ + dist(y, s ′′ ), respectively. -We may assume the edges e, e ′ to be stored in H S so that s ′ , s ′′ will choose the same common edge with s. -Then, we replace s by the vx-path in T s . It is important to notice that, by construction, we have w(C * H ) ≤ w(C H ). In particular, we can apply this above transformation to the (approximately shortest) cycle of H S that has been outputted by the algorithm of Roditty and Tov (Theorem 4).
Overall, let C min be a shortest cycle computed by the algorithm above (i.e., after Steps 1-5). In order to finish the proof, we need to show that w(C min ) is anÕ(n 2/3 )-approximation of the girth of G. By Properties 2 and 3, this is the case if there exists a shortest cycle intersecting at most two subtrees T s , s ∈ S. From now on assume that any shortest cycle C 0 of G intersects at least three subtrees T s . Write C 0 = (v 0 , v 1 , . . . , v p−1 , v 0 ) and assume w.l.o.g. v 0 , v p−1 are not contained into the same subtree T s . We partition the v i 's into the maximal subpaths P 0 , P 1 , . . . , P q−1 , q ≤ p that are contained into the vertex-set of a same subtree T s (in particular, v 0 ∈ V (P 0 ) and v p−1 ∈ V (P q−1 )). Furthermore for every j ∈ {0, 1, . . . , q − 1} let s j ∈ S be such V (P j ) ⊆ V (T s j ), and let i j be the largest index such that v i j ∈ V (P j ). For instance, i q−1 = p − 1 by construction. Since P 0 = P q and q ≥ 3 by the hypothesis, there exist distinct indices j 1 , j 2 such that s j 1 = s j 2 +1 and for every j ∈ {j 1 , j 1 + 1, . . . , j 2 } the s j 's are pairwise different (indices are taken modulo q). Then, two cases may arise: • Case j 2 = j 1 + 1. We have: Furthermore, C 0 is clearly a shortest cycle passing by v i j 1 (by v i j 1 +1 , v i j 2 +1 , v i j 2 , respectively), and so, by Property 1, either we computed a short cycle of weight ≤ 2w(C 0 ) during Step 1, or we have w(C 0 ) ≥ 2 · max{dist(s j 1 , v i j 1 ), dist(s j 1 , v i j 2 +1 ), dist(s j 2 , v i j 1 +1 ), dist(s j 2 , v i j 2 )}. In the latter case, there exists a cycle of weight: that is fully contained in V (T s j 1 ) ∪ V (T s j 2 ). By Property 3, we so computed a cycle of weight ≤ 9w(C 0 ) at Step 4.
• From now on let us assume j 2 = j 1 + 1. For every j we have e j := v i j v i j +1 ∈ E(s j , s j+1 ), and so, the edge s j s j+1 ∈ E S has weight no more than dist(s j , v i j ) + w e j + dist(v i j +1 , s j+1 ) in H S (indices are taken modulo q for the s j 's and modulo p for the v i 's). Furthermore, C 0 is clearly a shortest cycle passing by v i j (by v i j +1 , respectively), and so, by Property 1, either we computed a short cycle of weight ≤ 2w(C 0 ) during Step 1, or we have w(C 0 ) ≥ 2·max{dist(s j , v i j ), dist(s j+1 , v i j +1 } for every j. In the latter case, (s j 1 , s j 1 +1 , . . . , s j 2 , s j 2 +1 = s j 1 ) is a cycle in H S of weight: Then, let C H be a cycle of H S such that w(C H ) =Õ(n 2/3 · w(C 0 )) (obtained by applying the algorithm of Roditty and Tov to H S ). As explained above, we can derive from C H a cycle C * H of G such that w(C * H ) ≤ w(C H ) =Õ(n 2/3 · w(C 0 )). Summarizing, we obtain anÕ(n 2/3 )-approximation of the girth by outputting a shortest cycle computed during Steps 1,3,4,5.

Improving the approximation factor
We can now conclude this section with its main result: Theorem 2. For every ε > 0 and G = (V, E, w) with non negative edge-weights, we can compute a deterministic (2 + ε)-approximation for Girth in timeÕ(n 5/3 polylog1/ε + m).
Let S be as in Proposition 1. For every v ∈ V \ S, we compute a 2-approximation of a shortest cycle in G ′ v : the subgraph of G induced by the ball B S (v). -In fact, this is already done in the proof of Proposition 2, but we restate it here for completeness of the method. -By Theorem 4, it can be done in timeÕ(n 2/3 ) for each v, and so, this takes total timeÕ(n 5/3 ).
Then, let For every s ∈ S, we compute the smallest t ∈ T such that HBD(G, s, t) detects a cycle (if any). It can be done in timeÕ(|S|n log |T |) =Õ(n 5/3 log 1/ε) by using a dichotomic search.
• Otherwise, let v ∈ V \ S be contained into C 0 . We may assume that V (C 0 ) ⊆ B S (v), since otherwise C 0 is a cycle in G ′ v , and so, we can already conclude that g min ≤ 2w(C 0 ). In particular, we have: Let s ∈ S be such that dist G (v, s) = dist G (v, S). By Corollary 2, this implies that the smallest t s such that HBD(G, s, t s ) detects a cycle satisfies t s ≤ w(C 0 ). Therefore, we can choose as above the smallest index i 0 such that w(C 0 ) ≤ (1 + ε/2) i 0 . As already noticed i 0 ∈ {i min , i min + 1, . . . , i max }, and by Corollary 2 we know that HBD(G, s, (1 + ε/2) i 0 ) detects a cycle. In this situation, we can conclude by Lemma 4 that g min ≤ 2(1 + ε/2) i 0 ≤ 2(1 + ε/2)w(C 0 ) ≤ (2 + ε)w(C 0 ).

A subquadratic algorithm for dense graphs
A drawback of the algorithms in Theorems 1 and 2 is that their time complexity also depends on the number m of edges. It implies that for dense graphs with m = Θ(n 2 ) edges we do not achieve any improvement on the running time compared to [19,25]. Assuming sorted adjacency lists, we now prove that the dependency on m can always be discarded: 2. If all edge-weights are non negative then, we can compute a randomized 4-approximation for Girth in timeÕ(n 5/3 ). For every ε > 0, we can also compute a deterministic (4 + ε)approximation for Girth in timeÕ(n 5/3 polylog1/ε).
Theorem 5 is obtained from a natural modification of the algorithm that we presented in Section 3.2. We postpone its proof to Section 5.2. Section 5.1 is devoted to a different approach for the problem: that combines the result of Theorem 2 with a well-known density result for unweighted graphs in order to derive either a randomized 4-approximation, or a deterministic c-approximation for some constant c > 4.
Informally we will use Proposition 3 as a replacement for Proposition 2 in the proof of Theorem 5. We think that our approach in this section could also be of independent interest. Our result combines Theorem 2 with the following well-known result in graph theory: Theorem 6 ( [10]). Every unweighted graph with order n and m ≥ 1 2 + o(1) n 3/2 edges contains a cycle of length four.
Proof of Proposition 3. If G has m =Õ(n 5/3 ) edges then, we can simply apply Theorem 2 for ε = 2 (the latter can be easily verified by scanning the adjacency lists until we read the end of it or we reach the desired upper-bound). From now on assume this is not the case and let H be induced by the 1 2 + o(1) n 3/2 edges of minimum weight in G. We claim that H can be constructed in timeÕ(n 3/2 ) by using a priority queue Q. Indeed, initially we set E(H) = ∅ and for every v ∈ V we start inserting in Q the edge of minimum-weight that is incident to v. This way, we ensure that a minimum-weight edge of G \ E(H) is present in Q (recall that initially, E(H) = ∅, and so, G = G \ E(H)). Then, in order to preserve this above invariant, each time a minimum-weight edge uv is extracted from Q and added in H we insert in Q the remaining edge of minimum weight in Q u and the one in Q v (if any). -Note that in doing so, a same edge can be added in Q twice, but this has no consequence on the algorithm. -We now apply Theorem 2 for ε ′ = ε/4 to H, and we so obtain a cycle C that is a (2 + ε/4)approximation of the girth of H. We claim that w(C) is also a (8 + ε)-approximation of the girth of G. In order to prove this claim, we need to consider two different cases: • Assume there exists a shortest cycle C 0 of G such that E(C 0 ) ⊆ E(H). By Theorem 2, w(C) ≤ (2 + ε/4)w(C 0 ) < (8 + ε)w(C 0 ).
• Otherwise, any shortest cycle C 0 of G has at least one edge that is not contained in H. Since edges are added by increasing weights, this implies that every such a shortest cycle contains an edge of weight at least w max . In particular, the girth of G is at least w max , where w max denotes the maximum-weight of an edge in H. Furthermore, since H has enough edges by construction, by Theorem 6 it contains a cycle of four vertices; the latter has weight at most 4w max . As a result, w(C) ≤ (2 + ε/4) · 4w max = (8 + ε)w max ≤ (8 + ε)w(C 0 ).
The above proves the claim, and so, the deterministic version of the result. In order to obtain a randomized 4-approximation, it suffices to pick ε ≤ 2 and to output any cycle C ′ of H with four vertices (then, we output any of C, C ′ that has minimum weight). Up to some constant multiplicative increase of the number of edges to add in H, this can be done by using a randomized algorithm of Yuster and Zwick that runs in expected linear time [31,Theorem 2.9]. Note that this is the only source of randomness in the algorithm.

Derandomization
We end up derandomizing the result of Proposition 3.
Proof of Theorem 5. It suffices to prove the result for the graphs with non negative edge-weights and ε > 0 arbitrary. To see that, let us consider any graph G with all edge-weights in {1, 2, . . . , M }.
If we take G as the input of our deterministic algorithm for the graphs with non negative edgeweights, setting ε = 1 M (n+1) , then, the cycle C of G that is outputted by the algorithm has total integer weight strictly upper-bounded by 1/ε. In particular, w(C) is in fact a 4-approximation of the girth of G. Thus, from now on we will only consider the more general case of graphs G with non negative edge-weights.
Let ε > 0 be fixed. The randomized version of the theorem was already proved in Proposition 3. For proving the deterministic version, we start computing a c-approximation g * of the girth of G, for some universal constant c > 4. By Proposition 3, it can be done in timeÕ(n 5/3 ). Observe that the girth of G is somewhere between g * /c and g * . Now, define η = ε/6. Let i min , i max be the smallest nonnegative integers such that g * /c ≤ (1+η) i min and in the same way 5g * ≤ (1+η) imax . We have i max − i min = O(1/ log (1 + η)) = O(1/ε). Furthermore, let T = {(1 + η) i | i min ≤ i ≤ i max }.
The remaining of the algorithm is essentially the same as for Theorem 2, except that we avoid the costly computation of the induced subgraphs G ′ v . Specifically, our processing of the vertices in the set S (given by Proposition 1) remains unchanged. However, for every v ∈ V \ S, we compute the smallest t ∈ T such that t < dist G (v, S) and HBD(G, s, t) detects a cycle (if any). In doing so, we can only visit the vertices in B S (v), and so, the total running time for processing v is upperbounded byÕ(|B S (v)|polylogM ), that is inÕ(n 1/3 polylogM ). Overall, this algorithm runs in total timeÕ(n 5/3 log T ), that is inÕ(n 5/3 log 1/ε).
Let C ∈ {C v | v ∈ V } be of minimum weight amongst all the cycles computed by the algorithm. We claim that w(C) is a (4 + ε)-approximation of the girth of G. In order to prove this claim, let C 0 be a shortest cycle of G. There are two cases.
We leave open whether a better approximation-factor than 4 can be obtained in o(n 2 )-time.

Open problems
The most pressing question is whether we can achieve a 4/3-approximation for the girth in subquadratic time. If it is not the case then, what is the best approximation factor we can get in subquadratic time? We note that in [27], Roditty and Vassilevska Williams conjectured that we cannot achieve a (2 − ε)-approximation already for unweighted graphs. If true then, this would imply our algorithm is essentially optimal (at least for the non dense graphs with O(n 2−ε ) edges).