### Abstract

We present an algorithm that computes exact maximum flows and minimum-cost flows on directed graphs with *m* edges and polynomially bounded integral demands, costs, and capacities in *m*^{1+o(1)} time. Our algorithm builds the flow through a sequence of *m*^{1+o(1)} approximate undirected minimum-ratio cycles, each of which is computed and processed in amortized *m*^{o(1)} time using a new dynamic graph data structure.

Our framework extends to algorithms running in *m*^{1+o(1)} time for computing flows that minimize general edge-separable convex functions to high accuracy. This gives almost-linear time algorithms for several problems including entropy-regularized optimal transport, matrix scaling, *p*-norm flows, and *p*-norm isotonic regression on arbitrary directed acyclic graphs.

## Introduction

The maximum flow problem and its generalization, the minimum-cost flow problem, are classic combinatorial graph problems that find numerous applications in engineering and scientific computing. These problems have been studied extensively over the last seven decades, starting from the work of Dantzig and Ford-Fulkerson. Several important algorithmic problems can be reduced to minimum-cost flows, for example, max-weight bipartite matching, min-cut, and Gomory-Hu trees. The origin of numerous significant algorithmic developments such as the simplex method, graph sparsification, and link-cut trees can be traced back to seeking faster algorithms for maximum flow and minimum-cost flow.

### Problem formulation

Formally, we are given a directed graph *G* = (*V*, *E*) with |*V*| = *n* vertices and |*E*| = *m* edges, upper/lower edge capacities *u*^{+}, *u*^{−} ∈ ℝ^{E}, edge costs ** c** ∈ ℝ

^{E}, and vertex demands

**∈ ℝ**

*d*^{V}with ∑

_{v∈V}

*d*_{v}= 0. Our goal is to solve the following linear program for the

*minimum-cost flow problem*

where the last constraint, *B*^{⊤} ** f** =

**, succinctly captures the requirement that the flow**

*d**satisfies vertex demands*

**f***, where*

**d****∈ℝ**

*B*^{E×V}is the edge-vertex incidence matrix defined as

**B**_{((a,b),v)}is 1 if

*v*=

*a*, −1 if

*v*=

*b*, and 0 otherwise.

In this extended abstract, we assume that all ${u}_{e}^{+},{u}_{e}^{-},{c}_{e}$ and **d**_{v} are integral and polynomially bounded in *n* since this paper focuses on weakly-polynomial algorithms for the maximum flow and minimum-cost flow problems.

### Previous work

There has been extensive work on maximum flow and minimum-cost flow. Here, we briefly discuss some highlights from this work to help place our work in context.

Starting with the first pseudo-polynomial time algorithm by Dantzig^{14} for maximum-flow that ran in *O*(*mn*^{2}*U*) time where *U* denotes the maximum absolute capacity, approaches to designing faster flow algorithms were primarily combinatorial, working with various adaptations of augmenting paths, cycle canceling, blocking flows, and capacity/cost scaling. A long line of work led to a running time of Õ(*m* min{*m*^{½}, *n*^{⅔}})^{15}, ^{18}^{,}^{19}^{,}^{21} for maximum flow, and Õ(*mn*)^{17} for minimum-cost flow. These bounds stood for decades.

In a breakthrough work on solving Laplacian linear systems and computing electrical flows, Spielman and Teng^{34} introduced a novel set of ideas and tools for solving flow problems using combinatorial techniques in conjunction with continuous optimization methods. To deploy these methods, flow algorithms researchers have used graph-algorithmic techniques to solve increasingly difficult subproblems that drive powerful continuous methods.

In the context of maximum flow and minimum-cost flow, Daitch and Spielman^{13} demonstrated the power of this paradigm by using a path-following interior point method (IPM) to reduce the minimum-cost flow problem to solving a sequence of roughly $\sqrt{m}$ electrical flow (ℓ_{2}) problems. Since each of these ℓ_{2} problems could then be solved in nearly-linear time using the fast Laplacian solver by Spielman-Teng, they achieved an Õ(*m*^{1.5}) time algorithm for minimum-cost flow, the first progress in two decades. They showed that a key advantage of IPMs is that they reduce flow problems on directed graphs to flow problems on undirected graphs, which are easier to work with.

While other continuous optimization methods have been used in the context of maximum flow, even leading to nearly-linear time (1+ɛ)-approximate undirected maximum flow and multicommodity flow algorithms,^{12}^{,}^{23}^{,}^{30}^{,}^{32}^{,}^{33} to date all approaches for exact maximum flow and minimum-cost flow rely on the framework suggested by Daitch and Spielman of using a path-following IPM to reduce to a small but polynomial number of convex optimization problems. Notable achievements include an *m*^{4/3+o(1)}*U*^{1/3} time algorithm for bipartite matching and unit-capacity maximum flow.^{4}^{,}^{22}^{,}^{27}^{,}^{28}^{,}^{29} Further, for general capacities, minimum-cost flow algorithms were given with runtimes Õ(*m* + *n*^{1.5})^{8}^{,}^{9}^{,}^{10} and Õ(*m*^{3/2–1/58}).^{5}^{,}^{6}^{,}^{16}^{,}^{35} In both of these results, the development of efficient data structures to solve the sequence of ℓ_{2} sub-problems in amortized time sub-linear in *m* has played a key role in obtaining these runtimes. Yet, despite this progress, the best running time bounds remain far from linear.

### Our result

We give the first almost-linear time algorithm for minimum-cost flow, achieving the optimal running time up to subpolynomial factors.

**Theorem 1.1**

*There is an algorithm that, on a graph G = (V, E) with m edges, vertex demands, upper/lower edge capacities, and edge costs, all integral with capacities and costs bounded by a polynomial in n, computes an exact minimum-cost flow in m*^{1+o(1)} *time with high probability*.

