arXiv:2609.03574cs.DSSep 2026

Manuscript Offprint

arXiv:2609.03574

Improved algorithm for counting spanning trees by ℓ1\ell_1-regularized resistance

Rong-Hua Li, Yichun Yang

RONG-HUA LI AND YICHUN YANG

ABSTRACT. We study the basic problem of approximating the number of spanning trees of a graph. We propose an algorithm that approximates the number of spanning trees in O~(m+n7/4ε−3/2)\widetilde{\mathsf{O}}(m + n^{7/4}\varepsilon^{-3/2}) time on a graph with n vertices and m edges. Our algorithm improves upon the previously best known O~(m+n15/8ε−7/4)\widetilde{\mathsf{O}}(m + n^{15/8}\varepsilon^{-7/4}) time algorithm by Chu, Gao, Peng, Sachdeva, Sawlani, and Wang [FOCS 2018] and the O~(m1.5ε−1)\widetilde{\mathsf{O}}(m^{1.5}\varepsilon^{-1}) time algorithm by Liu, Peng and Yang [FOCS 2026] when m⩾n7/6m \geqslant n^{7/6}. Notably, our algorithm is based on the novel concept of ℓ1\ell_1-regularized resistance. We propose simple and efficient algorithms for computing ℓ1\ell_1-regularized resistance and we show that they can be used to approximate the number of spanning trees by combining with the determinant sparsifier framework of Durfee, Peebles, Peng, and Rao [FOCS 2017].

1. INTRODUCTION

Counting the number of spanning trees is a fundamental problem in theoretical computer science and graph theory. For a weighted undirected graph G=(V,E,w)\mathbf{G} = (\mathbf{V}, \mathbf{E}, \mathbf{w}) with nn vertices and mm edges, let

T(G)=∑TspanningtreeofG∏e∈Twe\mathcal{T}(\mathbf{G})=\sum_{\mathsf{T}\mathrm{spanning tree of}\mathbf{G}}\prod_{e\in\mathsf{T}}w_{e}

be its total spanning-tree weight. The classical Kirchhoff’s matrix-tree theorem [Kir47] identifies T(G)\mathcal{T}(G) with any cofactor of the graph Laplacian. Exact evaluation of T(G)\mathcal{T}(G) therefore reduces to computing the Laplacian determinant, which takes nωn^\omega arithmetic operations, where ω≈2.371\omega \approx 2.371 is the matrix-multiplication exponent [ADVW +^{+}25]. The related approximate counting problem is also studied in previous researches. Durfee, Peebles, Peng, and Rao firstly introduced determinant-preserving sparsification and a recursive Schur-complement algorithm for this problem [DPPR20]. They proposed a O~(n2ε−2)1\widetilde{\mathsf{O}}(n^2\varepsilon^{-2})^1 time algorithm for ε\varepsilon-approximating the number of spanning trees.

The main difficulty of their algorithm is that computing determinant sparsifiers need to compute the effective resistance between many pairs of vertices under high precision. Therefore, an improved effective resistance estimation algorithm would implies a faster algorithm for approximate counting spanning trees. Later, Chu, Gao, Peng, Sachdeva, Sawlani, and Wang use short-cycle decompositions to improve the effective resistance estimation and obtained m1+o(1)+n15/8+o(1)ε−7/4m^{1+o(1)} + n^{15/8+o(1)} \varepsilon^{-7/4} runtime for approximate counting spanning trees [CGP +^{+}18]. Recently, Liu, Peng, and Yang proposed a different O~(m3/2ε−1)\widetilde{\mathsf{O}}(m^{3/2} \varepsilon^{-1}) algorithm based on identifying uncorrelated edge sets [LPY25]. On expander graphs, Li and Sachdeva achieved O~(m+n3/2ε−1)\widetilde{\mathsf{O}}(m + n^{3/2} \varepsilon^{-1}) runtime via random walk-based local resistance representations [LS22]. Determinant sparsifiers require Ω(n3/2)\Omega(n^{3/2}) edges in the worst case and can be constructed with O~(n3/2poly(1/ε))\widetilde{\mathsf{O}}(n^{3/2} \text{poly}(1/\varepsilon)) edges [DPPR20]; thus, for constant ε\varepsilon, the O~(m+n3/2)\widetilde{\mathsf{O}}(m + n^{3/2}) bound is optimal under the determinant-sparsifier framework. Their approach, however, relies on constant spectral expansion so that random walks mix in O~(1)\widetilde{\mathsf{O}}(1) steps, and does not extend to general graphs, since the random walk-based resistance estimation relies on the spectral gap of Laplacian matrix.

(Rong-Hua Li) SCHOOL OF COMPUTER SCIENCE, BEIJING INSTITUTE OF TECHNOLOGY, BEIJING, CHINA (Yichun Yang) SCHOOL OF COMPUTER SCIENCE, BEIJING INSTITUTE OF TECHNOLOGY, BEIJING, CHINA

