Abstract 1 Introduction 2 Overview 3 Preliminaries 4 A new cycle searching technique 5 A πŸβ’π’Œ-hybrid algorithm and a (+𝟏)-approximation of the girth 6 A general hybrid algorithm 7 Approximation of the girth References

New Algorithms for Girth and Cycle Detection

Liam Roditty ORCID Department of Computer Science, Bar-Ilan University, Ramat-Gan, Israel    Plia Trabelsi ORCID Department of Computer Science, Bar-Ilan University, Ramat-Gan, Israel
Abstract

Let G=(V,E) be an unweighted undirected graph with n vertices and m edges. Let g be the girth of G, that is, the length of a shortest cycle in G. We present a randomized algorithm with a running time of O~⁒(β„“β‹…n1+1β„“βˆ’Ξ΅) that returns a cycle of length at most 2β’β„“β’βŒˆg2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹, where β„“β‰₯2 is an integer and Ρ∈[0,1], for every graph with g=polylog⁒(n).

Our algorithm generalizes an algorithm of Kadria et al. [SODA’22] that computes a cycle of length at most 4⁒⌈g2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹ in O~⁒(n1+12βˆ’Ξ΅) time. Kadria et al. presented also an algorithm that finds a cycle of length at most 2β’β„“β’βŒˆg2βŒ‰ in O~⁒(n1+1β„“) time, where β„“ must be an integer. Our algorithm generalizes this algorithm, as well, by replacing the integer parameter β„“ in the running time exponent with a real-valued parameter β„“βˆ’Ξ΅, thereby offering greater flexibility in parameter selection and enabling a broader spectrum of combinations between running times and cycle lengths.

We also show that for sparse graphs a better tradeoff is possible, by presenting an O~⁒(β„“β‹…m1+1β„“βˆ’Ξ΅) time randomized algorithm that returns a cycle of length at most 2⁒ℓ⁒(⌊gβˆ’12βŒ‹)βˆ’2⁒(⌊Ρ⁒⌊gβˆ’12βŒ‹βŒ‹+1), where β„“β‰₯3 is an integer and Ρ∈[0,1), for every graph with g=polylog⁒(n).

To obtain our algorithms we develop several techniques and introduce a formal definition of hybrid cycle detection algorithms. Both may prove useful in broader contexts, including other cycle detection and approximation problems. Among our techniques is a new cycle searching technique, in which we search for a cycle from a given vertex and possibly all its neighbors in linear time. Using this technique together with more ideas we develop two hybrid algorithms. The first allows us to obtain an O~⁒(m2βˆ’2⌈g/2βŒ‰+1)-time, (+1)-approximation of g. The second is used to obtain our O~⁒(β„“β‹…n1+1β„“βˆ’Ξ΅)-time and O~⁒(β„“β‹…m1+1β„“βˆ’Ξ΅)-time approximation algorithms.

Keywords and phrases:
Graph algorithms, All pairs shortest path, Girth, Cycle approximation
Funding:
Liam Roditty: Supported in part by BSF grants 2016365 and 2020356.
Copyright and License:
[Uncaptioned image] © Liam Roditty and Plia Trabelsi; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation β†’ Graph algorithms analysis
Related Version:
Full Version: https://arxiv.org/abs/2507.02061 [10]
Editor:
Pierre Fraigniaud

1 Introduction

Let G=(V,E) be an unweighted undirected graph with n vertices and m edges. A set of vertices Cβ„“={v1,v2,β‹―,vβ„“+1} in G, where β„“β‰₯2, is a cycle of length β„“ if v1=vβ„“+1 and (vi,vi+1)∈E, for every 1≀i≀ℓ. A C≀ℓ is a cycle of length at most β„“. The girth g of G is the length of a shortest cycle in G. The girth of a graph has been studied extensively since the 1970s by researchers from both the graph theory and the algorithms communities.

Itai and Rodeh [6] showed that the girth can be computed in O⁒(m⁒n) time or in O⁒(nΟ‰) time, where Ο‰<2.371552 [16], if Fast Matrix Multiplication (FMM) algorithms are used. They also proved that the problem of computing the girth is equivalent to the problem of deciding whether there is a C3 (triangle) in a graph or not.

In practice, algorithms for FMM have very large constant factors in their running time. Combinatorial algorithms, informally, are algorithms which do not use algebraic methods that are being used by FMM algorithms, and consequently are often more practical. Vassilevska W. and Williams [15] showed that if there exists a truly subcubic time combinatorial algorithm which detects if a graph has a triangle (and therefore also a subcubic time algorithm that computes the exact girth), then there exists a truly subcubic time combinatorial algorithm for Boolean Matrix Multiplication (BMM) (and therefore also for unweighted All Pairs Shortest Path (APSP), see [5], [13], [14]). Such an algorithm would be a major breakthrough. As a result, to get a faster running time for computing the girth, it is natural to settle for an approximation algorithm for the girth instead of an exact computation. An (Ξ±,Ξ²)-approximation g^ of g (where Ξ±β‰₯1 and Ξ²β‰₯0), satisfies g≀g^≀α⋅g+Ξ². We denote an approximation as an Ξ±-approximation if Ξ²=0 and as a (+Ξ²)-approximation if Ξ±=1.

Itai and Rodeh [6] presented a (+1)-approximation algorithm that runs in O⁒(n2) time. Notice that in contrast to the BMM or APSP problems, where a running time of Ω⁒(n2) is inevitable since the output size is Ω⁒(n2), in the girth problem the output is a single number, thus, there is no natural barrier for subquadratic time algorithms. Indeed, Lingas and Lundell [8] presented a 83-approximation algorithm that runs in O~⁒(n3/2) time, and Roditty and V. Williams [12] presented a 2-approximation algorithm that runs in O~⁒(n5/3) time. Dahlgaard, Knudsen and StΓΆckel [4] presented two tradeoffs between running time and approximation. One generalizes the algorithms of [8, 12] and computes a cycle of length at most 2⁒⌈g2βŒ‰+2⁒⌈g2⁒(β„“βˆ’1)βŒ‰ in O~⁒(n2βˆ’1/β„“) time. The other computes, whp, a C≀2ℓ⁒g, for any integer β„“β‰₯2, in O~⁒(n1+1/β„“) time.

Kadria et al. [7] significantly improved upon the second algorithm of [4] and presented an algorithm, that for every integer β„“β‰₯1, computes a C≀2β’β„“β’βŒˆg/2βŒ‰ in O~⁒(n1+1/β„“) time. They also presented an algorithm, that for every Ρ∈(0,1), computes a cycle of length at most 4⁒⌈g2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹β‰€(2βˆ’Ξ΅)⁒g+4, in O~⁒(n1+1/(2βˆ’Ξ΅)) time, for every graph with g=polylog⁒(n).

These two algorithms of Kadria et al., as well as few other approximation algorithms (see for example, [8], [2], [9]), were obtained using a general framework for girth approximation in which a search is performed over the range of possible values of g, using some algorithm π’œ that gets as an input an integer g~ which is a guess for the value of g. In each step of the search π’œ either returns a cycle C≀f⁒(g~), where f is a non decreasing function, or determines that g>g~. The goal of the search is to find the smallest g~, for which π’œ returns a cycle, because for this value we have g>g~βˆ’1 (and thus gβ‰₯g~), and algorithm π’œ returns a C≀f⁒(g~). This cycle is of length at most f⁒(g) since gβ‰₯g~ and f is a non decreasing function (f can represent the approximation, for example f⁒(g~)=2⁒g~ yields a 2-approximation). The two possible outcomes of π’œ and its usage in the general girth approximation framework inspired us to formally define the notion of a (Ξ³,Ξ΄)-hybrid algorithm as follows:

Definition 1.

A (Ξ³,Ξ΄)-hybrid algorithm is an algorithm that either outputs a C≀γ or determines that g>Ξ΄.

When Ξ³=Ξ΄, the algorithm is referred to as a Ξ³-hybrid algorithm. The girth approximation framework described above suggests that a possible approach for developing efficient girth approximation algorithms is by developing efficient (Ξ³,Ξ΄)-hybrid algorithms.

Kadria et al. [7] designed several algorithms that satisfy the definition of (Ξ³,Ξ΄)-hybrid algorithms. Their girth approximation algorithms mentioned above were obtained using two different (f⁒(g~),g~)-hybrid algorithms. Additionally, for every integer kβ‰₯2, they presented a (2⁒k,3)-hybrid and a (2⁒k,4)-hybrid algorithms that run in O⁒(min⁑{m1+1/(k+1),n1+2/k}) time, and a (max⁑{2⁒k,g},5)-hybrid algorithm that runs in O⁒(min⁑{m1+2/(k+1),n1+3/k}) time. Therefore, for kβ‰₯2, g~∈{3,4,5} and Ξ±=⌈g~2βŒ‰, there is a (max⁑{2⁒k,g},g~)-hybrid algorithm that runs in O⁒(min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}) time. A natural question is whether these three algorithms are only part of a general tradeoff between the running time, Ξ³ and Ξ΄.