Our algorithm can be extended to work with capacities and costs that are not polynomially bounded at the cost of an additional logarithmic dependency in both the maximum absolute capacity and the maximum absolute cost.

We make two key contributions to achieve our result. First, we develop a novel potential-reduction IPM, similar to Karmarkar’s original work.^{20} Our IPM is *worse* in some ways than existing path-following IPMs because it needs more updates to converge to a good solution. However, our new IPM reduces the minimum-cost flow problem to a sequence of update subproblems that have a more combinatorial structure than those studied before. This enables our second key contribution, a data structure that solves our sequence of update subproblems extremely quickly.

In addition to the use of highly combinatorial updates, our new IPM has three crucial properties. The IPM is (a) *robust* to approximation error in subproblems, (b) *stable* in terms of the subproblems it defines, and (c) *stable* in terms of a good solution to the subproblems. These features allow us to solve the sequence of update subproblems much faster by developing a powerful data structure, yielding a much faster algorithm overall. Thus, instead of making graph algorithms more suitable for continuous optimization, we made continuous optimization more suitable for graph algorithms.

We call the update subproblem that our IPM yields *min-ratio cycle*: This problem is specified by a graph where every edge has a “gradient” and a “length.” The problem asks us to find a cycle that minimizes the sum of (signed, directed) edge gradients relative to its (undirected) length.

Our data structure for solving the sequence of min-ratio cycle problems is our second key contribution. As a first observation, we show that if we sample a random “low-stretch” spanning tree of the graph, then with constant probability, some *fundamental tree cycle* approximately solves the min-ratio cycle problem. Recall a fundamental tree cycle is a cycle defined by a single non-tree edge and the unique tree path between its endpoints. Unfortunately, this simple approach fails after a single flow update, as the IPM requires us to change the gradients and lengths after each update.

To maintain a set of trees that repeatedly allow us to identify good update cycles, we develop a hierarchical construction based on a recursive approach. This requires us to repeatedly construct and contract a random forest (which partially defines our tree), and then recurse on the resulting smaller graph, which we call a *core graph*. Furthermore, to enable recursion, we need to reduce the edge count in the core graph. We achieve this using a new *spanner* construction, which identifies a sparse subgraph of the core graph on which to recurse *and* detects if the removed edges damage the min-ratio cycle. Maintaining the core graphs and spanners in our recursive construction requires us to develop an array of novel dynamic graph techniques, which may be of independent interest.

### Applications

Our result in Theorem 1.1 has a wide range of applications. By standard reductions, it gives the first *m*^{1+o(1)} time algorithms for bipartite matching, worker assignment, negative-lengths single-source shortest paths, and several other problems. For the negative-lengths shortest path problem, Bernstein, Nanongkai, and Wulff-Nilsen obtained the first *m* · poly(log *m*) time algorithm in an independent and concurrent work.^{7}

Using recent reductions from various connectivity problems to maximum flow, we also obtain the first *m*^{1+o(1)} time algorithms to compute vertex connectivity and Gomory-Hu trees in undirected, unweighted graphs,^{1}^{,}^{25} and (1 + *ɛ*)-approximate Gomory-Hu trees in undirected weighted graphs.^{26} We also obtain the current fastest algorithm to find the global min-cut in a directed graph.^{11} Finally, we obtain the first almost-linear-time algorithm to compute the approximate sparsest cuts in directed graphs.

Additionally, our algorithm extends to computing flows that minimize general edge-separable convex objectives.

**Informal Theorem 1.2**

*Consider a graph G with demands* ** d**,

*and an edge-separable convex cost function*

**cost**(

**) = ∑**

*f*_{e}

**cost**

_{e}(

*f*_{e})

*for “computationally efficient” edge costs*cost

*.*

_{e}*Then in m*

^{1+o(1)}

*time, we can compute a (fractional) flow*

**f***that routes demands*

**d***and*cost(

*) ≤ cost(*

**f**

**f**^{⋆})+exp(−log

^{C}*m*)

*for any constant C*> 0,

*where*

**f**^{⋆}

*minimizes*cost(

**f**^{⋆})

*over flows with demands*

*.*

**d**This generalization gives the first almost-linear-time algorithms for solving entropy-regularized optimal transport (equivalently, matrix scaling), *p*-norm flow problems, and *p*-norm isotonic regression for *p*∈[1,∞].

## Overview

### Computing minimum-cost flows via undirected min-ratio cycles

Recall the linear program for minimum-cost flow given in Equation (1). We assume that this LP has a unique optimal solution at *f*^{⋆} ∈ ℝ^{E} and let **F**^{⋆} = *c*^{⊤} *f*^{⋆} (this can be achieved by a negligible perturbation using the famous Isolation Lemma).

For our algorithm, we use a potential-reduction interior point method,^{20} where in each iteration we measure progress by reducing the value of the potential function

for *α* = 1/(1000 log *mU*). The reader can think of the barrier x^{−α} as the more standard −log *x* for simplicity instead. We use it for technical reasons beyond the scope of this paper.

Using standard techniques, one can add *O*(*n*) additional, artificial edges of large capacity and cost to the graph *G* such that the optimal solution to the minimum-cost flow problem remains unchanged (and in particular is not supported on the artificial edges) and such that one can easily find a *feasible* flow * f* on the artificial edges such that

*B*^{⊤}

**=**

*f***with bounded potential, that is, Φ(**

*d**) =*

**f***O*(

*m*log

*m*).

Given the current *feasible solution* * f*, the potential reduction interior point method asks to find a circulation

**Δ**, that is, a flow that satisfies

*B*^{⊤}

**Δ**=

**0**, such that Φ(

*+*

**f****Δ**) ≤ Φ(

*) −*

