← Wiki Index / Computation & Algorithms / Dinic's Algorithm
💻 Computation & Algorithms

Dinic's Algorithm

Dinic's algorithm is a strongly polynomial maximum-flow algorithm that alternates between breadth-first level-graph construction and depth-first blocking-flow augmentation in O(V²E) worst-case time.

Dinic's algorithm (also known as Dinitz's algorithm) is a strongly polynomial algorithm in computation and algorithms that computes a maximum s–t flow in a directed capacitated flow network G = (V, E, c) in O(V2E) worst-case time. Developed in 1969 and published in 1970 by Soviet computer scientist Yefim Dinitz (transliterated as E. A. Dinic in early English translations), the algorithm was discovered independently of and prior to the O(V E2) Edmonds–Karp specialization of the Ford–Fulkerson algorithm.

Rather than searching the residual network Gf from scratch for a single shortest augmenting path at a time, Dinic's algorithm operates in phases. In each phase, a Breadth-First Search (BFS) partitions the residual network into a level graph GL containing all shortest s–t augmenting paths simultaneously, and a subsequent Depth-First Search (DFS) with current-arc pointer maintenance pushes a blocking flow that saturates at least one edge along every s–t path in GL. On unit-capacity networks, its complexity improves to O(E min(V2/3, E1/2)), and on bipartite matching networks it runs in O(E √V) time, matching the Hopcroft–Karp algorithm.

Mathematical Formulation and Core Concepts

Residual Network and Level Graph Partitioning

Let G = (V, E, c) be a directed network with source s ∈ V, sink t ∈ V, vertex count V = |V|, and edge count E = |E|. Given a feasible s–t flow f, the residual network Gf = (V, Ef) consists of all directed pairs (u, v) with positive residual capacity cf(u, v) = c(u, v) − f(u, v) + f(v, u) > 0.

At the start of each phase, Dinic's algorithm computes for every vertex v ∈ V its unweighted shortest-path distance (or level) df(v) from the source s in Gf using a single BFS traversal in O(E) time, setting df(s) = 0 and df(v) = ∞ if v is unreachable from s. The level graph GL = (V, EL) is the directed acyclic subgraph of Gf containing only edges that advance the distance label by unit increments:

EL = { (u, v) ∈ Ef : df(v) = df(u) + 1 }

Every directed path from s to t in GL has length df(t) and is therefore a shortest s–t augmenting path in Gf. Conversely, any residual edge (u, v) ∈ Ef with df(v) ≤ df(u) cannot belong to any shortest s–t path during the current phase and is omitted from GL.

Blocking Flows vs. Maximum Flows

A flow g in the level graph GL is called a blocking flow (or maximal flow) if every directed path from s to t in GL contains at least one saturated edge (u, v) where g(u, v) = cf(u, v). Every maximum flow in GL is a blocking flow, but a blocking flow need not be a maximum flow in GL because blocking flows are found greedily without using backward cancellation edges within the same phase.

Strict Monotonicity of Sink Distance Across Phases

The foundational correctness and termination invariant of Dinic's algorithm is the Distance Monotonicity Lemma: if f′ = f + g is the flow obtained by augmenting f with a blocking flow g in GL, then the shortest-path distance from s to t in the new residual network Gf′ increases by at least 1:

df′(t) ≥ df(t) + 1

Proof Sketch: Every edge (u, v) ∈ Ef′ is either an unsaturated residual edge that already belonged to Ef (satisfying df(v) ≤ df(u) + 1) or the reverse (v, u) of an edge (u, v) ∈ EL along which g pushed positive flow (where df(u) = df(v) − 1, so it still satisfies df(u) ≤ df(v) + 1). Thus no path from s to t in Gf′ can have length less than df(t). Furthermore, any path of length df(t) in Gf′ would have to use only edges with df(v) = df(u) + 1, which belong exclusively to EL; however, because g is a blocking flow in GL, at least one edge on every such path was saturated by g and deleted from Ef′. Therefore, df′(t) > df(t). Because a simple s–t path contains at most V − 1 edges, Dinic's algorithm terminates in at most V − 1 phases.

Algorithmic Procedure and Complexity

Current-Arc Pointer Optimization (Shiloach–Even)

In Dinitz's original 1970 formulation and Shimon Even and Yossi Shiloach's 1975 refinement, each blocking-flow phase executes a Depth-First Search from s to t while maintaining for each vertex u ∈ V a current-arc pointer indexing its adjacency list in GL:

  1. DFS Advance: From vertex u, inspect the edge (u, v) currently indexed by u's pointer. If (u, v) ∈ EL and cf(u, v) > 0, recursively advance to v.
  2. Dead-End Pruning and Pointer Increment: If the recursive call from v returns 0 pushed flow (meaning t is no longer reachable from v in the remaining unsaturated level graph) or if (u, v) becomes saturated, increment u's current-arc pointer to the next incident edge. Once an edge is bypassed by the pointer, it is never inspected again during the current phase.
  3. Path Augmentation: Whenever t is reached, push bottleneck capacity Δ along the current DFS stack (or push multiple paths simultaneously via multiple-path DFS), saturating at least one bottleneck edge.