Problem 1.1.

Let g~β‰₯6 and kβ‰₯2 be two integers and let Ξ±=⌈g~2βŒ‰. Is it possible to obtain a (max⁑{2⁒k,g},g~)-hybrid algorithm that runs in O⁒(min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}) time?

In this paper we present a (max⁑{2⁒k,g},g~)-hybrid algorithm that runs, whp, in O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}) time, for every g~β‰₯3. This algorithm provides an affirmative answer to Problem 1.1, albeit the (k+1Ξ±βˆ’1+Ξ±) factor in the running time.

Kadria et al. [7] presented also a (2⁒k,6)-hybrid algorithm whose running time is O~⁒(min⁑{n⁒m12+12⁒(k+1),n32+1k}), for every integer kβ‰₯4. The running time of our algorithm when g~=6 is O~⁒(kβ‹…min⁑{m1+2k+1,n1+3k}). We improve the running time for every constant kβ‰₯5, in the case of m<O⁒(n1+1/k) (when mβ‰₯O⁒(n1+1/k) the two algorithms run a similar procedure and thus have the same asymptotic running time).

Using our (max⁑{2⁒k,g},g~)-hybrid algorithm we obtain a generalization of the O~⁒(n1+1/(2βˆ’Ξ΅)) time algorithm of Kadria et al. [7] that computes a cycle of length at most 4⁒⌈g2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹β‰€(2βˆ’Ξ΅)⁒g+4, for every graph with g=polylog⁒(n). Our generalized algorithm runs in O~⁒(β„“β‹…n1+1/(β„“βˆ’Ξ΅)) time, whp, and returns a cycle of length at most 2β’β„“β’βŒˆg2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹β‰€(β„“βˆ’Ξ΅)⁒g+β„“+2, where β„“β‰₯2 is an integer and Ρ∈[0,1], for every graph with g=polylog⁒(n). We also show that if the graph is sparse then the approximation can be improved. More specifically, we present an algorithm that runs in O~⁒(β„“β‹…m1+1/(β„“βˆ’Ξ΅)) time, whp, and returns a cycle of length at most (β„“βˆ’Ξ΅)⁒gβˆ’β„“+2⁒Ρ, where β„“β‰₯3 is an integer and Ρ∈[0,1), for every graph with g=polylog⁒(n).

Ξ΅ Time [3pt] exp Cycle bound
0 1+39 18
13 1+38 16
23 1+37 14
1 1+36 12
Figure 1: Our O~⁒(β„“β‹…n1+1β„“βˆ’Ξ΅)-time girth approximation algorithm compared to the O~⁒(n1+1β„“)-time algorithm of [7], for every Ρ∈[0,1], choosing β„“=3 and g=5 or 6. (a) The y-axis is the exponent of n in the running time, and the x-axis is Ξ΅. (b) The y-axis is the upper bound on the length of the returned cycle, and the x-axis is Ξ΅. The blue points correspond to our algorithm at four specific choices of Ξ΅: Ξ΅=0,13,23,1 (see the table on the right).

Our O~⁒(β„“β‹…n1+1/(β„“βˆ’Ξ΅))-time algorithm also generalizes the O~⁒(n1+1/β„“)-time algorithm of Kadria et al. [7], which computes a C≀2β’β„“β’βŒˆg/2βŒ‰ for every integer β„“β‰₯1. In our algorithm, the integer parameter β„“ that appears in the exponent of the running time is replaced by a real-valued parameter β„“βˆ’Ξ΅. Thus, we introduce many new points on the tradeoff curve between running time and approximation ratio. Specifically, for every integer ℓ≀polylog⁒(n), up to ⌈g/2βŒ‰βˆ’1 additional tradeoff points are added.111Up to ⌈g/2βŒ‰βˆ’1 tradeoff points are added since for every such β„“, when Ξ΅ is a multiple of 1⌈g/2βŒ‰, we get an O~⁒(n1+1/(β„“βˆ’Ξ΅))-time algorithm which computes a C≀2⁒(β„“βˆ’Ξ΅)⁒⌈g/2βŒ‰. For example, consider β„“=3 and a graph with girth g=5 or g=6. Our algorithm yields two additional points on the tradeoff curve, corresponding to Ξ΅=13 and Ξ΅=23. For Ξ΅=13, we compute a C≀16 in O~⁒(n1+38) time, and for Ξ΅=23, we compute a C≀14 in O~⁒(n1+37) time. These points lie between the two points on the tradeoff curve given by the algorithm of Kadria et al. [7], which computes either a C≀12 in O~⁒(n1+36) time or a C≀18 in O~⁒(n1+39) time. See Figure 1 for a comparison.

Together, the tradeoffs in the two algorithms of Kadria et al. [7] that we generalize encompass several other known results, including those of Itai and Rodeh [6], Lingas and Lundell [8], Roditty and V. Williams [12] and the first tradeoff of Dahlgaard et al. [4] (when g=polylog⁒(n)). Notably, some of these algorithms have resisted improvement for many years. Therefore, the unification of these algorithms within a single tradeoff curve in our result, together with the addition of new valid points on this curve, reinforces the possibility that it captures a fundamental relationship between running time and approximation quality. This, in turn, motivates further investigation into whether a matching lower bound exists for this tradeoff.

The rest of this paper is organized as follows. In Section 2 we provide an overview. Preliminaries are in Section 3. In Section 4, we present a new cycle searching technique that is used by our algorithms. In Section 5 we present a 2⁒k-hybrid algorithm and then use it to obtain a (+1)-approximation algorithm for the girth. In Section 6 we generalize the 2⁒k-hybrid algorithm and present a (max⁑{2⁒k,g},g~)-hybrid algorithm. In Section 7 we use the hybrid algorithm from Section 6 to obtain two more approximation algorithms for the girth.

2 Overview

Among the techniques that we develop to obtain our new algorithms, is a new cycle searching technique that might be of independent interest. Our new technique exploits the property that if s∈V is not on a C≀2⁒k, then for any two neighbors x and y of s, the set of vertices at distance exactly kβˆ’1 from x and y that are also at distance k from s are disjoint (see Figure 2). This allows us to check efficiently for all the neighbors of s if they are on a C≀2⁒k. Using this technique, together with more tools that we develop, we obtain two hybrid algorithms.

Figure 2: Disjoint sets of vertices at distance kβˆ’1 from x and y.

The first is a relatively simple O⁒(m1+kβˆ’1k+1)-time, 2⁒k-hybrid algorithm. We use this hybrid algorithm in the girth approximation framework described earlier, to obtain an O~⁒(m1+β„“βˆ’1β„“+1)-time, (+1)-approximation of the girth, where g=2⁒ℓ or g=2β’β„“βˆ’1 (the running time can also be written as O~⁒(m2βˆ’2⌈g/2βŒ‰+1)). We remark that using an algorithm of [3] for C2⁒k detection, it is possible to obtain a (+1)-approximation in O~⁒(β„“O⁒(β„“)β‹…m1+β„“βˆ’1β„“+1) time (see Section 5.2 for more details). However, the additional β„“O⁒(β„“) factor might be significant even for small values of β„“.

The second is the (max⁑{2⁒k,g},g~)-hybrid algorithm that solves Problem 1.1. Its main component is an (2⁒k,2⁒α)-hybrid algorithm that runs in O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…m1+Ξ±βˆ’1k+1)-time, whp, and generalizes the first O⁒(m1+kβˆ’1k+1)-time 2⁒k-hybrid algorithm, by introducing an additional parameter α≀k. Using Ξ± we can tradeoff between the running time and the lower bound on g and obtain a faster running time at the price of a worse lower bound.

