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.[1] The algorithm runs in
O(|V|2|E|)
O(|V||E|2)
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 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.
Let
G=((V,E),c,f,s,t)
c(u,v)
f(u,v)
(u,v)
The residual capacity is a mapping
cf\colonV x V\toR+
(u,v)\inE
cf(u,v)=c(u,v)-f(u,v)
(v,u)\inE
cf(u,v)=f(v,u)
cf(u,v)=0
The residual graph is an unweighted graph
Gf=((V,Ef),cf|
Ef |
,s,t)
Ef=\{(u,v)\inV x V\colon cf(u,v)>0\}
An augmenting path is an
s
t
Gf
Define
\operatorname{dist}(v)
s
v
Gf
Gf
GL=((V,EL),cf|
EL |
,s,t)
EL=\{(u,v)\inEf\colon \operatorname{dist}(v)=\operatorname{dist}(u)+1\}
A blocking flow is an
s
t
f'
G'=((V,EL'),s,t)
EL'=\{(u,v)\colon f'(u,v)<cf|
EL |
(u,v)\}
s
t
Dinic's Algorithm
Input: A network
G=((V,E),c,s,t)
Output: An
s
t
f
f(e)=0
e\inE
GL
Gf
G
\operatorname{dist}(t)=infty
f
f'
GL
f
f'
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
GL
O(E)
GL
O(VE)
with total running time
O(E+VE)=O(VE)
O(V2E)
Using a data structure called dynamic trees, the running time of finding a blocking flow in each phase can be reduced to
O(ElogV)
O(VElogV)
In networks with unit capacities, a much stronger time bound holds. Each blocking flow can be found in
O(E)
O(\sqrt{E})
O(V2/3)
O(min\{V2/3,E1/2\}E)
In networks that arise from the bipartite matching problem, the number of phases is bounded by
O(\sqrt{V})
O(\sqrt{V}E)
The following is a simulation of Dinic's algorithm. In the level graph
GL
\operatorname{dist}(v)
G | Gf | GL | |||
---|---|---|---|---|---|
1. | |||||
The blocking flow consists of \{s,1,3,t\} \{s,1,4,t\} \{s,2,4,t\} | f | is 14. Note that each augmenting path in the blocking flow has 3 edges. | |||
2. | |||||
The blocking flow consists of \{s,2,4,3,t\} | f | is 14 + 5 = 19. Note that each augmenting path has 4 edges. | |||
3. | |||||
Since t Gf | |||||
(u,v)
f'(u,v)=cf|
EL |
(u,v)
s
t
s
t
O(E)
O(V2/3)
O(\sqrtE)