Because each DFS step either advances toward t (at most V steps before reaching t or hitting a dead end) or increments a vertex's current-arc pointer (which can happen at most E times across the entire phase), finding a blocking flow takes at most O(V E) time per phase. Multiplied across at most V − 1 phases, total worst-case complexity is O(V2E). Replacing the DFS stack with a link/cut tree (Sleator and Tarjan, 1983) reduces the blocking-flow phase to O(E log V) and overall max-flow complexity to O(V E log V).

Unit-Capacity Networks and Bipartite Matching Bounds

When edge capacities are restricted to integers in {0, 1}, Alexander Karzanov (1973) and Even and Tarjan (1975) proved much tighter bounds within computational complexity theory:

  • Unit-Capacity Networks: In any network where c(e) = 1 for all e ∈ E, each DFS augmentation saturates every edge along its path, so finding a blocking flow takes O(E) time per phase. After k = ⌈min(V2/3, E1/2)⌉ phases, the distance from s to t exceeds k, and the pigeonhole principle implies the existence of a level boundary with residual capacity at most O(min(V2/3, E1/2)). Thus at most O(min(V2/3, E1/2)) additional phases occur, giving O(E min(V2/3, E1/2)) total time.
  • Unit Networks (Bipartite Matching): If every internal vertex v ∈ V \ {s, t} additionally has either in-degree 1 or out-degree 1, all augmenting paths in a blocking flow are vertex-disjoint. After √V phases, the remaining residual flow is at most √V, yielding O(E √V) total time.

Comparative Complexity Across Maximum-Flow Variants

Algorithm VariantGeneral Capacitated TimeUnit-Capacity Simple GraphUnit Network (Bipartite)Primary Mechanism
Edmonds–Karp (1972)O(V E2)O(E3/2)O(V E)Single BFS shortest path per step
Dinic's Algorithm (1970)O(V2E)O(E min(V2/3, E1/2))O(E √V)BFS level graph + current-arc DFS
Karzanov Preflow (1974)O(V3)O(E min(V2/3, E1/2))O(E √V)Layered preflow wave balancing
Sleator–Tarjan Dynamic Trees (1983)O(V E log V)O(E min(V2/3, E1/2))O(E √V)Blocking flow via link/cut tree
Push–Relabel Highest-Label (1988)O(V2 √E)O(E min(V2/3, E1/2))O(E √V)Local excess push + height relabel

Scientific and Engineering Applications

Dinic's algorithm is widely deployed as the core maximum-flow engine in Gomory–Hu tree construction, circulation with lower bounds, project selection (maximum-weight closure), and baseball elimination. In structural bioinformatics and systems biology, it computes minimum reaction cut sets in metabolic networks and resolves exon-splicing graph decompositions in transcriptomic assemblers.

Frequently Asked Questions

Why is the current-arc pointer essential for the O(V²E) bound?

Without advancing and persisting the current-arc pointer at each vertex during a phase, a naive DFS could repeatedly traverse and backtrack across the same dead-end subgraphs in GL, degrading a single blocking-flow phase from O(V E) to O(V2E) or worse.

How does Dinic's algorithm relate to the Hopcroft–Karp algorithm?

When applied to the standard unit-capacity source-to-sink network representing a bipartite graph G = (U ∪ W, E), Dinic's algorithm executes the exact same phase structure and achieves the same O(E √V) time bound as the Hopcroft–Karp algorithm.

References

  1. Dinic, E. A. (1970). "Algorithm for solution of a problem of maximum flow in a network with power estimation." Soviet Mathematics Doklady, 11(5), 1277–1280. https://mathscinet.ams.org/mathscinet-getitem?mr=0287976
  2. Even, S., & Tarjan, R. E. (1975). "Network flow and testing graph connectivity." SIAM Journal on Computing, 4(4), 507–518. https://doi.org/10.1137/0204043
  3. Sleator, D. D., & Tarjan, R. E. (1983). "A data structure for dynamic trees." Journal of Computer and System Sciences, 26(3), 362–391. https://doi.org/10.1016/0022-0000(83)90006-590006-5)
  4. Dinitz, Y. (2006). "Dinitz' algorithm: The original version and Even's version." In Theoretical Computer Science: Essays in Memory of Shimon Even (pp. 218–240). Springer. https://doi.org/10.1007/11685654_10
🧬 Support Open Science
Explore interactive science games on LowKey Games or browse scientific apparel & accessories in the CRV Science Shop.
💡 Spot an inaccuracy or have primary literature to expand this article?
Submit a citation or revision note using your shared CRV Science / LowKey Games profile ID.
Suggest Revision