We compare our (2⁒k,2⁒α)-hybrid algorithm to algorithm Cycle of Kadria et al. [7], an O⁒(m+n1+1β„“)-time,222Cycle runs in O⁒(n1+1β„“+m) time, which can be reduced to O⁒(n1+1β„“) time, as shown in [7]. (2⁒ℓ⁒α,g~)-hybrid algorithm, where Ξ±=⌈g~/2βŒ‰, that they used to obtain the O~⁒(n1+1β„“)-time, 2β’β„“β’βŒˆg/2βŒ‰-approximation algorithm. As we show later, the running time of our (2⁒k,2⁒α)-hybrid algorithm can be bounded by O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…n1+Ξ±k). Since in our algorithm k is not necessarily a multiple of Ξ± (compared to the ℓ⁒α of Cycle), our algorithm allows more flexibility, and we achieve many more possible tradeoffs between the running time and the output cycle length. For example, if we consider a multiplicative approximation better than 3, when the value of g is a constant known in advance, our algorithm can return longer cycles that are still shorter than 3⁒g, in a faster running time.333[7] presented also an O⁒((Ξ±βˆ’c)β‹…n1+Ξ±2β’Ξ±βˆ’c)-time, (4β’Ξ±βˆ’2⁒c,2⁒α)-hybrid algorithm, where 0<c≀α are integers. For c=2β’Ξ±βˆ’k, this is an O⁒((kβˆ’Ξ±)β‹…n1+Ξ±k)-time, (2⁒k,2⁒α)-hybrid algorithm, similar to our (2⁒k,2⁒α)-hybrid algorithm. However, since 0<c≀α, the possible values of k are restricted and must satisfy α≀k<2⁒α. By choosing Ξ±=⌈g2βŒ‰ and an appropriate k the two algorithms have a similar flexibility for a 2-approximation, but since in our algorithm also larger values of k are allowed, we can achieve a faster running time for a t-approximation where t>2.

The flexibility of our algorithm is also demonstrated as follows. For a given constant value of k, if our (2⁒k,2⁒α)-hybrid algorithm returns a cycle then its length is at most 2⁒k. If we want algorithm Cycle to output a C≀2⁒k, then ⌊kΞ±βŒ‹ is the largest β„“ that we can choose, since β„“ must be an integer. The running time is O⁒(n1+1/β„“)=O⁒(n1+1/⌊kΞ±βŒ‹). Our algorithm achieves a better running time if k is not divisible by Ξ±. (See the relevant figures in the full version of this paper [10] for a comparison).

Next, we overview our (2⁒k,2⁒α)-hybrid algorithm that either finds a C≀2⁒k or determines that g>2⁒α in O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…m1+Ξ±βˆ’1k+1) time. In order to determine that gβ‰₯2⁒α, we can check for every v∈V if v is on a C≀2⁒α (and either find a C≀2⁒k since α≀k, or return that g>2⁒α). If v is on a C≀2⁒α, then all the vertices and edges of this C≀2⁒α are at distance at most Ξ± from v. If, for every v∈V, the number of edges at distance at most Ξ± is O⁒(d⁒e⁒g⁒(v)β‹…mΞ±βˆ’1k+1) then using standard techniques we can check for every v∈V if v is on a C≀2⁒α in O⁒(m1+Ξ±βˆ’1k+1) time. However, this is not necessarily the case, and the region at distance at most Ξ± from some vertices might be dense. To deal with dense regions within the promised running time we develop an iterative sampling procedure (see BfsSample in Section 6), whose goal is to sparsify the graph, or to return a C≀2⁒k. One component of the iterative sampling procedure is a generalization of our new cycle searching technique mentioned above. In the generalization instead of checking whether a vertex s and its neighbors are on a C≀2⁒k, we check whether all the vertices up to a possibly further distance from s are on a C≀2⁒α, for α≀k, and if not we mark them so that they can be removed later.

If the iterative sampling procedure ends without finding a C≀2⁒k then there are two possibilities. Let r=(k+1)mod(Ξ±βˆ’1). If r=0 then it holds that the number of edges at distance at most Ξ± from every v∈V is O⁒(d⁒e⁒g⁒(v)β‹…mΞ±βˆ’1k+1), whp, as required. If r>0 then it holds that the number of edges at distance at most r from every v∈V is O⁒(mrk+1), whp. This does not necessarily imply that the graph is sparse enough for checking whether g>2⁒α. In this case, we run another algorithm (see HandleRemainder in Section 6) that continues to sparsify the graph until the number of edges at distance at most Ξ± from every v∈V is O⁒(d⁒e⁒g⁒(v)β‹…mΞ±βˆ’1k+1) and checking whether g>2⁒α is possible within the required running time of O⁒(m1+Ξ±βˆ’1k+1).

3 Preliminaries

Let G=(V,E) be an unweighted undirected graph with n vertices and m edges. Let UβŠ†V be a set of vertices and let Gβˆ–U be the graph obtained from G by deleting all the vertices of U together with their incident edges. For two graphs G=(V,E) and Gβ€²=(Vβ€²,Eβ€²), let Gβˆ–Gβ€² be Gβˆ–Vβ€². We say that GβŠ†Gβ€² if VβŠ†Vβ€² and EβŠ†Eβ€². For convenience, we use both u∈V and u∈G to say that u∈V. For every u,v∈V, let dG⁒(u,v) be the length of a shortest path between u and v in G. The girth g of G is the length of a shortest cycle in G. Let w⁒t⁒(C) be the length of a cycle C. For an integer β„“, we denote a cycle of length (at most) β„“ by (C≀ℓ) Cβ„“.444Both Cβ„“ and C≀ℓ might not be simple cycles. However, the cycles that our algorithms return are simple. Let E⁒(v) be the edges incident to v and E⁒(v,i) the ith edge in E⁒(v). Let d⁒e⁒gG⁒(v) be the degree of v in G. Let N⁒(v) be the set of neighbors of v, namely N⁒(v)={w∣(v,w)∈E}. For an edge set S, let V⁒(S) be the endpoints of S’s edges, that is, V⁒(S)={u∈Vβˆ£βˆƒ(u,v)∈S}. Let e=(u,v)∈E and w∈V. The distance dG⁒(w,e) between w and e is min⁑{dG⁒(w,u),dG⁒(w,v)}+1. For every u∈V and a real number k let B⁒(G,u,k)=(Vuk⁒(G),Euk⁒(G)) be the ball graph of u, where Vuk⁒(G)={v∈V∣dG⁒(u,v)≀k} and Euk⁒(G)={e∈E∣dG⁒(u,e)≀k} [7]. For an integer β„“β‰₯0 and a vertex u∈V, Let Luℓ⁒(G)={w∣dG⁒(u,w)=β„“}.555When the graph is clear from the context, we sometimes omit G from the notations.

We now turn to present several essential tools that are required in order to obtain our new algorithms. We first restate an important property of the ball graph B⁒(v,R).

Lemma 2 ([7]).

Let 0≀t≀R be two integers and let v∈V. If B⁒(v,R) is a tree then no vertex in VvRβˆ’t is part of a cycle of length at most 2⁒t in G.

We use procedure BallOrCycle⁒(G,v,R) [7, 8] (pseudo-code in [10]) that searches for a C≀2⁒R in the ball graph B⁒(v,R). We summarize BallOrCycle’s properties in the next lemma.

Lemma 3 ([7]).

Let v∈V. If the ball graph B⁒(v,R) is not a tree then BallOrCycle⁒(G,v,R) returns a C≀2⁒R from B⁒(v,R). If B⁒(v,R) is a tree then BallOrCycle⁒(G,v,R) returns VvR.666If VvR is returned then we assume that VvR is ordered by the distance from v, and for every u∈VvR we store d⁒(u,v) with u. Thus, given the set VvR, we can find VvRβ€² for every Rβ€²<R in O⁒(|VvRβ€²|) time. The running time of BallOrCycle⁒(G,v,R) is O⁒(|VvR|).

Next, we obtain a simple t-hybrid algorithm, called AllVtxBallOrCycle, using BallOrCycle. AllVtxBallOrCycle (pseudo-code in [10]) gets a graph G and an integer tβ‰₯2, and runs BallOrCycle⁒(v,t) from every v∈G as long as no cycle is found by BallOrCycle. If BallOrCycle finds a cycle then AllVtxBallOrCycle stops and returns that cycle. If no cycle is found then AllVtxBallOrCycle returns null. We prove the next lemma in the full version of this paper [10].

Algorithm 1 SparseOrCycle⁒(G,D,x,y).
Lemma 4.

AllVtxBallOrCycle⁒(G,t) either finds a C≀2⁒t or determines that g>2⁒t, in O⁒(βˆ‘v∈V|Vvt|) time.

We now show that if the input graph satisfies a certain sparsity property then the running time of AllVtxBallOrCycle⁒(G,t) can be bounded as follows.

Corollary 5.

If |Eutβˆ’1|<Dtβˆ’1 for every u∈V then AllVtxBallOrCycle⁒(G,t) runs in O⁒(m⁒Dtβˆ’1) time.

Proof.

