Data Structures and Algorithms • C# examples
Maximum Flow and Residual Graphs
Compute the greatest feasible flow from a source to a sink in a capacitated network.
Concept
A flow respects edge capacities and conservation at intermediate vertices. Residual edges represent how existing flow can be adjusted or canceled. Ford-Fulkerson repeatedly augments along residual paths; Edmonds-Karp uses BFS to choose paths and obtains a polynomial bound.
How to approach it
Maintain reverse residual edges and update both forward and reverse capacities after every augmentation.
Complexity
Edmonds-Karp O(VE²); faster algorithms exist for larger networks.
C# example
// Find a source-to-sink path in the residual graph.
// Let delta be its smallest remaining edge capacity.
// Subtract delta on forward edges and add delta on reverse edges.
flow += delta;
Expected result or behavior
When no residual path remains, the current flow is maximum.
Practice exercise
Trace one augmentation and show how a reverse edge permits rerouting previous flow.
Key takeaway: Residual capacity is what makes greedy-looking augmentation globally correct.