**f***m*

^{−o(1)}. Given

**Δ**, it then sets

*←*

**f***+*

**f****Δ**and repeats. When Φ(

*) ≤ −200*

**f***m*log

*mU*, we can terminate because then

*c*^{⊤}

**−**

*f*

*F*^{⋆}≤ (

*mU*)

^{−10}, at which point standard techniques let us round to an exact optimal flow.

^{13}Thus if we can reduce the potential by

*m*

^{−o(1)}per iteration, the method terminates in m

^{1+o(1)}iterations.

Let us next describe how to find a circulation **Δ** that reduces the potential sufficiently. Given the current flow * f*, defining the gradient and lengths $g\left(f\right)\stackrel{\text{def}}{=}\nabla \Phi \left(f\right)$ and $\ell {\left(f\right)}_{e}\stackrel{\text{def}}{=}{({u}_{e}^{+}-{f}_{e})}^{-1-\alpha}+{({f}_{e}-{u}_{e}^{-})}^{-1-\alpha}$, and we let $L\stackrel{\text{def}}{=}\text{diag}(\ell )$ be the matrix with these lengths on the diagonal and zeros elsewhere. We can then define the

*min-ratio cycle*problem

Given any solution **Δ** to this problem with ** g**(

**)**

*f*^{⊤}

**Δ**/∥

**∥**

*LΔ*_{1}≤−

*κ*for some

*κ*< 1/100, scaled so that ∥

*∥*

**LΔ**_{1}=

*κ*/50. Then a direct Taylor expansion shows that Φ(

*+*

**f****Δ**) ≤ Φ(

*) −*

**f***κ*/500. Hence, it suffices to show that such a

^{2}**Δ**exists with $k=\tilde{\Omega}\left(1\right)$, because then a data structure that returns an

*m*

^{o(1)}-approximate solution still has

*κ*=

*m*

^{−o(1)}, which suffices. Fortunately, the

*witness circulation*

**Δ**(

**f**^{⋆}) =

**f**^{⋆}−

*satisfies $g{\left(f\right)}^{\top}\Delta /\Vert L\Delta {\Vert}_{1}\le -\tilde{\Omega}\left(1\right)$.*

**f**We emphasize that it is essential for our data structure that the witness circulation **f**^{⋆} − * f* yields a sufficiently good solution. This assumption ensures that good solutions to the min ratio cycle instances do not change arbitrarily between iterations. Further, even though the algorithm does not have access to the witness circulation

**f**^{⋆}−

*, it still knows how it changes between iterations as it can track changes in*

**f***. We are able to leverage this guarantee to ensure our data structure succeeds for the updates coming from the IPM.*

**f**Finally, let us contrast our approach with previous approaches: previous analyses of IPMs solved ℓ_{2} problems, that is, problems of the form given in Equation (2) but with the ℓ_{1} norm replaced by a ℓ_{2} norm (see Figure 1), which can be solved using a linear system. Karmarkar^{20} shows that repeatedly solving ℓ_{2} subproblems, the IPM converges in Õ(*m*) iterations. Later analyses of path-following IPMs^{31} showed that a sequence of $\tilde{O}{\left(\sqrt{m}\right)\ell}_{2}$ subproblems suffices to give a high-accuracy solution. Surprisingly, we are able to argue that a solving sequence of Õ(*m*)ℓ_{1} minimizing subproblems of the form in Equation (2) suffice to give a high-accuracy solution to Equation (1). In other words, changing the ℓ_{2} norm to an ℓ_{1} norm does not increase the number of iterations in a potential reduction IPM. The use of an ℓ_{1}-norm-based subproblem gives us a crucial advantage: Problems of this form must have optimal solutions in the form of simple cycles—and our new algorithm finds approximately optimal cycles vastly more efficiently than any known approaches for ℓ_{2} subproblems.

### High-level overview of the data structure for dynamic min-ratio cycle

As discussed in the previous section, our algorithm computes a minimum-cost flow by solving a sequence of *m*^{1+o(1)} min-ratio cycle problems ${\mathrm{min}}_{{B}^{\top}\Delta =0}{g}^{\top}\Delta /{\Vert L\Delta \Vert}_{1}$ to *m*^{o(1)} multiplicative accuracy. Because our IPM ensures stability for lengths and gradients, and is even robust to approximations of lengths and gradients, we can show that over the course of the algorithm, we only need to update the entries of the gradients * g* and lengths

**ℓ**at most

*m*

^{1+o(1)}total times.

#### Warm-up: A simple, static ALGORITHM.

A simple approach to finding an *Õ*(1)-approximate min-ratio cycle is the following: given our graph *G*, we find a probabilistic low stretch spanning tree *T*, that is, a tree such that for each edge *e* = (*u, v*)∈ *G*, the stretch of *e*, defined as $st{r}_{e}^{T,\ell}\stackrel{\text{def}}{=}\frac{{\sum}_{f\in T[u,v]}\ell (f)}{\ell (e)}$ where *T*[*u*, *v*] is the unique path from *u* to *v* along the tree *T*, is *Õ*(1) in expectation. Such a tree can be found in Õ(*m*) time.^{2}^{,}^{3} This fact will allow us to argue that with probability at least $\frac{1}{2}$, one of the tree cycles is an *Õ*(1)-approximate solution to Equation (2).

Let **Δ**^{⋆} be the optimal circulation that minimizes Equation (2), and assume w.l.o.g. that **Δ**^{⋆} is a cycle that routes one unit of flow along the cycle. We assume for convenience, that edges on **Δ**^{⋆} are oriented along the flow direction of **Δ**^{⋆}, that is, $\Delta *\in {\mathbb{R}}_{\ge 0}^{E}$. Then, for each edge *e* = (*u*, *v*), the *fundamental tree cycle* of *e* in *T*, denoted *e* ⊕ *T*[*v*, *u*], is formed by edge *e* concatenated with the path in *T* from its endpoint *v* to *u*. To work again with vector notation, we denote by ** p**(

*e*⊕

*T*[

*v*,

*u*])∈ℝ