1^{1}In this paper, we use O~(⋅)\widetilde{\mathsf{O}}(\cdot) to hide the logarithmic factors in terms of n, m, ε\varepsilon.

1.1. Main result. Our main result is a improved algorithm for counting the number of spanning trees on general graphs. For constant ε\varepsilon, our runtime bound is O~(m+n7/4)\widetilde{\mathbf{O}}(m + n^{7/4}). It improves the O~(m+n15/8)\widetilde{\mathbf{O}}(m + n^{15/8}) term by [CGP+18][CGP^{+}18]. It is also faster than the recent O~(m3/2)\widetilde{\mathbf{O}}(m^{3/2}) algorithm by [LPY25][LPY25] whenever m⩾n7/6m \geqslant n^{7/6}.

Theorem 1. Let G be a connected undirected graph with n vertices, m edges, and positive edge weights satisfying wmax⁡/wmin⁡⩽nO(1)w_{\max}/w_{\min} \leqslant n^{\mathrm{O}(1)}. For n−O(1)⩽ε⩽1/2n^{-\mathrm{O}(1)} \leqslant \varepsilon \leqslant 1/2, there is a randomized algorithm that returns T^(G)\widehat{\mathcal{T}}(\mathrm{G}) such that (1−ε)T(G)⩽T^(G)⩽(1+ε)T(G)(1 - \varepsilon)\mathcal{T}(\mathrm{G}) \leqslant \widehat{\mathcal{T}}(\mathrm{G}) \leqslant (1 + \varepsilon)\mathcal{T}(\mathrm{G}) with probability 2/3. The expected running time is

O~(m+n7/4ε−3/2).\widetilde{\mathrm{O}}\left(\mathfrak{m}+\mathfrak{n}^{7/4}\varepsilon^{-3/2}\right).

Next we explain the proof sketch of Theorem 1 and several key ingredients of our proof.

1.2. Estimating the resistance. We note that the main bottleneck of approximate spanning-tree counting in prior work is effective-resistance computation [DPPR20, CGP +^{+}18, LS22]. The speedup of our algorithm comes from an improved approach to resistance estimation. Unlike previous algorithms, which estimate resistances directly, we introduce the novel notion of ℓ1\ell_{1}-regularized resistance and obtain an efficient algorithm by estimating these ℓ1\ell_{1}-regularized resistances. We believe that the study of ℓ1\ell_{1}-regularized resistances will also be of independent interest.

Definition 2. Given graph G with Laplacian LGL_G and its pseudo-inverse LG†L_G^\dagger, let bs,t=es−etb_{s,t} = e_s - e_t, the effective resistance between two vertices s and t is defined as

Rs,t=bs,tTLG†bs,t\mathsf{R}_{\mathsf{s},\mathsf{t}}=\mathsf{b}_{\mathsf{s},\mathsf{t}}^{\mathsf{T}}\mathsf{L}_{\mathsf{G}}^{\dagger}\mathsf{b}_{\mathsf{s},\mathsf{t}}

Next we formally define the ℓ1\ell_{1}-regularized resistance.

Definition 3. For a source s and a ℓ1\ell_1-regularized parameter λ∈(1/n,1/2)\lambda \in (1/n, 1/2), consider the following optimization problem:

zs∗=arg⁡min⁡z⩾0{12z⊤LGz−es⊤z+λ1⊤z}z_{s}^{*}=\arg\min_{z\geqslant0}\left\{\frac{1}{2}z^{\top}\mathrm{L}_{\mathrm{G}}z-e_{s}^{\top}z+\lambda\mathbf{1}^{\top}z\right\}

with the residual qs∗=es−LGzs∗q_s^* = e_s - L_G z_s^*. We define zs∗z_s^* as the ℓ1\ell_1-regularized potential, and

Rs,tλ=bs,tT(zs∗−zt∗)\mathsf{R}_{\mathsf{s},\mathsf{t}}^{\lambda}=\mathsf{b}_{\mathsf{s},\mathsf{t}}^{\mathsf{T}}(z_{\mathsf{s}}^{*}-z_{\mathsf{t}}^{*})

as the ℓ1\ell_{1}-regularized resistance between s and t.

We propose efficient algorithm for estimating the ℓ1\ell_{1}-regularized resistance. By simple computation, the Karush–Kuhn–Tucker (KKT) conditions imply

0⩽qs∗⩽λ1,1Tqs∗=1,∣supp⁡zs∗∣⩽λ−1.0\leqslant\mathsf{q}_{s}^{*}\leqslant\lambda\mathbf{1},\qquad\mathbf{1}^{\mathsf{T}}\mathsf{q}_{s}^{*}=1,\qquad|\operatorname{supp}z_{s}^{*}|\leqslant\lambda^{-1}.

