Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 03 · DSA · Worked, and deeper · about 17 min to read

Play it as a journeyTutor comes with a plan

Pushing water through pipes: max flow and matching

Graphs
Graphs · Open board

The graph board: dots joined by lines. This lesson gives every line a number, the most it can carry, and asks how much can pass through the whole graph.

In 1955 two analysts at the RAND Corporation, T. E. Harris and F. S. Ross, wrote a report on the Soviet and Eastern European railway network. They drew it as a graph. Each rail line got a number, the tons it could carry. Then they asked two questions. What is the most that can travel from Russia into Eastern Europe? And which lines, taken together, are the weak point that limits it? Their answer to both was the same number: 163,000 tons.

By the end of this lesson you will be able to find the largest flow through a network with the Edmonds-Karp method, name the pipes that limit it, and turn a matching problem into a flow problem.

The history (optional)

The report is RAND memorandum RM-1573. Alexander Schrijver’s history (see Go deeper) says 163,000 appears twice in it: as a flow, and as the capacity of lines that cut the network in two. Harris and Ross cared more about the cut. Ford and Fulkerson, also at RAND, cited it and published the augmenting path method in 1956. Yefim Dinitz published a faster version in 1970. Jack Edmonds and Richard Karp published the version in this lesson in the Journal of the ACM, volume 19, issue 2, April 1972, pages 248 to 264.

Before you start. Shortest Paths, Worked (Dijkstra, Bellman-Ford, A*) gave you graphs whose roads carry numbers, and the move of changing a number when a better route appears. Graphs (BFS, DFS, Dijkstra, topological sort) gave you BFS, which finds a path with the fewest roads by checking the nearest places first. This lesson uses BFS to choose paths, so you need nothing else.

Lesson 21 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • A flow network: pipes with a capacity
  • Why pushing along a path can get stuck
  • A residual pipe: room left, and room to undo
  • Ford-Fulkerson and Edmonds-Karp: keep augmenting, choose the shortest
  • Minimum cut: the pipes that limit the flow
  • Bipartite matching: three riders, three orders
  • Edmonds-Karp, whole
  • The reverse pipe, drawn
  • LC 785, Is Graph Bipartite?
  • LC 1349, Maximum Students Taking Exam
  • Cost and limits

Terms it explains: capacity, flow, maximum flow, residual, augmenting path, Ford-Fulkerson, Edmonds-Karp, cut, minimum cut, max-flow min-cut theorem, bipartite matching, Common mistakes, LC 886, Possible Bipartition, A*, adjacency list, adjacency matrix, Bellman-Ford, BFS, DAG, DFS, Dijkstra, directed vs undirected, in-degree, MST, relax an edge, sparse vs dense, topological sort, union-find, vertex/edge, weighted.

Lab

Every find walks a chain of houses up to the root. In the worst order, how long can that chain get, and what keeps it short?

Drag Cables joined to the end, then switch The habits and watch Tallest chain fall from 31 to 5.

Open The short chains

Review DSA