codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🧮

Data Structures & Algorithms

55 / 65 topics
54Network Flow Problems55Ford-Fulkerson Method56Edmonds-Karp Algorithm57Dinic's Algorithm
Tutorials/Data Structures & Algorithms/Ford-Fulkerson Method
🧮Data Structures & Algorithms

Ford-Fulkerson Method

Updated 2026-04-20
3 min read

Introduction

The Ford-Fulkerson method is a fundamental algorithm for computing the maximum flow in a flow network, which is a directed graph where each edge has a capacity and each edge receives a flow. The goal is to determine the maximum amount of flow that can be sent from a source node to a sink node without violating the capacity constraints on the edges.

Understanding Network Flows

Definitions

  • Flow Network: A directed graph \( G = (V, E) \) where each edge \( e \in E \) has a non-negative capacity \( c(e) \). There are two distinguished nodes: the source \( s \) and the sink \( t \).

  • Flow: An assignment of values to the edges such that:

    • Capacity Constraint: For every edge \( (u, v) \), \( 0 \leq f(u, v) \leq c(u, v) \).
    • Flow Conservation: For every node \( v \neq s, t \), the total flow into \( v \) equals the total flow out of \( v \).
  • Residual Graph: A graph that shows the remaining capacity after sending a certain amount of flow. It helps in finding augmenting paths.

Ford-Fulkerson Method

Overview

The Ford-Fulkerson method is based on the idea of repeatedly finding an augmenting path from the source to the sink in the residual graph and increasing the flow along this path until no more such paths exist. The algorithm uses a search strategy, typically Depth-First Search (DFS) or Breadth-First Search (BFS), to find these paths.

Steps

  1. Initialize Flow: Set the initial flow \( f(u, v) = 0 \) for all edges.
  2. Find Augmenting Path: Use a search algorithm to find an augmenting path from the source \( s \) to the sink \( t \) in the residual graph.
  3. Calculate Residual Capacity: Determine the minimum residual capacity along the found path.
  4. Augment Flow: Increase the flow along this path by the calculated residual capacity.
  5. Update Residual Graph: Modify the capacities of the edges and reverse edges based on the augmented flow.
  6. Repeat: Repeat steps 2-5 until no more augmenting paths can be found.

Pseudocode

function fordFulkerson(graph, source, sink) {
    let parent = new Array(graph.length).fill(null);
    let maxFlow = 0;

    while (bfs(graph, source, sink, parent)) {
        let pathFlow = Infinity;
        for (let v = sink; v !== source; v = parent[v]) {
            let u = parent[v];
            pathFlow = Math.min(pathFlow, graph[u][v]);
        }

        for (let v = sink; v !== source; v = parent[v]) {
            let u = parent[v];
            graph[u][v] -= pathFlow;
            graph[v][u] += pathFlow;
        }

        maxFlow += pathFlow;
    }

    return maxFlow;
}

function bfs(graph, s, t, parent) {
    let visited = new Array(graph.length).fill(false);
    let queue = [];
    queue.push(s);
    visited[s] = true;

    while (queue.length > 0) {
        let u = queue.shift();

        for (let v = 0; v < graph[u].length; v++) {
            if (!visited[v] && graph[u][v] > 0) {
                queue.push(v);
                visited[v] = true;
                parent[v] = u;

                if (v === t)
                    return true;
            }
        }
    }

    return false;
}

Explanation

  • bfs: This function performs a Breadth-First Search to find an augmenting path from the source \( s \) to the sink \( t \). It returns true if such a path exists, otherwise false.

  • fordFulkerson: This function implements the Ford-Fulkerson method. It repeatedly calls bfs to find augmenting paths and updates the flow until no more paths can be found.

Real-World Example

Consider a network with four nodes (A, B, C, D) where A is the source and D is the sink. The capacities of the edges are as follows:

A -> B: 10
A -> C: 5
B -> C: 6
B -> D: 8
C -> D: 10

We can represent this network as an adjacency matrix and apply the Ford-Fulkerson method to find the maximum flow from A to D.

const graph = [
    [0, 10, 5, 0], // A
    [0, 0, 6, 8],  // B
    [0, 0, 0, 10], // C
    [0, 0, 0, 0]   // D
];

const source = 0;
const sink = 3;

console.log(fordFulkerson(graph, source, sink)); // Output: 15

In this example, the maximum flow from A to D is 15 units.

Best Practices

  • Choose Appropriate Search Strategy: While BFS is commonly used for its simplicity and guarantee of finding a shortest path in terms of edges, DFS can also be used. However, DFS does not guarantee the shortest augmenting path.

  • Edge Cases: Handle cases where the graph has no path from source to sink or when all capacities are zero.

  • Optimization: The Ford-Fulkerson method can be optimized using various techniques such as Dijkstra's algorithm for finding the shortest path in terms of capacity (Edmonds-Karp algorithm) or by using blocking flows.

Conclusion

The Ford-Fulkerson method is a powerful tool for solving network flow problems. By understanding its principles and implementing it correctly, you can efficiently determine the maximum flow in complex networks. Whether you're working on logistics, telecommunications, or any other field that involves resource allocation, mastering this algorithm will provide you with valuable insights and solutions.


PreviousNetwork Flow ProblemsNext Edmonds-Karp Algorithm

Recommended Gear

Network Flow ProblemsEdmonds-Karp Algorithm