Thus the ℓ1\ell_1-regularized potential is local on every graph, its support size is independent on the number of vertices n. This property enables us to estimate the ℓ1\ell_1-regularized potential zs∗z_s^* locally and efficiently. Inspired by the recent progress in ℓ1\ell_1-regularized PageRank [WY26, MRWP23], we propose efficient algorithm for estimating ℓ1\ell_1-regularized resistance in high accuracy.

Theorem 4. Given a graph G, accuracy parameter ξ\xi, there is a randomized algorithm that takes O~(m+nλ−3)\widetilde{\mathbf{O}}(m+n\lambda^{-3}) preprocessing time to create a data structure of space O~(nλ−1)\widetilde{\mathbf{O}}(n\lambda^{-1}), from which one can query the ℓ1\ell_1-regularized resistance R^u,vλ\hat{\mathbf{R}}_{u,v}^\lambda for any vertex pair (u,v)(u,v) in O(1)\mathbf{O}(1) time such that ∣R^u,vλ−Ru,vλ∣⩽ξ|\hat{\mathbf{R}}_{u,v}^\lambda - \mathbf{R}_{u,v}^\lambda| \leqslant \xi, with probability 1−n−O(1)1 - n^{-\mathbf{O}(1)}.

We then propose efficient sampler of effective resistance using the ℓ1\ell_1-regularized resistance. We note that the ℓ1\ell_1-regularized resistance Rs,tλR_{s,t}^\lambda may not be a good estimator of the effective resistance Rs,tR_{s,t} in general. However, combing with the classical result by Spielman and Srivastava [SS11], we show that the aggregate Pearson error of the resistance estimator can be bounded, which is already enough for computing the determinant sparsifier and approximate counting spanning trees (see Section 4).

Theorem 5. Given a graph G=(V,E,w)\mathbf{G} = (\mathbf{V}, \mathbf{E}, \mathbf{w}), we can compute the approximate resistance R^s,t\widehat{\mathbf{R}}_{\mathbf{s}, \mathbf{t}} for every e=(s,t)∈E\mathbf{e} = (\mathbf{s}, \mathbf{t}) \in \mathbf{E} in O~(m+nλ−3)\widetilde{\mathbf{O}}(\mathbf{m} + \mathbf{n}\lambda^{-3}) time such that 14Rs,t⩽R^s,t⩽Rs,t\frac{1}{4} \mathbf{R}_{\mathbf{s}, \mathbf{t}} \leqslant \widehat{\mathbf{R}}_{\mathbf{s}, \mathbf{t}} \leqslant \mathbf{R}_{\mathbf{s}, \mathbf{t}}, and

∑e=(s,t)∈E(weRs,t−weR^s,t)2weR^s,t⩽O(λn).\sum_{e=(s,t)\in\mathbb{E}}\frac{(w_{e}\mathsf{R}_{s,t}-w_{e}\widehat{\mathsf{R}}_{s,t})^{2}}{w_{e}\widehat{\mathsf{R}}_{s,t}}\leqslant\mathsf{O}(\lambda\mathsf{n}).

1.3. Constructing the determinant sparsifiers. We combine the resistance estimator by Theorem 4 and the determinant sparsifier framework by Durfee et. al [DPPR20]. The original result of [DPPR20] needs to compute the effective resistance between many pairs of vertices under high precision. So we strengthen the variance analysis of [DPPR20] and show that the resistance estimator by Theorem 4 is already enough to construct the determinant sparsifier and approximate the number of spanning trees.

Definition 6. Given a graph G=(V,E,w)G = (V, E, w), a ε\varepsilon-determinant sparsifier of GG is a (sparse) graph HH such that (1−ε)TG⩽TH⩽(1+ε)TG(1 - \varepsilon) \mathcal{T}_G \leqslant \mathcal{T}_H \leqslant (1 + \varepsilon) \mathcal{T}_G.

Theorem 7. Given any graph G=(V,E,w)G = (V, E, w), we can compute the ε\varepsilon-determinant sparsifier with high probability in O~(m+nλ−3+λn2ε−2+n3/2ε−1)\widetilde{O}(m + n\lambda^{-3} + \lambda n^2\varepsilon^{-2} + n^{3/2}\varepsilon^{-1}) time.

By extending the determinant sparsifier to the Schur complement, we can approximate the number of spanning trees in the same asymptotic time as constructing the determinant sparsifier. Balancing the runtime by setting λ=n−1/4ε1/2\lambda = n^{-1/4}\varepsilon^{1/2}, we obtain the O~(m+n7/4ε−3/2)\widetilde{O}(m + n^{7/4}\varepsilon^{-3/2}) time algorithm for approximate counting spanning trees, which is the result of Theorem 1.

1.4. AI disclaimer. The high-level ideas and the overall proof structure of this paper were designed by the authors. The detailed proofs are generated by GPT-5.6 Sol. All proofs were verified by the authors.