Enhance docs, add more tests in FordFulkerson (#5953)

This commit is contained in:
Hardik Pawar
2024-10-23 23:37:04 +05:30
committed by GitHub
parent 4f7957ff14
commit 520e46443e
2 changed files with 140 additions and 0 deletions

View File

@ -3,12 +3,30 @@ package com.thealgorithms.datastructures.graphs;
import java.util.LinkedList;
import java.util.Queue;
/**
* This class implements the Ford-Fulkerson algorithm to compute the maximum flow
* in a flow network.
*
* <p>The algorithm uses breadth-first search (BFS) to find augmenting paths from
* the source vertex to the sink vertex, updating the flow in the network until
* no more augmenting paths can be found.</p>
*/
public final class FordFulkerson {
private static final int INF = Integer.MAX_VALUE;
private FordFulkerson() {
}
/**
* Computes the maximum flow in a flow network using the Ford-Fulkerson algorithm.
*
* @param vertexCount the number of vertices in the flow network
* @param capacity a 2D array representing the capacity of edges in the network
* @param flow a 2D array representing the current flow in the network
* @param source the source vertex in the flow network
* @param sink the sink vertex in the flow network
* @return the total maximum flow from the source to the sink
*/
public static int networkFlow(int vertexCount, int[][] capacity, int[][] flow, int source, int sink) {
int totalFlow = 0;