^{E}the vector that sends one unit of flow along the cycle

*e*⊕

*T*[

*v*,

*u*] in the direction that aligns with the orientation of

*e*. A classic fact from graph theory now states that $\Delta *={\sum}_{e:{\Delta}_{e}^{*}>0}{\Delta}_{e}^{*}\cdot p(e\oplus T[v,u])$ (note that the tree paths used by adjacent off-tree edges cancel out, see Figure 2). In particular, this implies that ${g}^{\top}\Delta *={\sum}_{e:{\Delta}_{e}^{*}>0}{\Delta}_{e}^{*}\cdot {g}^{\top}p(e\oplus T[v,u])$.

From the guarantees of the low-stretch tree distribution, we know that the circulation **Δ**^{⋆} is not stretched by too much in expectation. Thus, by Markov’s inequality, with probability at least $\frac{1}{2}$, the circulation **Δ**^{⋆} is not stretched by too much. Formally, we have that ${\sum}_{e:{\Delta}_{e}^{*}>0}{\Delta}_{e}^{*}\cdot {\Vert p(e\oplus T[v,u])\Vert}_{1}\le \gamma {\Vert L\Delta *\Vert}_{1}$ for γ = *Õ*(1). Combining these insights, we can derive that

where the last inequality follows from the fact that ${\mathrm{min}}_{i\in \left[n\right]}\frac{{x}_{i}}{{y}_{i}}\le \frac{{\sum}_{i\in \left[n\right]}{x}_{i}}{{\sum}_{i\in \left[n\right]}{y}_{i}}$ (recall also that *g*^{⊤} **Δ**^{⋆} is negative). This tells us that for the edge *e* minimizing the expression on the right, the tree cycle *e* ⊕ *T*[*v*, *u* ] is a *γ*-approximate solution to Equation (2), as desired. We can boost the probability of success of the above algorithm by sampling *Õ*(1) trees *T*_{1}, *T*_{2}, …, *T*_{s} independently at random and conclude that w.h.p. one of the fundamental tree cycles approximately solves Equation (2).

Unfortunately, after updating the flow * f* to

*along such a fundamental tree cycle, we cannot reuse the set of trees*

**f′***T*

_{1},

*T*

_{2}, …,

*T*

_{s}because the next solution to Equation (2) has to be found with respect to gradients

*(*

**g***) and lengths*

**f′****ℓ**(

*) depending on*

**f′***(instead of*

**f′***=*

**g***(*

**g***) and*

**f****ℓ**=

**ℓ**(

*)). But*

**f***(*

**g***) and*

**f′****ℓ**(

*) depend on the randomness used in trees*

**f′***T*

_{1},

*T*

_{2}, …,

*T*

*. Thus, naively, we have to recompute all trees, spending again Ω(*

_{s}*m*) time. But this leads to run-time Ω(

*m*

^{2}) for our overall algorithm which is far from our goal.

#### A dynamic approach.

Thus we consider the data structure problem of maintaining an *m*^{o(1)} approximate solution to Equation (2) over a sequence of at most *m*^{1+o(1)} changes to entries of * g*,

**ℓ**. To achieve an almost linear time algorithm overall, we want our data structure to have an amortized

*m*

^{o(1)}update time. Motivated by the simple construction above, our data structure will ultimately maintain a set of

*s*=

*m*

^{o(1)}spanning trees

*T*

_{1}, …,

*T*

*of the graph*

_{s}*G*. Each cycle

**Δ**that is returned is represented by

*m*

^{o(1)}off-tree edges and paths connecting them on some

*T*

_{i}.

To obtain an efficient algorithm to maintain these trees *T*_{i}, we turn to a recursive approach. Each level of the recursion will *partially* construct a tree, by choosing a spanning forest of the vertices, and contracting the connected components of the forest. We obtain a tree by repeating forest selection-and-contraction until only a single vertex is left. Then, we compose the forest edges obtained at different levels, yielding a spanning tree of the original graph. At each level of the construction, our forest is probabilistic and only succeeds with constant probability at preserving the hidden witness circulation well enough. To preserve the witness with high probability, we construct *O*(log *n*) different forests at each level and recurse on them separately.

In each level of our recursion, we first reduce the number of vertices using a forest contraction and then the number of edges by making the contracted graph sparse. To reduce the number of vertices, we produce a *core graph* (the result of contracting forest components) on a subset of the original vertex set, and we then compute a *spanner* of the core graph which reduces the number of edges. The edge-reduction step is important to ensure the overall recursion reduces the graph size in each step, which is essential to obtaining almost linear running time in our framework.

Both the *core graph* and *spanner* at each level need to be maintained dynamically, and we ensure they are very stable under changes in the graphs at shallower levels in the recursion. In both cases, our notion of stability relies on some subtle properties of the interaction between data structure and hidden witness circulation.

