ArticleslgStudy

computer science

Dinic's algorithm

Dinic's algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Dinic's algorithm rather than just read about it. In short: Dinic's algorithm or Dinitz's algorithm is a strongly polynomial algorithm for computing the maximum flow in a flow network, conceived in 1970 by Israeli (formerly Soviet) computer scientist Yefim Dinitz. The algorithm runs in O(|V|2|E|) time and is similar to the Edmonds–Karp algorithm, which runs in O(|V||E|2) time, in that it uses shortest augmenting paths.

Dinic's algorithm — main illustration
Dinic's algorithm — illustration

Key takeaways

  • Dinic's algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Dinic's algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Dinic's algorithm from memory before moving on to harder problems.

Reference excerpt

Dinic's algorithm or Dinitz's algorithm is a strongly polynomial algorithm for computing the maximum flow in a flow network, conceived in 1970 by Israeli (formerly Soviet) computer scientist Yefim Dinitz. The algorithm runs in O(|V|2|E|) time and is similar to the Edmonds–Karp algorithm, which runs in O(|V||E|2) time, in that it uses shortest augmenting paths. The introduction of the concepts of the level graph and blocking flow enable Dinic's algorithm to achieve its performance.

History Dinitz invented the algorithm in January 1969, as a master's student in Georgy Adelson-Velsky's group. A few decades later, he would recall:

In Adel'son-Vel'sky's Algorithms class, the lecturer had a habit of giving the problem to be discussed at the next meeting as an exercise to students. The DA was invented in response to such an exercise. At that time, the author was not aware of the basic facts regarding [the Ford–Fulkerson algorithm] ... Ignorance sometimes has its merits. Very probably, DA would not have been invented then, if the idea of possible saturated edge desaturation had been known to the author.

In 1970, Dinitz published a description of the algorithm in Doklady Akademii Nauk SSSR. In 1974, Shimon Even and (his then Ph.D. student) Alon Itai at the Technion in Haifa were very curious and intrigued by Dinitz's algorithm as well as Alexander V. Karzanov's related idea of blocking flow. However it was hard for them to decipher these two papers, each being limited to four pages to meet the restrictions of journal Doklady Akademii Nauk SSSR. Even did not give up, and after three days of effort managed to understand both papers except for the layered network maintenance issue. Over the next couple of years, Even gave lectures on "Dinic's algorithm", mispronouncing the name of the author while popularizing it. Even and Itai also contributed to this algorithm by combining BFS and DFS, which is how the algorithm is now commonly presented. For about 10 years of time after the Ford–Fulkerson algorithm was invented, it was unknown if it could be made to terminate in polynomial time in the general case of irrational edge capacities. This caused a lack of any known polynomial-time algorithm to solve the max flow problem in generic cases. Dinitz's algorithm and the Edmonds–Karp algorithm (published in 1972) both independently showed that in the Ford–Fulkerson algorithm, if each augmenting path is the shortest one, then the length of the augmenting paths is non-decreasing and the algorithm always terminates.

Definition Let G=((V,E),c,f,s,t) be a network with c(u,v) and f(u,v) the capacity and the flow of the edge (u,v), respectively.

The residual capacity is a mapping cf:V×V→R+ defined as, if (u,v)∈E, cf(u,v)=c(u,v)−f(u,v) if (v,u)∈E, cf(u,v)=f(v,u) cf(u,v)=0 otherwise. The residual graph is an unweighted graph Gf=((V,Ef),cf|Ef,s,t), where Ef={(u,v)∈V×V:cf(u,v)>0}. An augmenting path is an s–t path in the residual graph Gf. Define dist⁡(v) to be the length of the shortest path from s to v in Gf. Then the level graph of Gf is the graph GL=((V,EL),cf|EL,s,t), where EL={(u,v)∈Ef:dist⁡(v)=dist⁡(u)+1}. A blocking flow is an s–t flow f′ such that the graph G′=((V,EL′),s,t) with EL′={(u,v):f′(u,v)<cf|EL(u,v)} contains no s–t path.

Algorithm Dinic's Algorithm

