Manuscript Offprint
arXiv:2610.23698Approximating the Girth of an Undirected, Weighted Graph for Larger Approximation Factors
Abstract
The girth of a weighted undirected graph is defined as the length of a shortest cycle in the graph. In this paper, we give a randomized algorithm to approximate the girth of a graph with vertices and edges to within a factor of for any real . We assume that all edge weights are non-negative. For sufficiently high approximation factors, our algorithm outperforms the state of the art by polylogarithmic factors. Specifically, for approximation factors where , our algorithm gives a runtime of , while instantiating the previous best -approximation algorithms with yields a running time of [6]. Furthermore, the algorithm presented here is conceptually simple, has relatively small constants, eschews single-source shortest path and sparse spanner algorithms, and employs a new technique, which we call “random filtering.” That being said, the basic algorithm returns only a numerical estimate for the girth, rather than a witness cycle.
1 Introduction
The girth of a graph is defined as the length of a shortest cycle. It is a fundamental graph parameter that has been studied algorithmically as far back as the 1970s. A foundational algorithmic treatment of the problem was given by Itai and Rodeh in 1978 [4] in which they gave an algorithm to compute the girth of an unweighted, undirected graph, where is the matrix multiplication exponent. Since then, many advances have been made in computing graph girth. In 2016, Orlin and Sedeno-Noda gave an algorithm for computing the girth of a weighted, directed graph [9]. However, the difficulty of exact girth computation and the inability to break the cubic runtime barrier for combinatorial algorithms have prompted researchers to instead explore approximation algorithms.
The first truly subquadratic multiplicative approximation for unweighted, undirected graphs was given by Lingas and Lundell, whose randomized -time algorithm achieves an 8/3-approximation [8]. Roditty and Vassilevska Williams later obtained the first subquadratic 2-approximation: their deterministic algorithm runs in time [13]. For directed graphs, Pachocki, Roditty, Sidford, Tov, and Vassilevska Williams showed that, for every integer , the girth of a directed graph with nonnegative integer edge lengths can be approximated within a factor of in
time with high probability [10].
Most recently, Kadria, Roditty, and Vassilevska Williams obtained the currently best general time-approximation trade-off for weighted undirected graphs with nonnegative real edge lengths [6]. For every integer , their algorithm computes a -approximation in
time. This matches, up to polylogarithmic factors, the corresponding trade-off previously known for unweighted graphs [5, 12].
Lastly, our algorithm is randomized and works by repeatedly drawing randomly sampled subgraphs of our graph. Our algorithm draws inspiration from other well-known randomized graph algorithms, such as Karger's algorithm [7] and Alon-Yuster-Zwick's color-coding [2]. Indeed, some of these randomized sampling techniques have even been used as subroutines in cycle algorithms before, such as in [1] where they make use of the observation that if each vertex is retained with probability p, then a given triangle is more likely to be in a subgraph than a 4-cycle (by precisely a factor of p).
The key observation underlying our algorithm is that if we sample a random subgraph of G by preserving each edge e independently with probability , where t is some parameter we can tune later, then the probability that a particular cycle appears in this subgraph decreases exponentially with its length. Thus, this sampling procedure strongly favors shorter cycles and can help us estimate the girth by changing the values of t and seeing when cycles start to first appear with this sampling technique. The values of t for which cycles start to appear are strongly controlled by the girth of the graph, allowing us to estimate the value of g. We refer to this technique as “random filtering,” and expect it to be useful for other problems in algorithmic graph theory (after all, this idea of sampling random subgraphs that favor particular “small” structures to appear can be applied to paths, trees, matchings, etc., and not just cycles).
Remark 1 (Changing the parameter s). If we just keep the parameter s constant, we attain a strictly linear time algorithm for approximating the girth of a graph to within a logarithmic factor. By increasing the parameter s, we can improve our approximation factor at the cost of increasing our runtime, while decreasing the parameter s degrades our approximation factor while improving runtime.
1.2 Notation
Throughout this paper, any use of log or ln refers to the natural logarithm (though it usually doesn’t matter since we deal with asymptotics). For any graph , we let represent the set of vertices and represent the set of edges. To denote the weight of each edge, we consider the function that assigns a positive weight to each edge. We assume without loss of generality that all edge weights are strictly positive; if any edge weights are zero, we first check to see if there is a zero-weight cycle. If not, for every zero-weight edge we could simply contract the two vertices connected by said edge without changing the girth of a graph (we preserve all loops and parallel edges in the contraction, so we are technically working with a multi-graph). Additionally, we will use the variable to denote the girth of a graph, and the function to represent the minimum distance between two vertices, . Lastly, we assume that the graph we're working with has and that there are no isolated vertices (we can just delete isolated vertices). For the bounds in terms of , we assume , as holds for simple input graphs; these input sizes are taken before any contractions that create multigraphs.
2 The Algorithm
Algorithm 1 Random filtering with sampling parameter s
Require: An undirected graph with positive edge lengths and parameters and .
Ensure: With probability at least , return where and ; return if is acyclic.
1: function APPROXIMATEGIRTH( )
2: and
3: if contains no cycle then
4: return
5: end if
6:
7:
8:
9:
10: for do
11:
12: end for
13: the -th largest of
14:
15: return
16: end function
The algorithm is described above. The main subroutine doing most of the work is SAMPLETHRESHOLD, though the description of what it's doing is very simple. Essentially, if for each edge, e, in our graph, we let , then we can define to be the subgraph of G created by including all the edges e of G such that . We can then define the random variable T, which is given by
All SAMPLETHRESHOLD does is return one number sampled from the probability distribution of T. Indeed, SAMPLETHRESHOLD can be computed in linear time, giving us a linear-time implementation of our algorithm. The exact method by which we do this is described in Algorithm 2. Note that a naive implementation for SAMPLETHRESHOLD would sample the set where
, and then sort the set from smallest to largest. Afterwards, it would iterate through the set in descending order, adding the edges it is iterating over one by one to an initially edgeless graph until the first cycle appears. However, this takes time, since sorting a set of size takes at most this much time when .
To complete this task in linear time, perform the same sampling as before for each edge. Then find the median of the set , which can be done in linear time [3], and construct the graph . If the number of edges is even, we take the upper median. If has a cycle, then . Otherwise, .
If has a cycle, we may discard every edge such that , since those edges cannot affect the largest threshold at which a cycle exists. We then recurse on the remaining edges.
Now suppose that does not have a cycle, meaning that is a forest. Contract each connected component of into a single vertex, and delete every edge satisfying , since these are precisely the edges of . Retain every edge satisfying , including edges whose endpoints are contracted to the same vertex. Such an edge becomes a self-loop and represents a cycle consisting of that edge together with the unique path between its endpoints in . We must also retain parallel edges, since two parallel edges in the contracted multigraph may represent a cycle in the original graph. Thus, we can now recurse on the contracted graph, in which we now only have half as many edges, to find the value of .
At each step, we recurse on a subgraph that has half as many edges, and each step takes linear time in the number of edges we currently have, so the total amount of time taken is
Algorithm 2 Sampling the critical threshold T in linear time
1: function SAMPLETHRESHOLD(G = (V, E), ) 2: for all do 3: Sample 4: end for 5: return FINDTHRESHOLD(G, X) 6: end function
7: function FINDTHRESHOLD(H = (W, F), X) 8: if then 9: return 10: else if then 11: return if and e is a self-loop; otherwise return 12: end if 13: 14: and 15: if contains a cycle then 16: return FINDTHRESHOLD( , ) 17: else 18: Contract every component of in H, delete , and retain all self-loops and parallel edges; call the result 19: return FINDTHRESHOLD( , ) 20: end if 21: end function
3 Analysis
3.1 Bounding the Probability Distribution
To make our observation in Section 1.1 more rigorous and practical, we first prove Theorem 3.1.
Theorem 3.1. For any undirected, weighted graph , if for each edge we sample a random variable , we let denote the subgraph of created by including all the edges of such that , and we let , then
To prove these bounds, first note that the event is equivalent to the event that contains a cycle. The lower bound is immediate: the probability that contains a cycle is at least the probability that a minimum-weight cycle appears in , which is .
The proof of the upper bound is adapted from proofs for established cycle counting bounds in graphs with high girth [14], and also from cycle-freeness results for randomly sampled subgraphs with high girth [11]. First, note that between any two vertices in our graph, there is at most one simple path of length less than g/2. Indeed, if there were two distinct such paths, their union would contain a cycle of length less than g. Using this fact, for any graph we can non-constructively prove that there is a polynomial-sized collection of paths of length at least such that if were to contain a cycle, then it also must contain one of these paths. To show why such a family exists, note that for any cycle in , we can start at some arbitrary vertex in the cycle, and traverse the edges along the cycle until the distance travelled is at least . We can refer to this segment by , where represents the final edge along the segment and is the initial path along the segment. By construction, we must have that the length of is less than . Now, if the length of is greater than , we are done. Otherwise, we can continue traversing along the cycle until the total accumulated length traversed is at least . We can write this second segment as where the length of is less than and is some edge. Note that and are potentially empty paths. Thus, every cycle has an edge sequence of one of these forms
where the total weight of the edge sequence is at least and and both have length less than . Now, note that there are at most edge sequences of the form . This is because is perfectly specified by the starting vertex of the edge sequence, and the ending edge along with the orientation of the edge (recall that between any two points there is at most one path of length less than between them, so is entirely specified by its starting point and endpoint). There are edges, 2 orientations per edge, and possible starting points, giving the upper bound of . Using similar logic, we get that there are possible edge-sequences of the form , since there are starting points, possibilities for , possibilities for , and 2 possible orientations per edge. This brings the total to possible edge sequences. Thus, if any cycle were to appear in , we must have that at least one of these paths has appeared. The probability of any one of them appearing is at most since their lengths are at least . Thus,
which completes the proof of Theorem 3.1.
3.2 Proving Correctness and Runtime
For ease of notation, we will set in this section. Now, to prove correctness of our algorithm, note that if we choose any and set
then, by the lower bound in Theorem 3.1,
and by the upper bound in Theorem 3.1,
Thus, if we draw independent samples of and let be the -th largest of these samples, then
where we used standard multiplicative Chernoff bounds in the third line.
Thus, if we set , we have that is satisfied with probability at least . Thus, we also have
meaning that if we output
then
as desired.
We already noted that calling SAMPLETHRESHOLD takes linear time. Computing the required order statistic takes time using linear-time selection, so the whole algorithm takes time. In particular, the running time is linear in m for fixed s and .
Remark 2 (A note on finite-precision implementations). So far we have seemingly been assuming that our computer can manipulate real numbers and sample random variables perfectly. This assumption is not necessary for our algorithm to work; indeed, one can implement this algorithm in a word RAM model or even pointer-machine model where the only sacrifice is a small increase in the error probability. For exact details on how this can be done one can simply ask their favorite frontier large language model. However, if we just implement the exponential filtering algorithm using 64-bit float arithmetic, then some back-of-the-envelope calculations reveal that the increase in error probability is negligible. To see this, if we let (a float has 53 bits of significant precision), then we can generate exponential random variables with rate by sampling a uniform value, , in and computing . Assuming our logarithm and division operations are correct to within a relative error , then the rounding errors from this operation only introduce an error of in the CDF of our random variable, and the errors from the discretization of our probability sampling introduce an error of at most in the CDF, meaning we only have an error of in our CDF per sampled random variable. The rest of the rounding errors in our calculations will also incur an error, which is all negligible assuming reasonably sized graphs (i.e., not on the order of ) and edge weights (i.e., no risk of overflow or underflow).
3.3 Tuning the Parameter s
In this subsection we’ll explain how one can tune the parameter s to get a desired approximation ratio. Suppose one wants to approximate the girth of a graph to within a factor k. This means that
Substituting this into our runtime formula yields
Thus, if we then set where is fixed, we get that
where on the first line we used . The final step uses . These guarantees match the ones given in the abstract.
4 Conclusion and Future Directions
We presented an algorithm that can approximate the girth of an undirected, weighted graph to within any factor , though it only improves upon the state of the art algorithms for . Additionally, the algorithm is simple and very easy to implement, while also utilizing a technique not currently used in state-of-the-art algorithms. For future papers, it'd be interesting to apply this random filtering framework to other algorithmic graph theory problems. Namely, it'd be interesting to see if there are other problems in which one can design a random sampling method that heavily favors “small” constructions to appear and then leverage this to compute desired quantities of the graph. It'd also be interesting to explore if the girth approximation algorithm presented in this paper lends itself to more efficient parallelized algorithms. The main bottleneck in this algorithm's runtime is that one needs to draw many random samples from the same distribution, but this could easily be parallelized. Lastly, the main limitation of this algorithm is that it doesn't return a witness cycle. If we let T be defined as in Theorem 3.1, then perhaps we can recover a witness cycle by looking at the weight of the only cycle present in and recording the smallest weight across all our trials. After all, the weight of the cycle in intuitively seems to be a crucial piece of information about our graph, yet it is completely neglected in our algorithm.
Acknowledgments
Many thanks to Professor Vassilevska Williams and Professor Tarjan for helpful questions and discussions related to this research.
AI Acknowledgement. ChatGPT5.6sol (high thinking) was used throughout the development and writing of this paper. The authors developed the paper's core insight and intuition: sampling random subgraphs so that longer cycles are exponentially less likely to appear, and then extracting information from the point at which cycles first begin to occur. ChatGPT5.6sol was used for much of the technical work that followed, including the linear-time implementation of Algorithm 2, the formulation and proof of the upper bound in Theorem 3.1, and the replacement of Bernoulli random variables with exponentially decreasing success probabilities by an equivalent formulation using exponential random variables. The approximation ratio and upper bound in theorem 3.1 was then optimized further by ChatGPT6Astra (Max thinking).
References
[1] Amir Abboud, Karl Bringmann, Seri Khoury, and Or Zamir. "Hardness of approximation in p via short cycle removal: cycle detection, distance oracles, and beyond". In: Proceedings of the 54th Annual ACM SIGACT Symposium on Theory of Computing. 2022, pp. 1487–1500.
[2] Noga Alon, Raphael Yuster, and Uri Zwick. "Color-coding". In: Journal of the ACM (JACM) 42.4 (1995), pp. 844–856.
[3] Manuel Blum, Robert W. Floyd, Vaughan R. Pratt, Ronald L. Rivest, Robert Endre Tarjan, et al. "Time bounds for selection". In: J. Comput. Syst. Sci. 7.4 (1973), pp. 448–461.
[4] Alon Itai and Michael Rodeh. "Finding a Minimum Circuit in a Graph". In: SIAM Journal on Computing 7.4 (Nov. 1978), pp. 413–423. DOI: 10.1137/0207033.
[5] 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). 2022, pp. 1471–1492. DOI: 10.1137/1.9781611977073.62.
[6] Avi Kadria, Liam Roditty, and Virginia Vassilevska Williams. “Tighter Bounds for Weighted and Unweighted Shortest Cycle Approximation”. In: 34th Annual European Symposium on Algorithms (ESA 2026). Leibniz International Proceedings in Informatics (LIPIcs). 2026, 82:1–82:20. ISBN: 978-3-95977-445-1.
[7] David R Karger. “Global min-cuts in RNC, and other ramifications of a simple min-cut algorithm.” In: Soda. Vol. 93. 1993, pp. 21–30.
[8] Andrzej Lingas and Eva-Marta Lundell. “Efficient approximation algorithms for shortest cycles in undirected graphs”. In: Information Processing Letters 109.10 (2009), pp. 493–498.
[9] James B Orlin and Antonio Sedeno-Noda. “An O (nm) time algorithm for finding the min length directed cycle in a graph”. In: Proceedings of the Twenty-Eighth Annual ACM-SIAM Symposium on Discrete Algorithms. SIAM. 2017, pp. 1866–1879.
[10] Jakub Pachocki, Liam Roditty, Aaron Sidford, Roei Tov, and Virginia Vassilevska Williams. "Approximating cycles in directed graphs: Fast algorithms for girth and roundtrip spanners". In: Proceedings of the twenty-ninth annual ACM-SIAM symposium on discrete algorithms. SIAM. 2018, pp. 1374–1392.
[11] Aaron Putterman, Salil Vadhan, and Vadim Zaripov. “Bounded Independence Edge Sampling for Combinatorial Graph Properties”. In: arXiv preprint arXiv:2603.25095 (2026).
[12] Liam Roditty and Plia Trabelsi. "New Algorithms for Girth and Cycle Detection". In: arXiv preprint arXiv:2507.02061 (2025).
[13] 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. SODA '12. Philadelphia, PA, USA: Society for Industrial and Applied Mathematics, 2012, pp. 833–845. DOI: 10.5555/2095116.2095183.
[14] Ashok Subramanian. “A polynomial bound on the number of light cycles in an undirected graph”. In: Information processing letters 53.4 (1995), pp. 173–176.