New Algorithms for Girth and Cycle Detection
Abstract
Let be an unweighted undirected graph with vertices and edges. Let be the girth of , that is, the length of a shortest cycle in . We present a randomized algorithm with a running time of that returns a cycle of length at most , where is an integer and , for every graph with .
Our algorithm generalizes an algorithm of Kadria et al. [SODAβ22] that computes a cycle of length at most in time. Kadria et al. presented also an algorithm that finds a cycle of length at most in 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 time randomized algorithm that returns a cycle of length at most , where is an integer and , for every graph with .
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 -time, -approximation of . The second is used to obtain our -time and -time approximation algorithms.
Keywords and phrases:
Graph algorithms, All pairs shortest path, Girth, Cycle approximationFunding:
Liam Roditty: Supported in part by BSF grants 2016365 and 2020356.Copyright and License:
2012 ACM Subject Classification:
Theory of computation Graph algorithms analysisEditor:
Pierre FraigniaudSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl β Leibniz-Zentrum fΓΌr Informatik
1 Introduction
Let be an unweighted undirected graph with vertices and edges. A set of vertices in , where , is a cycle of length if and , for every . A is a cycle of length at most . The girth of is the length of a shortest cycle in . 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 time or in time, where [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 (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 of (where and ), satisfies . We denote an approximation as an -approximation if and as a -approximation if .
Itai and Rodeh [6] presented a -approximation algorithm that runs in time. Notice that in contrast to the BMM or APSP problems, where a running time of is inevitable since the output size is , 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 -approximation algorithm that runs in time, and Roditty and V. Williams [12] presented a -approximation algorithm that runs in 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 in time. The other computes, whp, a , for any integer , in time.
Kadria et al. [7] significantly improved upon the second algorithm of [4] and presented an algorithm, that for every integer , computes a in time. They also presented an algorithm, that for every , computes a cycle of length at most , in time, for every graph with .
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 , using some algorithm that gets as an input an integer which is a guess for the value of . In each step of the search either returns a cycle , where is a non decreasing function, or determines that . The goal of the search is to find the smallest , for which returns a cycle, because for this value we have (and thus ), and algorithm returns a . This cycle is of length at most since and is a non decreasing function ( can represent the approximation, for example yields a -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 or determines that .
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 -hybrid algorithms. Additionally, for every integer , they presented a -hybrid and a -hybrid algorithms that run in time, and a -hybrid algorithm that runs in time. Therefore, for , and , there is a -hybrid algorithm that runs in 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 and be two integers and let . Is it possible to obtain a -hybrid algorithm that runs in time?
In this paper we present a -hybrid algorithm that runs, whp, in time, for every . This algorithm provides an affirmative answer to Problem 1.1, albeit the factor in the running time.
Kadria et al. [7] presented also a -hybrid algorithm whose running time is , for every integer . The running time of our algorithm when is . We improve the running time for every constant , in the case of (when the two algorithms run a similar procedure and thus have the same asymptotic running time).
Using our -hybrid algorithm we obtain a generalization of the time algorithm of Kadria et al. [7] that computes a cycle of length at most , for every graph with . Our generalized algorithm runs in time, whp, and returns a cycle of length at most , where is an integer and , for every graph with . We also show that if the graph is sparse then the approximation can be improved. More specifically, we present an algorithm that runs in time, whp, and returns a cycle of length at most , where is an integer and , for every graph with .
| Time [3pt] exp | Cycle bound | |
|---|---|---|
Our -time algorithm also generalizes the -time algorithm of Kadria et al. [7], which computes a for every integer . 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 , up to additional tradeoff points are added.111Up to tradeoff points are added since for every such , when is a multiple of , we get an -time algorithm which computes a . For example, consider and a graph with girth or . Our algorithm yields two additional points on the tradeoff curve, corresponding to and . For , we compute a in time, and for , we compute a in 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 in time or a in 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 ). 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 -hybrid algorithm and then use it to obtain a -approximation algorithm for the girth. In Section 6 we generalize the -hybrid algorithm and present a -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 is not on a , then for any two neighbors and of , the set of vertices at distance exactly from and that are also at distance from are disjoint (see Figure 2). This allows us to check efficiently for all the neighbors of if they are on a . Using this technique, together with more tools that we develop, we obtain two hybrid algorithms.
The first is a relatively simple -time, -hybrid algorithm. We use this hybrid algorithm in the girth approximation framework described earlier, to obtain an -time, -approximation of the girth, where or (the running time can also be written as ). We remark that using an algorithm of [3] for detection, it is possible to obtain a -approximation in time (see Section 5.2 for more details). However, the additional factor might be significant even for small values of .
The second is the -hybrid algorithm that solves Problem 1.1. Its main component is an -hybrid algorithm that runs in -time, whp, and generalizes the first -time -hybrid algorithm, by introducing an additional parameter . Using we can tradeoff between the running time and the lower bound on and obtain a faster running time at the price of a worse lower bound.
We compare our -hybrid algorithm to algorithm Cycle of Kadria et al. [7], an -time,222Cycle runs in time, which can be reduced to time, as shown in [7]. -hybrid algorithm, where , that they used to obtain the -time, -approximation algorithm. As we show later, the running time of our -hybrid algorithm can be bounded by . Since in our algorithm 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 , when the value of is a constant known in advance, our algorithm can return longer cycles that are still shorter than , in a faster running time.333[7] presented also an -time, -hybrid algorithm, where are integers. For , this is an -time, -hybrid algorithm, similar to our -hybrid algorithm. However, since , the possible values of are restricted and must satisfy . By choosing and an appropriate the two algorithms have a similar flexibility for a -approximation, but since in our algorithm also larger values of are allowed, we can achieve a faster running time for a -approximation where .
The flexibility of our algorithm is also demonstrated as follows. For a given constant value of , if our -hybrid algorithm returns a cycle then its length is at most . If we want algorithm Cycle to output a , then is the largest that we can choose, since must be an integer. The running time is . Our algorithm achieves a better running time if is not divisible by . (See the relevant figures in the full version of this paper [10] for a comparison).
Next, we overview our -hybrid algorithm that either finds a or determines that in time. In order to determine that , we can check for every if is on a (and either find a since , or return that ). If is on a , then all the vertices and edges of this are at distance at most from . If, for every , the number of edges at distance at most is then using standard techniques we can check for every if is on a in 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 . 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 and its neighbors are on a , we check whether all the vertices up to a possibly further distance from are on a , for , and if not we mark them so that they can be removed later.
If the iterative sampling procedure ends without finding a then there are two possibilities. Let . If then it holds that the number of edges at distance at most from every is , whp, as required. If then it holds that the number of edges at distance at most from every is , whp. This does not necessarily imply that the graph is sparse enough for checking whether . 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 is and checking whether is possible within the required running time of .
3 Preliminaries
Let be an unweighted undirected graph with vertices and edges. Let be a set of vertices and let be the graph obtained from by deleting all the vertices of together with their incident edges. For two graphs and , let be . We say that if and . For convenience, we use both and to say that . For every , let be the length of a shortest path between and in . The girth of is the length of a shortest cycle in . Let be the length of a cycle . For an integer , we denote a cycle of length (at most) by () .444Both and might not be simple cycles. However, the cycles that our algorithms return are simple. Let be the edges incident to and the th edge in . Let be the degree of in . Let be the set of neighbors of , namely . For an edge set , let be the endpoints of βs edges, that is, . Let and . The distance between and is . For every and a real number let be the ball graph of , where and [7]. For an integer and a vertex , Let .555When the graph is clear from the context, we sometimes omit 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 .
Lemma 2 ([7]).
Let be two integers and let . If is a tree then no vertex in is part of a cycle of length at most in .
We use procedure [7, 8] (pseudo-code in [10]) that searches for a in the ball graph . We summarize BallOrCycleβs properties in the next lemma.
Lemma 3 ([7]).
Let . If the ball graph is not a tree then returns a from . If is a tree then returns .666If is returned then we assume that is ordered by the distance from , and for every we store with . Thus, given the set , we can find for every in time. The running time of is .
Next, we obtain a simple -hybrid algorithm, called AllVtxBallOrCycle, using BallOrCycle. AllVtxBallOrCycle (pseudo-code in [10]) gets a graph and an integer , and runs from every 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].
Lemma 4.
either finds a or determines that , in time.
We now show that if the input graph satisfies a certain sparsity property then the running time of can be bounded as follows.
Corollary 5.
If for every then runs in time.
Proof.
For every , we have , which is at most . Thus, by Lemma 4, the running time of is .
Next, we present procedure from [7]. IsDense (pseudo-code in [10]) gets a graph , a vertex , a budget (real) and a distance (integer). In the procedure a BFS is executed from . The BFS counts the edges that are scanned as long as their total number is less than and the farthest vertex from is at distance at most .
Lemma 6 ([7]).
Procedure runs in time. If then . If then .
Given a vertex and a distance we sometimes want to bound . 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 be positive integers, let be a real number, and let . If , and for every , then .
Corollary 8.
Let be a positive integer and let be a real number. If for every , then , for every and .
We also adapt procedure of [7] to our needs. SparseOrCycle (see Algorithm 1) gets a graph , a parameter , and two integers , and iterates over vertices using a for-each loop. Let be the vertex currently considered and the current graph. If then is called. If BallOrCycle returns a cycle then is returned by SparseOrCycle. Otherwise, the vertex set is removed from along with the edge set . After the loop ends, if no cycle was found, we return null. Let be the set of vertices for which BallOrCycle was called and no cycle was found, and 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.
satisfies the following:
-
(i)
If a cycle is returned then
-
(ii)
If a cycle is not returned then , for every
-
(iii)
If then is not part of a in
-
(iv)
runs in time.
Similarly to AllVtxBallOrCycle, we show for SparseOrCycle that if satisfies a certain sparsity property, the running time can be bounded as follows. The proof is in the full version [10].
Corollary 10.
If for every vertex then runs in time.
Lemma 11.
It is possible to obtain in time, using sampling, a set of edges of size , that hits, whp, the closest edges of every .
We remark that some of our algorithms get a graph that is being updated during their run. Within their scope, 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 is not on a , to check efficiently whether any neighbor of lies on a .
Consider a vertex . It is straightforward to check whether is on a , for every integer , using in time. If does not return a then for every it holds that , where , as otherwise there was a passing through and would have returned a (see Figure 2). We show that it is possible to exploit this property to check for every whether is on a , using , in time instead of . More specifically, we present algorithm (see Algorithm 2) that gets a graph , a vertex , and an integer . We first initialize to . Then, we run . If a cycle is found by then is returned by NbrBallOrCycle. Otherwise, we add the vertex to , keep the neighbors of in , and then remove from . Recall that equals . Next, for every we run , as long as a cycle is not found. If a cycle is returned by then is returned by NbrBallOrCycle.777For our needs it suffices to stop and return a cycle passing through an neighbor once we find one, though BallOrCycle can be run from all the neighbors of in the same running time bound of . Otherwise, is added to . After the loop ends, the vertex and its adjacent edges are added back to the graph, and the set is returned by NbrBallOrCycle. We prove the following lemma in the full version of this paper [10].
Lemma 12.
If algorithm finds a cycle then . Otherwise, no vertex in is part of a in , and the set is returned.
To bound the running time of NbrBallOrCycle, we show how to use the fact that no was found by , to efficiently run for every .
Lemma 13.
Let . If the ball graph is a tree then the total cost of running for every is .
Proof.
By the definitions of , and , we know that and . Since contains no cycles it follows that and , for any two distinct vertices . Therefore, (i) , and (ii) . From Lemma 3 it follows that the total cost of the calls to for every is . It holds that , for every . Thus, we get that the total cost is . This equals to , and it follows from (i) and (ii) that this is at most .
We use Lemma 13 to bound the running time of NbrBallOrCycle.
Lemma 14.
Algorithm NbrBallOrCycle runs in time.
Proof.
Running costs . If a cycle is found, it is returned and the running time is . If no cycle is found, then removing (and later adding back) and its edges costs . By Lemma 13, the cost of running for every is . Adding and to takes time. Thus, the total running time of NbrBallOrCycle is .
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 -hybrid algorithm that in time, either returns a or determines that . Then, we use the -hybrid algorithm to compute a -approximation of .
5.1 A -hybrid algorithm
We first present algorithm that gets a graph and an integer . Let () be before (after) running -SparseOrCycle. either finds a or removes vertices that are not on a , such that for every , the ball graph is relatively sparse, that is, . -SparseOrCycle (pseudo-code in [10]) iterates over vertices using a for-each loop. Let be the vertex currently considered. If then is called. If NbrBallOrCycle returns a cycle then -SparseOrCycle returns . If NbrBallOrCycle returns a vertex set then is removed from . After the loop ends, if no cycle was found, we return null.
Β Remark.
Notice that either finds a or removes vertices that are not on a , such that for every it holds that . Using NbrBallOrCycle instead of BallOrCycle in -SparseOrCycle enables us in the case that a cycle is found to bound the cycle length with rather than , while still maintaining the property that , for every , in the case that no cycle is found.
We prove the following lemma in the full version of this paper [10].
Lemma 15.
satisfies the following:
-
(i)
If a cycle is returned then
-
(ii)
If a cycle is not returned then , for every
-
(iii)
If then is not part of a in
-
(iv)
runs in time.
Next, we use -SparseOrCycle to design a -hybrid algorithm called -Hybrid. Notice first that if for every , then it is straightforward to obtain an -time -hybrid algorithm, by running . Thus, in -Hybrid we ensure that if we call AllVtxBallOrCycle then it holds for every that . To do so, we run -SparseOrCycle and possibly SparseOrCycle. If no cycle was returned then we have for every , and we can safely run AllVtxBallOrCycle.
-Hybrid (pseudo-code in [10]) gets a graph and an integer . -Hybrid is composed of three stages. In the first stage we call . If -SparseOrCycle returns a cycle then -Hybrid stops and returns , otherwise we proceed to the second stage. In the second stage, if , we call . If SparseOrCycle returns a cycle then -Hybrid stops and returns , otherwise we proceed to the last stage. In the last stage, we call . If AllVtxBallOrCycle returns a cycle then -Hybrid stops and returns , otherwise -Hybrid returns null. We prove the next lemma in the full version of this paper [10].
Lemma 16.
either returns a or determines that , in time.
5.2 A -approximation of the girth
Next, we describe algorithm AdtvGirthApprox, which uses -Hybrid and the framework described in Section 1, to obtain a -approximation of , when . AdtvGirthApprox (pseudo-code in [10]) gets a graph . In AdtvGirthApprox, we set to and start a while loop. In each iteration, we create a copy of and call . If -Hybrid finds a cycle then AdtvGirthApprox stops and returns , otherwise we increment by and continue to the next iteration. We prove the following theorem in the full version of this paper [10].
Theorem 17.
Algorithm returns either a or a , and runs in time, where or and .888We note that when , the -time, -approximation of Itai and Rodeh [6] can be used.
Β Remark.
Dahlgaard, Knudsen and StΓΆckel [3] showed that a , if exists, can be found in time. It is possible to use their detection algorithm to obtain a -approximation for the girth in time, where or , as mentioned in Section 2. This -approximation is obtained as follows. We run the detection algorithm with increasing values of , starting with . If a is detected we stop and return the detected cycle. In such a case is a -approximation for the girth. If there is no then it follows from the analysis of [3] that a , if exists, can be detected within the same running time using a slight modification of their algorithm. If a is detected we stop and return the detected cycle. In such a case is the girth. If neither a nor a is found we increment by . Since a cycle must be found when , we obtain a -approximation for the girth in time, where or .
A disadvantage of the algorithm described above is the factor which in our new algorithm does not exist. To better appreciate our contribution we compare our -Hybrid algorithm (for detection) and the algorithm of [3] (for 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 -time detection algorithm from each high degree vertex (vertex of degree ). If a is found then a 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 edges up to distance rather than . This is possible using our NbrBallOrCycle algorithm, since we can search for a from a vertex and also its neighbors in time. If a is found then a is returned, otherwise the vertex and its neighbors are removed (therefore also the edges up to distance 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 then the number of capped -walks (walks of length that visit only nodes according to a fixed ordering) in the graph is bounded by , where the 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 in these graphs efficiently. In our algorithm, after the sparsification stage it holds that the total number of edges up to distance from all the vertices is bounded by (avoiding the factor), and we can search efficiently for a .
6 A general hybrid algorithm
Algorithm , presented in the previous section, either returns a or determines that , in time. In this section we introduce an additional parameter and present a -hybrid algorithm that either returns a or determines that , in time. In Section 7 we use the -hybrid algorithm to present two tradeoffs for girth approximation.
To obtain the -hybrid algorithm we first extend algorithm NbrBallOrCycle. Then, we use the extended NbrBallOrCycle together with additional tools that we develop to either return a or sparsify dense regions of the graph, so that we can check whether (or return a ) in time, by running .
6.1 Extending NbrBallOrCycle
In algorithm NbrBallOrCycle we mark vertices that can be removed from the graph, by using the property that if did not return a then is not on a . In [7], they introduce an additional parameter and used the following extended version of this property: If did not return a then no vertex of is on a . We use the same approach and modify NbrBallOrCycle to get an additional integer parameter such that . After each call to , where , if no cycle was found we add , instead of , to . 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 . If finds a cycle then . Otherwise, no vertex in is part of a in , and the set is returned.
For the running time, we note that the sets are computed during the execution of , for every for which no cycle was found. Their total size is also , and we can obtain from them the sets and add these sets to in time. Therefore, the modified NbrBallOrCycle also runs in time.
6.2 A -hybrid algorithm
In this section we present a -hybrid algorithm called ShortCycle, where . ShortCycle (pseudo-code in [10]) gets a graph and two integers . If then we run algorithm (pseudo-code in [10]), which is based on algorithm DegenerateOrCycle of [7].
If then the main challenge is when . In this case we run algorithm (described later). The cases that or are relatively simple and are treated by algorithm (see the full version of this paper [10]). We summarize the properties of in the next theorem.
Theorem 19.
Let be integers. runs whp in time and either returns a , or determines that .
The next corollary follows from Theorem 19, when .
Corollary 20.
Let . Algorithm runs whp in time and either returns a , or determines that .
In the rest of this section, we present the proof of Theorem 19. As follows from [7], if then returns in time a . We now consider the case in which . We prove in the full version of this paper [10] that satisfies the claim of Theorem 19, when or .
Our main technical contribution is algorithm ShortCycleSparse that handles the case of . Notice that if for every , then is a -hybrid algorithm that either finds a (which is also a as ) or determines that , in time. Thus, in ShortCycleSparse we ensure that if we call AllVtxBallOrCycle, the property that , for every (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 and two integers such that , and is composed of three stages. In the first stage we call (described later). If BfsSample returns a cycle then ShortCycleSparse stops and returns , otherwise we proceed to the second stage. In the second stage, if , we call (also described later). If HandleRemainder returns a cycle then ShortCycleSparse stops and returns , otherwise we proceed to the last stage. In the last stage, we call . If AllVtxBallOrCycle returns a cycle then -Hybrid stops and returns , 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 , or to report a . For simplicity assume that . In such a case, if BfsSample does not report a , then the graph after BfsSample ends contains every that was in the original graph, and satisfies, whp, the following sparsity property: For every it holds that .
This implies that in BfsSample we need to find every which is in a dense region with , and to check if is in a , so that if not we can remove . Finding every such is possible within the time limit by running for every . The problem is that checking whether is on a for every such is too costly since there might be such vertices, and this check costs using .
One way to overcome this problem is to sample an edge set of size that hits the closest edges of each vertex, and then use to detect the vertices in the dense regions that are not on a . In BfsSample we use a detection process in which we call BallOrCycle or NbrBallOrCycle from the endpoints of β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 . The detection process either detects vertices that are not on a and can be removed, or reports a . However, it is not clear how to implement this detection process efficiently, since just running BallOrCycle from the endpoints of βs edges takes time which might be too much. Our solution is an iterative sampling procedure that starts with a smaller hitting set of edges, of size . For such a hitting set we can run our detection process. If a was not reported, then we remove the appropriate vertices and sparsify the graph without removing any . 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 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 for every (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 is reported, to bound with for every , rather than . This is used to achieve the required sparsity property. Since NbrBallOrCycle runs in 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.
We now formally describe BfsSample. BfsSample (see Algorithm 3) gets a graph and two integers such that . We first set to . Then, we start the main for loop that has at most iterations. In the th iteration, we initialize to and sample a set of size . Next, we scan the endpoints in using an inner for-each loop.
If , we call from every endpoint . NbrBallOrCycle returns either a cycle or a set of vertices . If NbrBallOrCycle returns a cycle then the cycle is returned by BfsSample. Otherwise, we add to .
If then we call , where , from every endpoint . If a cycle is found by BallOrCycle then the cycle is returned by BfsSample. If BallOrCycle does not return a cycle then we add to .
Right after the inner for-each loop ends, we remove from , and continue to the next iteration of the main for loop. If no cycle was found after iterations, we return null. Let be the last iteration in which vertices were removed. Let be the set of vertices that were removed during the th iteration, where for . Let () be 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.
satisfies the following:
-
(i)
If a cycle is returned then
-
(ii)
If a cycle is not returned then , for every , whp
-
(iii)
If then is not part of a in
-
(iv)
runs in time, whp.
Recall that our goal is to obtain the sparsity property that , for every , so that we can run . However, after running BfsSample the required sparsity property is guaranteed to hold (whp) only if . In the case that we need an additional step which is implemented in HandleRemainder, to guarantee that the required sparsity property holds.
Next, we formally describe HandleRemainder. HandleRemainder (see Algorithm 4) gets a graph and two integers such that where and . We set to and to . Then, a while loop runs as long as . Let be the value of when the th iteration begins, so that is . Let be the total number of iterations and the value of after the th iteration. During the th iteration, we set to , where is the smallest multiple of that is at least (see Figure 3). Then, we call . If SparseOrCycle returns a cycle then HandleRemainder returns . If SparseOrCycle does not return a cycle then it might be that some vertices were removed from , and we continue to the next iteration. If the while loop ends without returning a cycle then we return null. Let () be before (after) running HandleRemainder. Next, we prove two properties on the value of during the run of HandleRemainder (see the full version of this paper [10] for the proof).
Claim 22.
Let and assume . (i) . (ii) (, for every .
We also prove in the full version [10] the main lemma regarding HandleRemainder.
Lemma 23.
Let and assume that , , and that , for every . satisfies the following:
-
(i)
If a cycle is returned then
-
(ii)
If a cycle is not returned then , for every vertex
-
(iii)
If then is not on a in
-
(iv)
runs in 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 such that , where and are integers. Algorithm runs whp in time and either returns a , or determines that .
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 , so by Corollary 20, ShortCycle is an -time, -hybrid algorithm.
7.1 Dense graphs
Kadria et al. [7] presented an -time, -hybrid algorithm, where are two integers (see footnote 3 in Section 2). This algorithm, combined with a binary search, was used by [7] to compute for every a cycle such that , in time, if . We use ShortCycle in a similar way and prove:
Theorem 25.
Let be an integer, and . It is possible to compute, whp, in time, a cycle such that .999We note that when , we can run the -time algorithm of [7], which computes a , with , to get the required approximation. Since , its running time is . Thus, our running time becomes , where the factor is absorbed into the 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 in Theorem 25 we get the approximation of [7]. By setting we get an time algorithm that computes a , which is similar to the time algorithm of [7] that computes a .
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 be an integer, and . It is possible to compute, whp, in time, a cycle such that .
By setting we get an -time algorithm that computes a , as opposed to the time algorithm that computes a .
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.