For every v∈V, we have O⁒(|Vvt|)≀O⁒(|Evt|)≀O⁒(βˆ‘u∈N⁒(v)|Eutβˆ’1|), which is at most O⁒(βˆ‘u∈N⁒(v)Dtβˆ’1)=O⁒(d⁒e⁒g⁒(v)β‹…Dtβˆ’1). Thus, by Lemma 4, the running time of AllVtxBallOrCycle⁒(G,t) is O⁒(βˆ‘v∈V|Vvt|)≀O⁒(βˆ‘v∈Vd⁒e⁒g⁒(v)β‹…Dtβˆ’1)=O⁒(m⁒Dtβˆ’1). β—€

Next, we present procedure IsDense⁒(G,w,T,r) from [7]. IsDense (pseudo-code in [10]) gets a graph G, a vertex w, a budget Tβ‰₯1 (real) and a distance rβ‰₯0 (integer). In the procedure a BFS is executed from w. The BFS counts the edges that are scanned as long as their total number is less than T and the farthest vertex from w is at distance at most r.

Lemma 6 ([7]).

Procedure IsDense⁒(G,w,T,r) runs in O⁒(⌈TβŒ‰)=O⁒(T) time. If IsDense⁒(G,w,T,r)=No then |Ewr|<T. If IsDense⁒(G,w,T,r)=Yes then |Ewr|β‰₯T.

Given a vertex v and a distance R we sometimes want to bound |EvR|. Therefore, we adapt a lemma and a corollary of [7] from vertices to edges. The proofs are in the full version of this paper [10].

Lemma 7.

Let x,y be positive integers, let Dβ‰₯1 be a real number, and let w∈V. If |Ewx|<Dx, and |Euy|<Dy for every u∈V, then |Ewx+y|<Dx+y.

Corollary 8.

Let x be a positive integer and let Dβ‰₯1 be a real number. If |Ewx|<Dx for every w∈V, then |Ewi⁒x|<Di⁒x, for every w∈V and iβ‰₯1.

We also adapt procedure SparseOrCycle⁒(G,D,x,y) of [7] to our needs. SparseOrCycle (see Algorithm 1) gets a graph G, a parameter Dβ‰₯1, and two integers x,y>0, and iterates over vertices using a for-each loop. Let w be the vertex currently considered and G⁒(w) the current graph. If IsDense⁒(G⁒(w),w,Dx,x)=Yes then BallOrCycle⁒(G⁒(w),w,xβˆ’1+y) is called. If BallOrCycle returns a cycle C then C is returned by SparseOrCycle. Otherwise, the vertex set Vwxβˆ’1 is removed from G⁒(w) along with the edge set Ewx. After the loop ends, if no cycle was found, we return null. Let WβŠ†V be the set of vertices for which BallOrCycle was called and no cycle was found, and G^=(V^,E^) the graph after SparseOrCycle ends. The following lemma is similar to the corresponding lemmas from [7]. For completeness, the proof is provided in the full version of this paper [10].

Lemma 9.

SparseOrCycle⁒(G,D,x,y) satisfies the following:

  1. (i)

    If a cycle C is returned then w⁒t⁒(C)≀2⁒(xβˆ’1+y)

  2. (ii)

    If a cycle is not returned then |Eux|<Dx, for every u∈G^

  3. (iii)

    If u∈Gβˆ–G^ then u is not part of a C≀2⁒y in G

  4. (iv)

    SparseOrCycle⁒(G,D,x,y) runs in O⁒(n⁒Dx+βˆ‘w∈W(|Vwxβˆ’1+y|)) time.

Similarly to AllVtxBallOrCycle, we show for SparseOrCycle that if G satisfies a certain sparsity property, the running time can be bounded as follows. The proof is in the full version [10].

Corollary 10.

If |Euxβˆ’1+y|<Dxβˆ’1+y for every vertex u∈V then SparseOrCycle⁒(G,D,x,y) runs in O⁒(n⁒Dx+m⁒Dyβˆ’1) time.

Finally, we include a standard lemma about sampling a hitting set (see, e.g., [1], [8], [11]).

Lemma 11.

It is possible to obtain in O⁒(m) time, using sampling, a set of edges S of size Θ~⁒(ms), that hits, whp, the s closest edges of every v∈V.

We remark that some of our algorithms get a graph G that is being updated during their run. Within their scope, G denotes the current graph that includes all updates done so far.

4 A new cycle searching technique

In this section we introduce a new cycle searching technique implemented in algorithm NbrBallOrCycle. This technique exploits the property that a vertex s∈V is not on a C≀2⁒k, to check efficiently whether any neighbor of s lies on a C≀2⁒k.

Consider a vertex s∈V. It is straightforward to check whether s is on a C≀2⁒k, for every integer k, using BallOrCycle⁒(G,s,k) in O⁒(n) time. If BallOrCycle⁒(G,s,k) does not return a C≀2⁒k then for every x,y∈N⁒(s) it holds that Vxkβˆ’1⁒(Gβ€²)∩Vykβˆ’1⁒(Gβ€²)=βˆ…, where Gβ€²=Gβˆ–{s}, as otherwise there was a C≀2⁒k passing through s and BallOrCycle⁒(G,s,k) would have returned a C≀2⁒k (see Figure 2). We show that it is possible to exploit this property to check for every v∈N⁒(s) whether v is on a C≀2⁒k, using BallOrCycle⁒(Gβ€²,v,k), in O⁒(n+m) time instead of O⁒(d⁒e⁒g⁒(s)β‹…n). More specifically, we present algorithm NbrBallOrCycle⁒(G,s,k) (see Algorithm 2) that gets a graph G, a vertex s, and an integer kβ‰₯2. We first initialize U^ to βˆ…. Then, we run BallOrCycle⁒(G,s,k). If a cycle C is found by BallOrCycle⁒(G,s,k) then C is returned by NbrBallOrCycle. Otherwise, we add the vertex s to U^, keep the neighbors of s in Ns, and then remove s from G. Recall that Gβ€² equals Gβˆ–{s}. Next, for every v∈Ns we run BallOrCycle⁒(Gβ€²,v,k), as long as a cycle is not found. If a cycle C is returned by BallOrCycle⁒(Gβ€²,v,k) then C is returned by NbrBallOrCycle.777For our needs it suffices to stop and return a cycle passing through an s neighbor once we find one, though BallOrCycle can be run from all the neighbors of s in the same running time bound of O⁒(n+m). Otherwise, v is added to U^. After the loop ends, the vertex s and its adjacent edges are added back to the graph, and the set U^ is returned by NbrBallOrCycle. We prove the following lemma in the full version of this paper [10].

Algorithm 2 NbrBallOrCycle⁒(G,s,k).
Lemma 12.

If algorithm NbrBallOrCycle⁒(G,s,k) finds a cycle C then w⁒t⁒(C)≀2⁒k. Otherwise, no vertex in Vs1 is part of a C≀2⁒k in G, and the set U^=Vs1 is returned.

To bound the running time of NbrBallOrCycle, we show how to use the fact that no C≀2⁒k was found by BallOrCycle⁒(G,s,k), to efficiently run BallOrCycle⁒(Gβ€²,v,k) for every v∈Ns.

Lemma 13.

Let s∈V. If the ball graph B⁒(G,s,k) is a tree then the total cost of running BallOrCycle⁒(Gβ€²,v,k) for every v∈Ns is O⁒(|Vsk⁒(G)|+βˆ‘w∈Lsk⁒(G)d⁒e⁒g⁒(w)).

Proof.

By the definitions of Vsk, Lsk and Gβ€², we know that Vsk⁒(G)=βˆͺv∈NsVvkβˆ’1⁒(Gβ€²)βˆͺ{s} and Lsk⁒(G)=βˆͺv∈NsLvkβˆ’1⁒(Gβ€²). Since B⁒(G,s,k) contains no cycles it follows that Vxkβˆ’1⁒(Gβ€²)∩Vykβˆ’1⁒(Gβ€²)=βˆ… and Lxkβˆ’1⁒(Gβ€²)∩Lykβˆ’1⁒(Gβ€²)=βˆ…, for any two distinct vertices x,y∈Ns. Therefore, (i) |Vsk⁒(G)|=βˆ‘v∈Ns|Vvkβˆ’1⁒(Gβ€²)|+1, and (ii) Lsk⁒(G)=β‹…Ξ“βˆͺv∈NsLvkβˆ’1⁒(Gβ€²). From Lemma 3 it follows that the total cost of the calls to BallOrCycle⁒(Gβ€²,v,k) for every v∈Ns is O⁒(βˆ‘v∈Ns|Vvk⁒(Gβ€²)|). It holds that |Vvk⁒(Gβ€²)|≀|Vvkβˆ’1⁒(Gβ€²)|+βˆ‘w∈Lvkβˆ’1⁒(Gβ€²)d⁒e⁒g⁒(w), for every v∈Ns. Thus, we get that the total cost is O⁒(βˆ‘v∈Ns|Vvk⁒(Gβ€²)|)=O⁒(βˆ‘v∈Ns(|Vvkβˆ’1⁒(Gβ€²)|+βˆ‘w∈Lvkβˆ’1⁒(Gβ€²)d⁒e⁒g⁒(w))). This equals to O(βˆ‘v∈Ns|Vvkβˆ’1(Gβ€²)|+βˆ‘v∈Nsβˆ‘w∈Lvkβˆ’1⁒(Gβ€²)deg(w))), and it follows from (i) and (ii) that this is at most O⁒(|Vsk⁒(G)|+βˆ‘w∈Lsk⁒(G)d⁒e⁒g⁒(w)). β—€

