Hey everyone!
We were taught basic network flow in our algorithms course in university and I started to learn it. Found this useful blog blog by Zhtluo link
Target Audience.
This post is for anyone who has some free time :)
Basic
Bipartite Matching Example
Suppose we have two sets:
Set A = people Set B = books
Each person likes certain books, and we want to find the maximum number of unique person-book matches, where each person gets exactly one book they like.
Here’s how Network Flow helps: Connect the source to all people. Connect each person to the books they like. Connect all books to the sink.
Then, when we run a maximum flow algorithm, the maximum flow value will tell us the number of unique person-book pairs that can be matched.
This is basically the maximum bipartite matching problem.

The Ford–Fulkerson Algorithm
We keep finding paths from the source to the sink that still have some remaining capacity, and push as much flow as possible through them — until no such paths exist.
Steps
Use DFS to find a path from source to sink.
Find the smallest capacity (bottleneck) along that path.
Send that much “water” (flow) through the path.
Add a reverse edge to allow undoing flow later.
Repeat until no more augmenting paths exist.
Time Complexity
O(E × f) where f is the value of the maximum flow.
Code
It’s conceptually simple but can be slow if the capacities are large because runtime depends directly on the flow value.
The Edmonds–Karp Algorithm
This is an optimized version of Ford–Fulkerson that uses BFS instead of DFS to find augmenting paths.
Why BFS? Using DFS can lead to zig-zagging paths that push very little flow each time, making the algorithm slow. BFS ensures we always find the shortest path (in terms of number of edges), which makes the process much more efficient.
Steps
Use BFS to find the shortest augmenting path.
Find the bottleneck capacity on that path.
Push flow along the path and update reverse edges.
Repeat until no more augmenting paths exist.
Time Complexity
O(V × E²)
This guarantees a polynomial runtime
Code
PRACTICE PROBLEMS
Again, if possible, please provide new perspectives and interesting problems to explore using this algorithm








Auto comment: topic has been updated by deinepapa (previous revision, new revision, compare).
Real men use the $$$O(n^{1+\varepsilon})$$$ flow algorithm.