We maintain a recursive hierarchy of graphs. At the top level of our hierarchy, for the input graph *G*, we produce *B* = *O*(log *n*) core graphs. To obtain each such core graph, for each *i*∈[*B*], we sample a (random) forest *F*_{i} with *Õ*(*m*/*k*) connected components for some size reduction parameter *k*. The associated core graph is the graph *G/F*_{i} which denotes *G* after contracting the vertices in the same components of *F** _{i}*. We can define a map that lifts circulations $\hat{\Delta}$ in the core graph

*G/F*

_{i}, to circulations

**Δ**in the graph

*G*by routing flow along the contracted paths in

*F*

*. The lengths in the core graph $\hat{\ell}$ (again let $\hat{L}=\text{diag}\left(\hat{\ell}\right))$) are chosen to upper bound the length of circulations when mapped back into*

_{i}*G*such that ${\Vert \hat{L}\hat{\Delta}\Vert}_{1}\ge {\Vert L\Delta \Vert}_{1}$. Crucially, we must ensure these new lengths $\hat{\ell}$ do not stretch the witness circulation

**Δ**

^{⋆}when mapped into

*G/F*

_{i}by too much, so we can recover it from

*G/F*

_{i}. To achieve this goal, we choose

*F*

*to be a low-stretch forest, that is, a forest with properties similar to those of a low-stretch tree. In Section 2.3, we summarize the central aspects of our core graph construction.*

_{i}While each core graph *G/F*_{i} now has only *Õ*(*m*/*k*) vertices, it still has *m* edges which are too large for our recursion. To overcome this issue we build a spanner on *S*(*G*, *F*_{i}) on *G/F*_{i} to reduce the number of edges to *Õ*(*m*/*k*), which guarantees that for every edge *e* = (*u*, *v*) that we remove from *G/F*_{i} to obtain *S*(*G*, *F*_{i}), there is a *u*-to-*v* path in *S*(*G*, *F*_{i}) of length *m*^{o(1)}. Ideally, we would now recurse on each spanner *S*(*G*, *F*_{i}), again approximating it with a collection of smaller core graphs and spanners. However, we face an obstacle: removing edges could destroy the witness circulation so that possibly no good circulation exists in any *S*(*G*, *F*_{i}). To solve this problem, we compute an explicit embedding ${\Pi}_{{G/F}_{i}\to S(G,{F}_{i})}$ that maps each edge *e*=(*u*, *v*)∈*G*/*F*_{i} to a short *u*-to-*v* path in *S*(*G*, *F*_{i}). We can then show the following dichotomy: Let $\hat{\Delta}*$ denote the witness circulation when mapped into the core graph *G/F*_{i}. Then, *either* one of the edges ${e\in E}_{{G/F}_{i}}{E}_{S(G,{F}_{i})}$ has a spanner cycle consisting of *e* combined with ${\Pi}_{{G/F}_{i}\to S(G,{F}_{i})}\left(e\right)$ which is almost as good as $\hat{\Delta}*$, *or* re-routing $\hat{\Delta}*$ into *S*(*G*, *F*_{i}) roughly preserves its quality. Figure 3 illustrates this dichotomy. Thus, either we find a good cycle using the spanner, or we can recursively find a solution *S*(*G*, *F*_{i}) onthat almost matches $\hat{\Delta}*$ in quality. To construct our dynamic spanner with its efficient updates and strong stability guarantees under changes in the input graph, we design a new approach that diverges from other recent works on dynamic spanners.

Our recursion uses *d* levels, where we choose the size reduction factor *k* such that *k*^{d} ≈ *m* and the bottom level graphs have *m*^{o(1)} edges. Note that since we build *B* trees on *G* and recurse on the spanners of *G/F*_{1}, *G/F*_{2}, …, *G/F** _{B}*, our recursive hierarchy has a branching factor of

*B*=

*O*(log

*n*) at each level of recursion. Thus, choosing $d\le \sqrt{\mathrm{log}n}$, we get

*B*

^{d}=

*m*

^{o(1)}leaf nodes in our recursive hierarchy. Now, consider the forests ${{F}_{i}}_{1},{{F}_{i}}_{2},\mathrm{\dots},{{F}_{i}}_{d}$ on the path from the top of our recursive hierarchy to a leaf node. We can patch these forests together to form a tree associated with the leaf node. For each of these trees, we maintain a link-cut tree data structure. Using this data structure, whenever we find a good cycle, we can route flow along it and detect edges where the flow has changed significantly. The cycles are either given by an off-tree edge or a collection of

*m*

^{o(1)}off-tree edges coming from a spanner cycle. We call the entire construction a

*branching tree chain*. In Section 2.4, we elaborate on the overall composition of the data structure.

What have we achieved using this hierarchical construction compared to our simple, static algorithm? First, consider the setting of an *oblivious adversary*, where the gradient and length update sequences and the optimal circulation after each update are fixed in advance (i.e., the adversary is oblivious of the algorithm’s random choices). In this setting, we can show that our spanner-of-core graph construction can survive through *m*^{1−o(1)}*/k*^{i} updates at level *i*. Meanwhile, we can rebuild these constructions in time *m*^{1+o(1)}*/k*^{i−1}, leading to an amortized cost per update of *km*^{o(1)} ≤ *m*^{o(1)} at each level. This gives the first dynamic data structure for our undirected min-ratio problem with *m*^{o(1)} query time against an oblivious adversary.

However, our real problem is harder: the witness circulation in each round is **Δ**(* f*)

^{⋆}=

**f**^{⋆}−

*and depends on the updates we make to*

**f***, making our sequence of subproblems adaptive. While we cannot show that our data structure succeeds against an adaptive adversary, we give a data structure that works against a restricted adaptive adversary. We show that the witness circulation*

**f**

**f**^{⋆}−

*lets us express the IPM as such a restricted adversary.*

**f**### Building core graphs

In this section, we describe our core graph construction, which maps our dynamic undirected min-ratio cycle problem on a graph *G* with at most *m* edges and vertices into a problem of the same type on a graph with only *Õ*(*m*/*k*) vertices and *m* edges, and handles *Õ*(*m*/*k*) updates to the edges before we need to rebuild it.

#### Forest routings and stretches.

To understand how to define the stretch of an edge *e* with respect to a forest *F*, it is useful to define how to *route* an edge *e* in *F*. Given a spanning forest *F*, every path and cycle in *G* can be mapped to *G/F* naturally (where we allow *G/F* to contain self-loops). On the other hand, if every connected component in *F* is rooted, where ${\text{root}}_{u}^{F}$ denotes the root corresponding to a vertex *u* ∈ *V*, we can map every path and cycle in *G/F* back to *G* as follows. Let *P* = *e*_{1}, …, *e** _{k}* be any (not necessarily simple) path in

*G/F*where the preimage of every edge

*e*

_{i}is ${e}_{i}^{G}=({u}_{i}^{G},{v}_{i}^{G})\in G$. The preimage of

*P*, denoted

*P*

^{G}, is defined as the following concatenation of paths:

where we use *A* ⊕ *B* to denote the concatenation of paths *A* and *B*, and *F*[*a*, *b*] to denote the unique *ab*-path in the forest *F*. When *P* is a circuit (i.e., a not necessarily simple cycle), *P ^{G}* is a circuit in

*G*as well. One can extend these maps linearly to all flow vectors and denote the resulting operators as Π

_{F}: ℝ

^{E(G)}→ ℝ

^{E(G/F)}and ${\Pi}_{F}^{-1}:{\mathbb{R}}^{E(G/F)}\to {\mathbb{R}}^{E\left(G\right)}$. Since we let

*G/F*have self-loops, there is a bijection between the edges of

*G*and

*G/F*, and thus Π

_{F}acts like the identity function. Related routing schemes date back to Spielman-Teng

^{34}and are generally known as

*portal routing*.

To make our core graph construction dynamic, the key operation we need to support is the dynamic addition of more root nodes, which results in forest edges being deleted to maintain the invariant each connected component has a root node. Whenever an edge is changing in *G*, we ensure that *G/F* approximates the changed edge well by forcing both its endpoints to become root nodes, which in turn makes the portal routing of the new edge trivial and this guarantees its stretch is 1.

For any edge *e** ^{G}* = (

*u*

*,*

^{G}*v*

*) in*

^{G}*G*with image

*e*in

*G/F*, we set ${\hat{\ell}}_{e}^{F}$, the edge length of

*e*in

*G/F*, to be

*an upper bound*on the length of the

*forest routing*of

*e*, that is, the path $F[{\text{root}}_{{u}^{G}}^{F},{u}^{G}]\oplus {e}^{G}\oplus F[{v}^{G},{\text{root}}_{{u}^{G}}^{F}]$. Meanwhile, we define ${\tilde{str}}_{e}\stackrel{def}{=}{\widehat{l}}_{e}^{F}/{l}_{e}$, as an overestimate on the stretch of

*e*w.r.t. the forest routing. A priori, it is unclear how to provide a single upper bound on the stretch of every edge, as the root nodes of the endpoints are changing over time. Providing such a bound for every edge is important for us as the lengths in

*G/F*could otherwise be changing too often when the forest changes. We guarantee these bounds by a scheme that makes auxiliary edge deletions in the forest in response to external updates, with the resulting additional roots chosen carefully to ensure the length of upper bounds.

Now, for any flow * f* in

*G/F*, its length in

*G/F*is at least the length of its pre-image in

*G*, that is, ${\Vert {L\Pi}_{F}^{-1}f\Vert}_{1}\le {\Vert {\hat{L}}^{F}f\Vert}_{1}$. Let

**Δ**

^{⋆}be the optimal solution to Equation (2). We will show later how to build

*F*such that with constant probability ${\Vert {\hat{L}}^{F}\Delta *\Vert}_{1}\le \gamma {\Vert L\Delta *\Vert}_{1}$ holds for some

*γ*=

*m*

^{o(1)}, solving Equation (2) on

*G/F*with edge length $\hat{\ell}$ and properly defined gradient

**on**

*ĝ**G/F*yields an $\frac{1}{\gamma}$-approximate solution for

*G*. The gradient

**is defined so that the total gradient of any circulation**

*ĝ***Δ**on

*G/F*and its preimage ${\Pi}_{F}^{-1}$ in

*G*is the same, that is, ${\hat{g}}^{\top}\Delta ={\hat{g}}^{\top}{\Pi}_{F}^{-1}\Delta $. The idea of incorporating gradients into portal routing was introduced in Kyng et al.

^{24}; our version of this construction is somewhat different to allow us to make it dynamic efficiently.

#### Collections of low stretch decompositions (LSD).

The first component of the data structure is constructing and maintaining forests of *F* that form a *Low Stretch Decomposition (LSD)* of *G*. Informally, a *k*-LSD is a rooted forest *F* ⊆ *G* that decomposes *G* into *O*(*m/k*) vertex disjoint components. Given some positive edge weights $v\in {\mathbb{R}}_{>0}^{E}$ and reduction factor *k* > 0, we compute a *k*-LSD *F* and length upper bounds ${\hat{\ell}}^{F}$ of *G/F* that satisfy two properties:

${\tilde{str}}_{e}^{F}={\widehat{l}}_{e}^{F}/{l}_{{e}^{G}}=\tilde{O}\left(k\right)$ for any edge

*e*^{G}∈*G*with image*e*in*G/F*, andThe weighted average of ${\tilde{str}}_{e}^{F}$ w.r.t.

is only**v***Õ*(1) that is, ${\sum}_{{e}^{G}\in G}{v}_{{e}^{G}}\cdot {\tilde{str}}_{e}^{F}\le \tilde{O}\left(1\right)\cdot {\Vert v\Vert}_{1}$.

Item 1 guarantees that the solution to Equation (2) for *G/F* yields a *Õ*(*k*)-approximate one for *G*. However, this guarantee is not sufficient for our data structure, as our *B*-branching tree chain has *d* ≈ log_{k} *m* levels of recursion and the quality of the solution from the deepest level would only be *Õ*(*k*)^{d}≈*m*^{1+o(1)}-approximate.

Instead, we compute *k* different edge weight assignments **v**_{1}, …, **v*** _{k}* via multiplicative weight updates so that the LSDs

*F*

_{1}, …,

*F*

*have*

_{k}*Õ*(1) an average stretch on every edge in $G:{\sum}_{j=1}^{k}{\tilde{str}}_{e}^{{F}_{j}}=\tilde{O}\left(k\right)$, for all

*e*

^{G}∈

*G*with image

*e*in

*G/F*.

By Markov’s inequality, for any fixed flow * f* in $G,{\Vert {\hat{L}}^{{F}_{j}}f\Vert}_{1}\le \tilde{O}\left(1\right){\Vert Lf\Vert}_{1}$ holds for at least half the LSDs corresponding to

*F*

_{1}, …,

*F*

*. Taking*

_{k}*O*(log

*n*) samples uniformly from

*F*

_{1}, …,

*F*

*, say*

_{k}*F*

_{1}, …,

*F*

*for*

_{B}*B*=

*O*(log

*n*) we get that with high probability

That is, it suffices to solve Equation (2) on *G/F*_{1}, …, *G/F** _{B}* to find an

*Õ*(1)-approximate solution for

*G*.

### Maintaining a branching tree chain

Our branching chain is constructed as follows:

Sample and maintain

*B*=*O*(log*n*)*k*-LSDs*F*_{1},*F*_{2}, …,*F*, and their associated core graphs_{B}*G/F*_{i}. Across*O*(*m/k*) updates at the top level, the forests*F*are_{i}*decremental*, that is, only undergo edge deletions (from root insertions), and will have*Õ*(*m*/*k*) connected components.Maintain spanners

*S*(*G*,*F*_{i}) of the core graphs*G/F*_{i}, and embeddings ${\Pi}_{E(G/{F}_{i})\to S(G/{F}_{i})}$, say with length increase*γ*_{ℓ}=*m*^{o(1)}.Recursively process the graphs

*S*(*G*,*F*), that is, maintain LSDs and core graphs on those, and spanners on the contracted graphs, etc., for_{i}*d*total levels, with*k*=^{d}*m*.Whenever a level

*i*accumulates*m/k*total updates, hence doubling the number of edges in the graphs at that level, we rebuild levels^{i}*i*,*i*+ 1, …,*d*.

Recall that on average, the LSDs stretch lengths by *Õ*(1), and the spanners *S*(*G*, *F _{i}*) stretch lengths by

*γ*

_{ℓ}. Hence, the overall data structure stretches lengths by

*Õ*(γ

_{ℓ})

^{d}=

*m*

^{o(1)}(for appropriately chosen

*d*).

We now discuss how to update the forests *G/F*_{i} and spanners *S*(*G*, *F _{i}*). Intuitively, every time an edge

*e*= (

*u*,

*v*) is changed in

*G*, we will delete

*Õ*(1) additional edges from

*F*

*. This ensures that no edge’s total stretch/routing-length increases significantly due to the deletion of*

_{i}*e*. As the forest

*F*

*undergoes edge deletions, the graph*

_{i}*G/F*

_{i}undergoes

*vertex splits*, where a vertex has a subset of its edges moved to a newly created vertex. Thus, a key component of our data structure is to maintain spanners and embed-dings of graphs undergoing vertex splits (and edge insertions/ deletions). Importantly, the amortized recourse (number of changes) to the spanner

*S*(

*G*,

*F*) is

_{i}*m*

^{o(1)}independent of

*k*, even though the average degree of

*G/F*

_{i}is

*Ω*(

*k*). Hence, on average

*Ω*(

*k*) edges will move in

*G/F*

_{i}per vertex split.

Overall, let every level have recourse *γ** _{r}* =

*m*

^{o(1)}(independent of

*k*) per tree. Then each update at the top level induces

*O*(

*Bγ*)

_{r}*(as we branch using*

^{d}*B*forests/core graphs at each level of the recursion) updates in the data structure overall. Intuitively, for the proper choice of

*d*=

*ω*(1), both the total recourse

*O*(

*Bγ*)

_{r}*and approximation factor*

^{d}*Õ*(

*γ*)

_{ℓ}*are*

^{d}*m*

^{o(1)}as desired.

### Going beyond oblivious adversaries by using IPM guarantees

The precise data structure in the previous section only works for *oblivious adversaries*, because we used that if we sampled *B* = *O*(log *n*) LSDs, then w.h.p. there is a tree whose average stretch is *Õ*(1) with respect to a *fixed flow* * f*. However, since we are updating the flow along the circulations returned by our data structure, we influence future updates, so the optimal circulations our data structure needs to preserve, are not independent of the randomness used to generate the LSDs. To overcome this issue, we leverage the key fact that the flow

**f**^{⋆}−

*is a good witness for the min-ratio cycle problem at each iteration.*

**f**To simplify our discussion, we focus on the role of the witness in ensuring the functioning of a single layer of core graph construction, which already captures the main ideas. We can prove that for any flow ** f**,

**(**

*g***)**

*f*^{⊤}

**Δ**(

**)/(100**

*f**m*+∥

**(**

*L***)**

*f***Δ**(

**)∥**

*f*_{1}) ≤ −

**Ω̃**(1) holds where

**Δ**(

*) =*

**f**

**f**^{⋆}−

*. Then, the best solution to Equation (2) among the LSDs*

**f***G/F*

_{1}, …,

*G/F*

*maintains an*

_{B}*Õ*(1)-approximation of the quality of the witness

**Δ**(

*) =*

**f**

**f**^{⋆}−

*as long as*

**f**In this case, let $\hat{\Delta}$ be the best solution obtained from graphs *G/F*_{1}, …, *G/F** _{B}*. We have

The additive term is there for technical reasons that can be ignored for now. We define the *width* * w*(

*) of*

**f****Δ**(

*) as*

**f***(*

**w***) = 100 ·*

**f****1**+|

*(*

**L***)*

**f****Δ**(

*)|. The name comes from the fact that*

**f***(*

**w***)*

**f***is always at least $|\ell {\left(f\right)}_{e}\left({f}_{e}^{*}-{f}_{e}\right)|$ for any edge*

_{e}*e*. We show that the width is also slowly changing across IPM iterations, in that if the width changed by a lot, then the residual capacity of

*e*must have changed significantly. This gives our data structure a way to predict which edges’ contribution to the length of the witness flow

**f**^{⋆}−

*could have significantly increased.*

**f**Observe that for any forest *F** _{j}* in the LSD of

*G*, we have ${\Vert {\hat{L}}^{{F}_{j}}\Delta \left(f\right)\Vert}_{1}\le {\Vert {\tilde{str}}^{{F}_{j}}\circ w\left(f\right)\Vert}_{1}$. Thus, we can strengthen Equation (4) and show that the IPM potential can be decreased by

*m*

^{−o(1)}if

Equation (5) also holds with w.h.p. if the collection of LSDs is built after knowing * f*. However, this does not necessarily hold after augmenting with

**Δ**, an approximate solution to Equation (2).

Due to the stability of * w*(

*), we have*

**f***(*

**w***+*

**f****Δ**)

*≈*

_{e}*(*

**w***)*

**f***for every edge*

_{e}*e*whose length does not change a lot. For other edges, we update their edge length and force the stretch to be 1, that is, ${\tilde{str}}_{e}^{{F}_{j}}=1$ via the dynamic LSD maintenance, by shortcutting the routing of the edge

*e*at its endpoints. To distinguish between the earlier stretch values and those after updating edges, let us denote the former by ${\tilde{str}}_{\text{old}}^{{F}_{j}}$ and the latter by ${\tilde{str}}_{\text{new}}^{{F}_{j}}$. This gives that for any

*j*∈[

*B*], the following holds:

Using the fact that ${\mathrm{min}}_{j\in \left[B\right]}{\Vert {\tilde{str}}_{\text{old}}^{{F}_{j}}\circ w\left(f\right)\Vert}_{1}\lesssim \tilde{O}\left({\Vert w\left(f\right)\Vert}_{1}\right)$, we have the following:

$\underset{j\in \left[B\right]}{\mathrm{min}}{\Vert {\tilde{str}}_{\text{new}}^{{F}_{j}}\circ w(f+\Delta )\Vert}_{1}\lesssim \tilde{O}\left({\Vert w\left(f\right)\Vert}_{1}\right)+{\Vert w(f+\Delta )\Vert}_{1}\mathrm{.}$Thus, solving Equation (2) on the updated *G/F*_{1}, …, *G/F** _{B}* yields a good enough solution for reducing IPM potential as long as the width of

*(*

**w***+*

**f****Δ**) has not decreased significantly, that is, ∥

**(**

*w***)∥**

*f*_{1}≤

*Õ*(1)∥

**(**

*w***)∥**

*f + Δ*_{1}.

If the solution on the updated graphs *G/F*_{1}, …, *G/F** _{B}* does not have a good enough quality, we know by the above discussion that ∥

**(**

*w***)∥**

*f + Δ*_{1}≤ 0.5∥

**(**

*w***)∥**

*f*_{1}must hold. Then, we re-compute the collection of LSDs of

*G*and solve Equation (2) on the new collection of

*G/F*

_{1}, …,

*G/F*

*again. Because each recomputation reduces the ℓ*

_{B}_{1}norm of the width by a constant factor, and all the widths are bounded by exp(log

*(1)*

^{O}*m*) (which can be guaranteed by the IPM), there can be at most

*Õ*(1) such recomputations. At the top level, this only increases our runtime by

*Õ*(1) factors.

The full construction is along these lines, but more complicated since we recursively maintain the solutions on the spanners of each core graph *G/F*_{1}, …, *G/F** _{B}*. In the full version of the paper, we describe and analyze a multi-level rebuilding scheme that extends the above reasoning to our full data structure.

## Conclusion

In this paper, we presented an almost-linear time algorithm for minimum-cost flow, maximum flow, and more generally, all convex single-commodity flows. Our work essentially settles the complexity of several fundamental and intensely studied problems in algorithms design. We hope that the ideas introduced in this work will spur further research in several directions, including simpler and faster algorithms for flow problems; hopefully resulting in a significant impact on algorithms in practice.

## Acknowledgments

Li Chen was supported by NSF Grant CCF-2106444. Rasmus Kyng and Maximilian Probst Gutenberg have received funding from the grant “Algorithms and complexity for high-accuracy flows and convex optimization” (no. 200021 204787) of the Swiss National Science Foundation. Yang P. Liu was supported by NSF CAREER Award CCF-1844855 and NSF Grant CCF-1955039. Richard Peng was partially supported by NSF CAREER Award CCF-1846218 and NSERC Discovery Grant RGPIN-2022–03207. Sushant Sachdeva’s research is supported by a Natural Sciences and Engineering Research Council of Canada (NSERC) Discovery Grant RGPIN-2018–06398 and an Ontario Early Researcher Award (ERA) ER21–16–284.

The authors thank the 2021 Hausdorff Research Institute for Mathematics Program Discrete Optimization. The authors are very grateful to Yin Tat Lee and Aaron Sidford for several useful discussions.

## Join the Discussion (0)

## Become a Member or Sign In to Post a Comment