We use Lemma 13 to bound the running time of NbrBallOrCycle.

Lemma 14.

Algorithm NbrBallOrCycle runs in O⁒(n+m) time.

Proof.

Running BallOrCycle⁒(G,s,k) costs O⁒(n). If a cycle is found, it is returned and the running time is O⁒(n)=O⁒(n+m). If no cycle is found, then removing (and later adding back) s and its edges costs O⁒(d⁒e⁒g⁒(s)). By Lemma 13, the cost of running BallOrCycle⁒(Gβ€²,v,k) for every v∈Ns is O⁒(|Vsk⁒(G)|+βˆ‘w∈Lsk⁒(G)d⁒e⁒g⁒(w))=O⁒(n+m). Adding s and Ns to U^ takes O⁒(Vs1)=O⁒(n) time. Thus, the total running time of NbrBallOrCycle is O⁒(n+m). β—€

5 A πŸβ’π’Œ-hybrid algorithm and a (+𝟏)-approximation of the girth

In this section we first show how to use algorithm NbrBallOrCycle from the previous section to obtain a 2⁒k-hybrid algorithm that in O⁒(m1+kβˆ’1k+1) time, either returns a C≀2⁒k or determines that g>2⁒k. Then, we use the 2⁒k-hybrid algorithm to compute a (+1)-approximation of g.

5.1 A πŸβ’π’Œ-hybrid algorithm

We first present algorithm 2-SparseOrCycle⁒(G,k) that gets a graph G and an integer kβ‰₯2. Let G0 (G1) be G before (after) running 2-SparseOrCycle. 2-SparseOrCycle⁒(G,k) either finds a C≀2⁒k or removes vertices that are not on a C≀2⁒k, such that for every u∈G1, the ball graph B⁒(G1,u,2) is relatively sparse, that is, |Eu2⁒(G1)|<m2k+1. 2-SparseOrCycle (pseudo-code in [10]) iterates over vertices using a for-each loop. Let s be the vertex currently considered. If βˆ‘v∈N⁒(s)d⁒e⁒g⁒(v)β‰₯m2k+1 then NbrBallOrCycle⁒(G,s,k) is called. If NbrBallOrCycle returns a cycle C then 2-SparseOrCycle returns C. If NbrBallOrCycle returns a vertex set U^ then U^ is removed from G. After the loop ends, if no cycle was found, we return null.

β–ΆΒ Remark.

Notice that SparseOrCycle⁒(G,m2k+1,2,k) either finds a C≀2⁒k+2 or removes vertices that are not on a C≀2⁒k, such that for every u∈G1 it holds that |Eu2⁒(G1)|<m2k+1. Using NbrBallOrCycle instead of BallOrCycle in 2-SparseOrCycle enables us in the case that a cycle is found to bound the cycle length with 2⁒k rather than 2⁒k+2, while still maintaining the property that |Eu2⁒(G1)|<m2k+1, for every u∈G1, in the case that no cycle is found.

We prove the following lemma in the full version of this paper [10].

Lemma 15.

2-SparseOrCycle⁒(G,k) satisfies the following:

  1. (i)

    If a cycle C is returned then w⁒t⁒(C)≀2⁒k

  2. (ii)

    If a cycle is not returned then |Eu2|<m2k+1, for every u∈G1

  3. (iii)

    If u∈G0βˆ–G1 then u is not part of a C≀2⁒k in G0

  4. (iv)

    2-SparseOrCycle⁒(G,k) runs in O⁒(m1+kβˆ’1k+1) time.

Next, we use 2-SparseOrCycle to design a 2⁒k-hybrid algorithm called 2⁒k-Hybrid. Notice first that if |Eukβˆ’1|<mkβˆ’1k+1 for every u∈V, then it is straightforward to obtain an O⁒(m1+kβˆ’1k+1)-time 2⁒k-hybrid algorithm, by running AllVtxBallOrCycle⁒(G,k). Thus, in 2⁒k-Hybrid we ensure that if we call AllVtxBallOrCycle then it holds for every u∈V that |Eukβˆ’1|<mkβˆ’1k+1. To do so, we run 2-SparseOrCycle and possibly SparseOrCycle. If no cycle was returned then we have |Eukβˆ’1|<mkβˆ’1k+1 for every u∈V, and we can safely run AllVtxBallOrCycle.

2⁒k-Hybrid (pseudo-code in [10]) gets a graph G and an integer kβ‰₯2. 2⁒k-Hybrid is composed of three stages. In the first stage we call 2-SparseOrCycle⁒(G,k). If 2-SparseOrCycle returns a cycle C then 2⁒k-Hybrid stops and returns C, otherwise we proceed to the second stage. In the second stage, if (kβˆ’1)mod2β‰ 0, we call SparseOrCycle⁒(G,m1k+1,1,k). If SparseOrCycle returns a cycle C then 2⁒k-Hybrid stops and returns C, otherwise we proceed to the last stage. In the last stage, we call AllVtxBallOrCycle⁒(G,k). If AllVtxBallOrCycle returns a cycle C then 2⁒k-Hybrid stops and returns C, otherwise 2⁒k-Hybrid returns null. We prove the next lemma in the full version of this paper [10].

Lemma 16.

2⁒k-Hybrid⁒(G,k) either returns a C≀2⁒k or determines that g>2⁒k, in O⁒(m1+kβˆ’1k+1) time.

5.2 A (+𝟏)-approximation of the girth

Next, we describe algorithm AdtvGirthApprox, which uses 2⁒k-Hybrid and the framework described in Section 1, to obtain a (+1)-approximation of g, when g≀log⁑n. AdtvGirthApprox (pseudo-code in [10]) gets a graph G. In AdtvGirthApprox, we set k to 2 and start a while loop. In each iteration, we create a copy Gβ€² of G and call 2⁒k-Hybrid⁒(Gβ€²,k). If 2⁒k-Hybrid finds a cycle C then AdtvGirthApprox stops and returns C, otherwise we increment k by 1 and continue to the next iteration. We prove the following theorem in the full version of this paper [10].

Theorem 17.

Algorithm AdtvGirthApprox⁒(G) returns either a Cg or a Cg+1, and runs in O~⁒(m1+β„“βˆ’1β„“+1) time, where g=2⁒ℓ or g=2β’β„“βˆ’1 and 2≀ℓ<log⁑n.888We note that when β„“β‰₯log⁑n, the O⁒(n2)-time, (+1)-approximation of Itai and Rodeh [6] can be used.

β–ΆΒ Remark.

Dahlgaard, Knudsen and StΓΆckel [3] showed that a C2⁒k, if exists, can be found in O⁒(kO⁒(k)β‹…m2⁒kk+1) time. It is possible to use their C2⁒k detection algorithm to obtain a (+1)-approximation for the girth in O~⁒(β„“O⁒(β„“)β‹…m1+β„“βˆ’1β„“+1) time, where g=2⁒ℓ or g=2β’β„“βˆ’1, as mentioned in Section 2. This (+1)-approximation is obtained as follows. We run the detection algorithm with increasing values of k, starting with k=2. If a C2⁒k is detected we stop and return the detected cycle. In such a case 2⁒k is a (+1)-approximation for the girth. If there is no C2⁒k then it follows from the analysis of [3] that a C2⁒kβˆ’1, if exists, can be detected within the same running time using a slight modification of their algorithm. If a C2⁒kβˆ’1 is detected we stop and return the detected cycle. In such a case 2⁒kβˆ’1 is the girth. If neither a C2⁒k nor a C2⁒kβˆ’1 is found we increment k by 1. Since a cycle must be found when k=β„“, we obtain a (+1)-approximation for the girth in O~⁒(β„“O⁒(β„“)β‹…m1+β„“βˆ’1β„“+1) time, where g=2⁒ℓ or g=2β’β„“βˆ’1.

A disadvantage of the algorithm described above is the β„“O⁒(β„“) factor which in our new algorithm does not exist. To better appreciate our contribution we compare our 2⁒k-Hybrid algorithm (for C≀2⁒k detection) and the algorithm of [3] (for C2⁒k detection), that are used for obtaining the approximation.