Input: A network G=((V,E),c,s,t). Output: An s–t flow f of maximum value. Set f(e)=0 for each e∈E. Construct GL from Gf of G. If dist⁡(t)=∞, stop and output f. Find a blocking flow f′ in GL. Augment flow f by f′ and go back to step 2.

Analysis It can be shown that the number of layers in each blocking flow increases by at least 1 each time and thus there are at most |V|−1 blocking flows in the algorithm. For each of them:

the level graph GL can be constructed by breadth-first search in O(E) time a blocking flow in the level graph GL can be found in O(VE) time with total running time O(E+VE)=O(VE) for each layer. As a consequence, the running time of Dinic's algorithm is O(V2E). Using a data structure called dynamic trees (specifically link-cut trees developed by Daniel Sleator and Robert Tarjan), the running time of finding a blocking flow in each phase can be reduced to O(|E|log⁡|V|). This is achieved by representing the active paths in the level graph as a forest of dynamic trees, which allows path operations such as finding the bottleneck capacity, pushing flow, and cutting saturated edges to be performed in O(log⁡|V|) amortized time per operation. Consequently, the total running time of Dinic's algorithm is improved to O(|V||E|log⁡|V|).

Special cases In networks with unit capacities, a much stronger time bound holds. Each blocking flow can be found in O(E) time, and it can be shown that the number of phases does not exceed O(E) and O(V2/3). Thus the algorithm runs in O(min⁡{V2/3,E1/2}E) time. In networks that arise from the bipartite matching problem, the number of phases is bounded by O(V), therefore leading to the O(VE) time bound. The resulting algorithm is also known as Hopcroft–Karp algorithm. More generally, this bound holds for any unit network — a network in which each vertex, except for source and sink, either has a single entering edge of capacity one, or a single outgoing edge of capacity one, and all other capacities are arbitrary integers.

Example The following is a simulation of Dinic's algorithm. In the level graph GL, the vertices with labels in red are the values dist⁡(v). The paths in blue form a blocking flow.

See also Ford–Fulkerson algorithm Maximum flow problem

Notes

References Dinitz, Yefim (2006). "Dinitz' Algorithm: The Original Version and Even's Version". In Oded Goldreich; Arnold L. Rosenberg; Alan L. Selman (eds.). Theoretical Computer Science: Essays in Memory of Shimon Even. Lecture Notes in Computer Science. Vol. 3895. Springer. pp. 218–240. doi:10.1007/11685654_10. ISBN 978-3-540-32880-3. Kadar, Ilan; Albagli, Sivan (18 April 2019). Dinitz's algorithm for finding a maximum flow in a network. Ben-Gurion University. Archived from the original on 22 December 2023. Korte, B. H.; Vygen, Jens (2008). "8.4 Blocking Flows and Fujishige's Algorithm". Combinatorial Optimization: Theory and Algorithms (Algorithms and Combinatorics, 21). Springer Berlin Heidelberg. pp. 174–176. ISBN 978-3-540-71844-4. Tarjan, R. E. (1983). Data structures and network algorithms.

Illustrations

Dinic's algorithm illustration
Dinic's algorithm illustration
Dinic's algorithm illustration
Dinic's algorithm illustration
Dinic's algorithm illustration

Worked examples

Example 1 — a first encounter with Dinic's algorithm

Start with the simplest possible case. Write down what Dinic's algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Dinic's algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Dinic's algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Dinic's algorithm

In research
Dinic's algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Dinic's algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Dinic's algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Graph algorithms, Network flow problem, so understanding it makes those chapters shorter.
In everyday life
Look for Dinic's algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Dinic's algorithm” →

How to study Dinic's algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Dinic's algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Dinic's algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Dinic's algorithm in simple terms?

Dinic's algorithm or Dinitz's algorithm is a strongly polynomial algorithm for computing the maximum flow in a flow network, conceived in 1970 by Israeli (formerly Soviet) computer scientist Yefim Dinitz. The algorithm runs in O(|V|2|E|) time and is similar to the Edmonds–Karp algorithm, which runs…

Why does Dinic's algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Dinic's algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Dinic's algorithm.

Tags

  • Graph algorithms
  • Network flow problem

Keep exploring