View on GitHub

Network Flow

Network Flow Modeling for Algorithms and Algorithm Analysis

Network Flow Example

This project provides a simple implementation and example of finding the maximum flow of a network.

This implements the Edmonds-Karp algorithm for Ford-Fulkerson using breadth-first search and an adjacency representation of the network.

Utility class: MaxFlowExample

JUnit 5 Test class: MaxFlowExampleTest

Software Development Observation

Why use a Record?

The first draft used side-effects in Java, where a method modifies an object passed to it. The residualGraph array was passed into the method as a mutable object to be modified by the method. It is a simple way to “return” multiple pieces of information, in this case the int flow (return value) and the int[][] graph.

Argument Against Side-Effects (clean code)

Most modern programming paradigms (especially Functional Programming) argue for immutability. When a method modifies an object passed into it:

Why do we treat returning the parent array and the residualGraph differently?

There is a subtle but important distinction in how these two arrays function within the logic:


Network Flow Example provides learners with a framework for experimenting with network flow algorithms.

Copyright (c) 2026, Dr. Jody Paul

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.