Both algorithms first sparsify the graph (or find a cycle). The algorithm of [3] first handles high degree vertices, by running an O⁒(m)-time C2⁒k detection algorithm from each high degree vertex (vertex of degree >m2/(k+1)). If a C2⁒k is found then a C2⁒k is returned, otherwise the high degree vertices (and their adjacent edges) are removed. This is possible within the running time since there cannot be too many high degree vertices. In our algorithm, we handle first vertices with at least m2/(k+1) edges up to distance 2 rather than 1. This is possible using our NbrBallOrCycle algorithm, since we can search for a C≀2⁒k from a vertex and also its neighbors in O⁒(m) time. If a C2⁒k is found then a C2⁒k is returned, otherwise the vertex and its neighbors are removed (therefore also the edges up to distance 2 from the vertex). Then, if required, we handle also high degree vertices and remove them.

After the sparsification stage, in [3] they prove that when the maximum degree is bounded, if there is no C2⁒k then the number of capped k-walks (walks of length k that visit only nodes according to a fixed ordering) in the graph is bounded by O⁒(kO⁒(k)⁒m1+(kβˆ’1)/(k+1)), where the kO⁒(k) factor follows from their analysis. They use this property to build a series of subgraphs in which the total number of edges is bounded, and therefore it is possible to search for a C2⁒k in these graphs efficiently. In our algorithm, after the sparsification stage it holds that the total number of edges up to distance k from all the vertices is bounded by O⁒(m1+(kβˆ’1)/(k+1)) (avoiding the kO⁒(k) factor), and we can search efficiently for a C≀2⁒k.

6 A general hybrid algorithm

Algorithm 2⁒k-Hybrid⁒(G,k), presented in the previous section, either returns a C≀2⁒k or determines that g>2⁒k, in O⁒(m1+kβˆ’1k+1) time. In this section we introduce an additional parameter 2≀α≀k and present a (2⁒k,2⁒α)-hybrid algorithm that either returns a C≀2⁒k or determines that g>2⁒α, in O⁒((k+1Ξ±βˆ’1+Ξ±)β‹…m1+Ξ±βˆ’1k+1) time. In Section 7 we use the (2⁒k,2⁒α)-hybrid algorithm to present two tradeoffs for girth approximation.

To obtain the (2⁒k,2⁒α)-hybrid algorithm we first extend algorithm NbrBallOrCycle. Then, we use the extended NbrBallOrCycle together with additional tools that we develop to either return a C≀2⁒k or sparsify dense regions of the graph, so that we can check whether g>2⁒α (or return a C≀2⁒k) in O⁒(m1+Ξ±βˆ’1k+1) time, by running AllVtxBallOrCycle⁒(G,Ξ±).

6.1 Extending NbrBallOrCycle

In algorithm NbrBallOrCycle we mark vertices that can be removed from the graph, by using the property that if BallOrCycle⁒(v,k) did not return a C≀2⁒k then v is not on a C≀2⁒k. In [7], they introduce an additional parameter Ξ± and used the following extended version of this property: If BallOrCycle⁒(v,k) did not return a C≀2⁒k then no vertex of Vvkβˆ’Ξ± is on a C≀2⁒α. We use the same approach and modify NbrBallOrCycle to get an additional integer parameter Ξ± such that 2≀α≀k. After each call to BallOrCycle⁒(Gβ€²,v,k), where v∈Ns, if no cycle was found we add Vvkβˆ’Ξ±, instead of v, to U^. The modified pseudo-code appears in the full version of this paper [10]. We rephrase Lemma 12 to suit this modification. The proof is also given in [10].

Lemma 18.

Let 2≀α≀k. If NbrBallOrCycle⁒(G,s,k,Ξ±) finds a cycle C then w⁒t⁒(C)≀2⁒k. Otherwise, no vertex in Vskβˆ’Ξ±+1 is part of a C≀2⁒α in G, and the set U^=Vskβˆ’Ξ±+1 is returned.

For the running time, we note that the sets Vvk are computed during the execution of BallOrCycle⁒(Gβ€²,v,k), for every (s,v)∈Ns for which no cycle was found. Their total size is also O⁒(n+m), and we can obtain from them the sets Vvkβˆ’Ξ± and add these sets to U^ in O⁒(n+m) time. Therefore, the modified NbrBallOrCycle also runs in O⁒(n+m) time.

6.2 A (𝐦𝐚𝐱⁑{πŸβ’π’Œ,π’ˆ},π’ˆ~)-hybrid algorithm

In this section we present a (max⁑{2⁒k,g},2⁒α)-hybrid algorithm called ShortCycle, where Ξ±=⌈g~2βŒ‰. ShortCycle (pseudo-code in [10]) gets a graph G and two integers Ξ±,kβ‰₯2. If mβ‰₯1+⌈nβ‹…(1+n1/k)βŒ‰ then we run algorithm ShortCycleDense⁒(G,k) (pseudo-code in [10]), which is based on algorithm DegenerateOrCycle of [7].

If m<1+⌈nβ‹…(1+n1/k)βŒ‰ then the main challenge is when α≀k<n2. In this case we run algorithm ShortCycleSparse⁒(G,k,Ξ±) (described later). The cases that kβ‰₯n2 or k<Ξ± are relatively simple and are treated by algorithm SpecialCases⁒(G,k,Ξ±) (see the full version of this paper [10]). We summarize the properties of ShortCycle⁒(G,k,Ξ±) in the next theorem.

Theorem 19.

Let Ξ±,kβ‰₯2 be integers. ShortCycle⁒(G,k,Ξ±) runs whp in O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}) time and either returns a C≀max⁑{2⁒k,g}, or determines that g>2⁒α.

The next corollary follows from Theorem 19, when α≀k.

Corollary 20.

Let 2≀α≀k. Algorithm ShortCycle⁒(G,k,Ξ±) runs whp in O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}) time and either returns a C≀2⁒k, or determines that g>2⁒α.

In the rest of this section, we present the proof of Theorem 19. As follows from [7], if mβ‰₯1+⌈nβ‹…(1+n1/k)βŒ‰ then ShortCycleDense⁒(G,k) returns in O⁒(min⁑{m,n1+1/k}) time a C≀2⁒k. We now consider the case in which m<1+⌈nβ‹…(1+n1/k)βŒ‰. We prove in the full version of this paper [10] that SpecialCases⁒(G,k,Ξ±) satisfies the claim of Theorem 19, when kβ‰₯n2 or k<Ξ±.

Our main technical contribution is algorithm ShortCycleSparse that handles the case of α≀k<n2. Notice that if |EuΞ±βˆ’1|<mΞ±βˆ’1k+1 for every u∈V, then AllVtxBallOrCycle⁒(G,Ξ±) is a (2⁒k,2⁒α)-hybrid algorithm that either finds a C≀2⁒α (which is also a C≀2⁒k as α≀k) or determines that g>2⁒α, in O⁒(m1+Ξ±βˆ’1k+1) time. Thus, in ShortCycleSparse we ensure that if we call AllVtxBallOrCycle, the property that |EuΞ±βˆ’1|<mΞ±βˆ’1k+1, for every u∈V (whp), holds. To do so, we run BfsSample and possibly HandleRemainder. If no cycle was returned, the property holds, and we can safely run AllVtxBallOrCycle.

ShortCycleSparse (pseudo-code in [10]) gets a graph G and two integers Ξ±,kβ‰₯2 such that α≀k<n2, and is composed of three stages. In the first stage we call BfsSample⁒(G,k,Ξ±) (described later). If BfsSample returns a cycle C then ShortCycleSparse stops and returns C, otherwise we proceed to the second stage. In the second stage, if (k+1)mod(Ξ±βˆ’1)β‰ 0, we call HandleRemainder⁒(G,k,Ξ±) (also described later). If HandleRemainder returns a cycle C then ShortCycleSparse stops and returns C, otherwise we proceed to the last stage. In the last stage, we call AllVtxBallOrCycle⁒(G,Ξ±). If AllVtxBallOrCycle returns a cycle C then 2⁒k-Hybrid stops and returns C, otherwise ShortCycleSparse returns null.

Next, we give a high level description of BfsSample. The goal of BfsSample is to either sparsify the graph without removing any C≀2⁒α, or to report a C≀2⁒k. For simplicity assume that (k+1)mod(Ξ±βˆ’1)=0. In such a case, if BfsSample does not report a C≀2⁒k, then the graph after BfsSample ends contains every C≀2⁒α that was in the original graph, and satisfies, whp, the following sparsity property: For every u∈V it holds that |EuΞ±βˆ’1|<mΞ±βˆ’1k+1.

This implies that in BfsSample we need to find every u∈V which is in a dense region with |EuΞ±βˆ’1|β‰₯mΞ±βˆ’1k+1, and to check if u is in a C≀2⁒α, so that if not we can remove u. Finding every such u is possible within the time limit by running IsDense⁒(G,u,mΞ±βˆ’1k+1,Ξ±βˆ’1) for every u∈V. The problem is that checking whether u is on a C≀2⁒α for every such u is too costly since there might be n such vertices, and this check costs O⁒(n) using BallOrCycle⁒(G,u,Ξ±).

One way to overcome this problem is to sample an edge set S of size Θ~⁒(m1βˆ’Ξ±βˆ’1k+1) that hits the mΞ±βˆ’1k+1 closest edges of each vertex, and then use S to detect the vertices in the dense regions that are not on a C≀2⁒α. In BfsSample we use a detection process in which we call BallOrCycle or NbrBallOrCycle from the endpoints of S’s edges, and then, if no cycle was found, we use the information obtained from this call to identify vertices that are not on a C≀2⁒α. The detection process either detects vertices that are not on a C≀2⁒α and can be removed, or reports a C≀2⁒k. However, it is not clear how to implement this detection process efficiently, since just running BallOrCycle from the endpoints of S’s edges takes O⁒(n⁒m1βˆ’Ξ±βˆ’1k+1) time which might be too much. Our solution is an iterative sampling procedure that starts with a smaller hitting set of edges, of size Θ~⁒(mΞ±βˆ’1k+1). For such a hitting set we can run our detection process. If a C≀2⁒k was not reported, then we remove the appropriate vertices and sparsify the graph without removing any C≀2⁒α. When the graph is sparser, the running time of our detection process becomes faster. Thus, in the following iteration we can sample a larger hitting set for which we run this process, and either return a C≀2⁒k or sparsify the graph further for the next iteration. We continue the iterative sampling procedure until we get to the required sparsity property in which |EuΞ±βˆ’1|<mΞ±βˆ’1k+1 for every u∈V (whp).

We remark that in the first iteration of BfsSample, the detection process calls NbrBallOrCycle, while in the rest of the iterations BallOrCycle is called. The use of NbrBallOrCycle allows us, in the case that no C≀2⁒k is reported, to bound |Evd| with mdk+1 for every v∈V, rather than |Evdβˆ’1|. This is used to achieve the required sparsity property. Since NbrBallOrCycle runs in O⁒(m) time we can only use it in the first iteration when the sampled set is small enough. In the rest of the iterations we use BallOrCycle instead.

Algorithm 3 BfsSample⁒(G,k,α).

We now formally describe BfsSample. BfsSample (see Algorithm 3) gets a graph G and two integers Ξ±,kβ‰₯2 such that α≀k<n2. We first set y to ⌈k+1Ξ±βˆ’1βŒ‰βˆ’1. Then, we start the main for loop that has at most y iterations. In the ith iteration, we initialize V^ to βˆ… and sample a set SiβŠ†E of size Θ~⁒(miβ‹…(Ξ±βˆ’1)k+1). Next, we scan the endpoints in V⁒(Si) using an inner for-each loop.

If i=1, we call NbrBallOrCycle⁒(G,s,k,α) from every endpoint s∈V⁒(S1). NbrBallOrCycle returns either a cycle or a set of vertices U^. If NbrBallOrCycle returns a cycle then the cycle is returned by BfsSample. Otherwise, we add U^ to V^.

If i>1 then we call BallOrCycle⁒(s,ki), where ki=(k+1)βˆ’(iβˆ’1)β‹…(Ξ±βˆ’1), from every endpoint s∈V⁒(Si). If a cycle is found by BallOrCycle then the cycle is returned by BfsSample. If BallOrCycle does not return a cycle then we add Vujkiβˆ’Ξ± to V^.

Right after the inner for-each loop ends, we remove V^ from G, and continue to the next iteration of the main for loop. If no cycle was found after y iterations, we return null. Let ℓ≀y be the last iteration in which vertices were removed. Let Vi^ be the set of vertices that were removed during the ith iteration, where Vi^=βˆ… for i>β„“. Let G0 (G1) be G before (after) running BfsSample. The relevant figures in the full version of this paper [10] illustrate the key steps of the first and the following iterations of BfsSample. We summarize the properties of BfsSample in the next lemma. The proof is also given in the full version [10].

Lemma 21.

BfsSample⁒(G,k,α) satisfies the following:

  1. (i)

    If a cycle C is returned then w⁒t⁒(C)≀2⁒k

  2. (ii)

    If a cycle is not returned then |Eu(k+1)βˆ’yβ‹…(Ξ±βˆ’1)|<m1βˆ’yβ‹…(Ξ±βˆ’1)k+1, for every u∈G1, whp

  3. (iii)

    If u∈G0βˆ–G1 then u is not part of a C≀2⁒α in G0

  4. (iv)

    BfsSample⁒(G,k,Ξ±) runs in O~⁒(⌊k+1Ξ±βˆ’1βŒ‹β‹…m1+Ξ±βˆ’1k+1) time, whp.

Recall that our goal is to obtain the sparsity property that |EuΞ±βˆ’1|<mΞ±βˆ’1k+1, for every u∈V, so that we can run AllVtxBallOrCycle⁒(G,Ξ±). However, after running BfsSample the required sparsity property is guaranteed to hold (whp) only if (k+1)mod(Ξ±βˆ’1)=0. In the case that (k+1)mod(Ξ±βˆ’1)β‰ 0 we need an additional step which is implemented in HandleRemainder, to guarantee that the required sparsity property holds.

Algorithm 4 HandleRemainder⁒(G,k,α).
Figure 3: The relation between ri, ri+1 and Ξ±βˆ’1.

Next, we formally describe HandleRemainder. HandleRemainder (see Algorithm 4) gets a graph G and two integers Ξ±,kβ‰₯2 such that k+1=q⁒(Ξ±βˆ’1)+r where qβ‰₯1 and r>0. We set D to m1k+1 and r to (k+1)mod(Ξ±βˆ’1). Then, a while loop runs as long as (Ξ±βˆ’1)modrβ‰ 0. Let ri be the value of r when the ith iteration begins, so that r1 is (k+1)mod(Ξ±βˆ’1). Let β„“ be the total number of iterations and rβ„“+1 the value of r after the β„“th iteration. During the ith iteration, we set ri+1 to (βŒˆΞ±βˆ’1riβŒ‰β‹…ri)βˆ’(Ξ±βˆ’1), where βŒˆΞ±βˆ’1riβŒ‰β‹…ri is the smallest multiple of ri that is at least Ξ±βˆ’1 (see Figure 3). Then, we call SparseOrCycle⁒(G,D,ri+1,Ξ±). If SparseOrCycle returns a cycle C then HandleRemainder returns C. If SparseOrCycle does not return a cycle then it might be that some vertices were removed from G, and we continue to the next iteration. If the while loop ends without returning a cycle then we return null. Let G0 (G1) be G before (after) running HandleRemainder. Next, we prove two properties on the value of r during the run of HandleRemainder (see the full version of this paper [10] for the proof).

Claim 22.

Let k+1=q⁒(Ξ±βˆ’1)+r1 and assume r1>0. (i) 0<rβ„“+1<rβ„“<β‹―<r1<Ξ±βˆ’1. (ii) (ri+1+Ξ±βˆ’1)modri=0, for every 1≀i≀ℓ.

We also prove in the full version [10] the main lemma regarding HandleRemainder.

Lemma 23.

Let k+1=q⁒(Ξ±βˆ’1)+r1 and assume that r1>0, qβ‰₯1, and that |Eur1|<Dr1, for every u∈V. HandleRemainder⁒(G,k,Ξ±) satisfies the following:

  1. (i)

    If a cycle C is returned then w⁒t⁒(C)≀2⁒k

  2. (ii)

    If a cycle is not returned then |EuΞ±βˆ’1|<DΞ±βˆ’1, for every vertex u∈G2

  3. (iii)

    If u∈G1βˆ–G2 then u is not on a C≀2⁒α in G1

  4. (iv)

    HandleRemainder⁒(G,k,Ξ±) runs in O⁒(r1β‹…m1+Ξ±βˆ’1k+1) time.

Now we are ready to prove the correctness and running time of ShortCycleSparse. The proof is in the full version [10].

Lemma 24.

Let 2≀α≀k<n2 such that k+1=q⁒(Ξ±βˆ’1)+r, where qβ‰₯1 and 0≀r<Ξ±βˆ’1 are integers. Algorithm ShortCycleSparse⁒(G,k,Ξ±) runs whp in O~⁒((q+r)β‹…m1+Ξ±βˆ’1k+1) time and either returns a C≀2⁒k, or determines that g>2⁒α.

Since ShortCycleSparse is run by ShortCycle when m≀O⁒(n1+1k) and when α≀k and so 1+Ξ±βˆ’1k+1≀2, we have m1+Ξ±βˆ’1k+1≀O⁒(n1+Ξ±k). Thus, the running time of ShortCycleSparse is whp O~⁒((q+r)β‹…min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}), which is at most O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k}). Together with the relatively simple special cases handled in the full version of this paper [10], this completes the proof of Theorem 19.

7 Approximation of the girth

In this section we present two new tradeoffs for girth approximation that follow from Corollary 20. In these tradeoffs we use ShortCycle with 2≀α≀k, so by Corollary 20, ShortCycle is an O~⁒((k+1Ξ±βˆ’1+Ξ±)β‹…min⁑{m1+Ξ±βˆ’1k+1,n1+Ξ±k})-time, (2⁒k,2⁒α)-hybrid algorithm.

7.1 Dense graphs

Kadria et al. [7] presented an O⁒((Ξ±βˆ’c)β‹…n1+Ξ±2β’Ξ±βˆ’c)-time, (4β’Ξ±βˆ’2⁒c,2⁒α)-hybrid algorithm, where 0<c≀α are two integers (see footnote 3 in Section 2). This algorithm, combined with a binary search, was used by [7] to compute for every Ρ∈(0,1] a cycle C such that w⁒t⁒(C)≀4⁒⌈g2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹β‰€(2βˆ’Ξ΅)⁒g+4, in O~⁒(n1+1/(2βˆ’Ξ΅)) time, if g≀log2⁑n. We use ShortCycle in a similar way and prove:

Theorem 25.

Let β„“β‰₯2 be an integer, Ρ∈[0,1] and g≀log2⁑n. It is possible to compute, whp, in O~⁒(β„“β‹…n1+1/(β„“βˆ’Ξ΅)) time, a cycle C such that w⁒t⁒(C)≀2β’β„“β’βŒˆg2βŒ‰βˆ’2⁒⌊Ρ⁒⌈g2βŒ‰βŒ‹β‰€(β„“βˆ’Ξ΅)⁒g+β„“+2.999We note that when β„“>log⁑n, we can run the O~⁒(n1+1/β„“β€²)-time algorithm of [7], which computes a C≀2β’β„“β€²β’βŒˆg/2βŒ‰, with β„“β€²=β„“βˆ’1, to get the required approximation. Since β„“>log⁑n, its running time is O~⁒(n). Thus, our running time becomes O~⁒(n1+1/(β„“βˆ’Ξ΅)), where the β„“ factor is absorbed into the O~ notation.

The proof is in the full version of this paper [10]. Our algorithm can be viewed as a natural generalization of a couple of algorithms from [7]. By setting β„“=2 in Theorem 25 we get the (2βˆ’Ξ΅)⁒g+4 approximation of [7]. By setting Ξ΅=0 we get an O~⁒(β„“β‹…n1+1/β„“) time algorithm that computes a C≀2β’β„“β’βŒˆg2βŒ‰, which is similar to the O~⁒(n1+1/β„“) time algorithm of [7] that computes a C≀2β’β„“β’βŒˆg2βŒ‰.

7.2 Sparse graphs

We use a similar approach to obtain a tradeoff for girth approximation in sparse graphs. We prove the following theorem in the full version of this paper [10].

Theorem 26.

Let β„“β‰₯3 be an integer, Ρ∈[0,1) and g≀log2⁑n. It is possible to compute, whp, in O~⁒(β„“β‹…m1+1/(β„“βˆ’Ξ΅)) time, a cycle C such that w⁒t⁒(C)≀2⁒ℓ⁒(⌈g2βŒ‰βˆ’1)βˆ’2⁒⌊Ρ⁒(⌈g2βŒ‰βˆ’1)βŒ‹βˆ’2≀(β„“βˆ’Ξ΅)⁒gβˆ’β„“+2⁒Ρ.

By setting Ξ΅=0 we get an O~⁒(β„“β‹…m1+1/β„“)-time algorithm that computes a C≀2⁒ℓ⁒(⌈g2βŒ‰βˆ’1)βˆ’2, as opposed to the O~⁒(β„“β‹…n1+1/β„“) time algorithm that computes a C≀2β’β„“β’βŒˆg2βŒ‰.

References

  • [1] Donald Aingworth, Chandra Chekuri, Piotr Indyk, and Rajeev Motwani. Fast estimation of diameter and shortest paths (without matrix multiplication). SIAM Journal on Computing, 28(4):1167–1181, 1999. doi:10.1137/S0097539796303421.
  • [2] Shiri Chechik, Yang P. Liu, Omer Rotem, and Aaron Sidford. Constant girth approximation for directed graphs in subquadratic time. In Proccedings of the 52nd Annual ACM SIGACT Symposium on Theory of Computing, STOC 2020, Chicago, IL, USA, June 22-26, 2020, pages 1010–1023. ACM, 2020. doi:10.1145/3357713.3384330.
  • [3] SΓΈren Dahlgaard, Mathias BΓ¦k Tejs Knudsen, and Morten StΓΆckel. Finding even cycles faster via capped k-walks. In Hamed Hatami, Pierre McKenzie, and Valerie King, editors, Proceedings of the 49th Annual ACM SIGACT Symposium on Theory of Computing, STOC 2017, Montreal, QC, Canada, June 19-23, 2017, pages 112–120. ACM, 2017. doi:10.1145/3055399.3055459.
  • [4] SΓΈren Dahlgaard, Mathias BΓ¦k Tejs Knudsen, and Morten StΓΆckel. New subquadratic approximation algorithms for the girth. arXiv preprint arXiv:1704.02178, 2017. arXiv:1704.02178.
  • [5] Zvi Galil and Oded Margalit. All pairs shortest distances for graphs with small integer length edges. Information and Computation, 134(2):103–139, 1997. doi:10.1006/INCO.1997.2620.
  • [6] Alon Itai and Michael Rodeh. Finding a minimum circuit in a graph. In Proceedings of the ninth annual ACM symposium on Theory of computing, pages 1–10, 1977.
  • [7] Avi Kadria, Liam Roditty, Aaron Sidford, Virginia Vassilevska Williams, and Uri Zwick. Algorithmic trade-offs for girth approximation in undirected graphs. In Proceedings of the 2022 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1471–1492. SIAM, 2022. doi:10.1137/1.9781611977073.62.
  • [8] Andrzej Lingas and Eva-Marta Lundell. Efficient approximation algorithms for shortest cycles in undirected graphs. Information Processing Letters, 109(10):493–498, 2009. doi:10.1016/J.IPL.2009.01.008.
  • [9] Liam Roditty and Roei Tov. Approximating the girth. ACM Transactions on Algorithms (TALG), 9(2):1–13, 2013. doi:10.1145/2438645.2438647.
  • [10] Liam Roditty and Plia Trabelsi. New algorithms for girth and cycle detection. arXiv preprint arXiv:2507.02061, 2025. doi:10.48550/arXiv.2507.02061.
  • [11] Liam Roditty and Virginia Vassilevska Williams. Fast approximation algorithms for the diameter and radius of sparse graphs. In Proceedings of the forty-fifth annual ACM symposium on Theory of computing, pages 515–524, 2013. doi:10.1145/2488608.2488673.
  • [12] Liam Roditty and Virginia Vassilevska Williams. Subquadratic time approximation algorithms for the girth. In Proceedings of the Twenty-Third Annual ACM-SIAM Symposium on Discrete Algorithms, pages 833–845. SIAM, 2012. doi:10.1137/1.9781611973099.67.
  • [13] Raimund Seidel. On the all-pairs-shortest-path problem in unweighted undirected graphs. Journal of computer and system sciences, 51(3):400–403, 1995. doi:10.1006/JCSS.1995.1078.
  • [14] Avi Shoshan and Uri Zwick. All pairs shortest paths in undirected graphs with integer weights. In 40th Annual Symposium on Foundations of Computer Science (Cat. No. 99CB37039), pages 605–614. IEEE, 1999. doi:10.1109/SFFCS.1999.814635.
  • [15] Virginia Vassilevska Williams and R. Ryan Williams. Subcubic equivalences between path, matrix, and triangle problems. J. ACM, 65(5):27:1–27:38, 2018. doi:10.1145/3186893.
  • [16] Virginia Vassilevska Williams, Yinzhan Xu, Zixuan Xu, and Renfei Zhou. New bounds for matrix multiplication: from alpha to omega. In Proceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 3792–3835. SIAM, 2024. doi:10.1137/1.9781611977912.134.