Unit 9 of 9 · about 2 hours · explain
Flow and matching at recognition depth
Flows and matchings are recognition vocabulary at this stage: routing, assignment and cut problems recur across ML systems, and naming the reduction correctly is the transferable skill.
You'll be able to
- State the max-flow min-cut theorem and explain how an equal-value cut certifies a claimed maximum flow.
- Reduce bipartite matching to max flow with a source, a sink and unit capacities, and read a matching back from the flow.
- Recognize flow-shaped problems (capacities, bottlenecks, conflict-free assignment) and name what a full implementation would still need.
Covers
Read
In this order, only the parts listed
0 of 2 done
- Maximum Flows and Minimum Cuts, Chapter 10Algorithms - graph chapters
10.1 Flows, 10.2 Cuts, 10.3 The Maxflow-Mincut Theorem and 10.4 Ford and Fulkerson's augmenting-path algorithm (printed pp. 328-336)
- Flow applications including bipartite matching, Chapter 11Algorithms - graph chapters
11.1 Edge-Disjoint Paths and 11.3 Bipartite Matching with the source-sink unit-capacity reduction (printed pp. 353-357)
Read the reductions and state the constructions; skip implementing Dinic or push-relabel here.
Focus on
- Recognition signals: capacities on edges plus a bottleneck question means flow; two-sided assignment with conflicts (left set, right set, allowed pairs) means bipartite matching.
- The certificate is the cut: a flow of value with a cut of capacity is maximum by the theorem. Always exhibit both.
- Bipartite matching is flow with unit capacities: source to left, allowed edges left to right, right to sink; integer flow of value is a matching of size .
- Explicit non-goals: residual-graph implementation at scale, Dinic or push-relabel, general (non-bipartite) matching and spectral methods stay in the section's leave-for-later list.
Common mistakes · 3
- Augmenting without residual backward edges: the greedy path choice gets stuck below maximum because it cannot undo earlier flow. Backward edges with residual capacity are the algorithm, not an optimization.
- Confusing bipartite check with bipartite matching: two-coloring decides a partition exists; matching finds the largest conflict-free edge set given one. LC 785 does not solve LC 1349.
- Undirected edges as single arcs: an undirected edge of capacity
cbecomes two opposite arcs of capacityc. One arc forbids flow in the other direction and can silently lower the maximum.
Try it yourself
Closed-book, before checking anything
[(0,1,3),(0,2,2),(1,2,1),(1,3,2),(2,3,3)] from 0 to 3 and report max flow 5. Exhibit the certifying cut ( versus ) with capacity 3 + 2 = 5.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.State the max-flow min-cut theorem and its use as a certificate.Answer
The value of a maximum - flow equals the capacity of a minimum - cut. A flow of value plus a cut of capacity proves optimality without trusting the solver: no flow can exceed any cut's capacity.
2.Give the bipartite-matching-to-flow reduction exactly.Answer
Source to each left vertex capacity 1, each allowed left-right pair capacity 1, each right vertex to sink capacity 1. Integer max flow of value saturates disjoint pairs: a matching of size , and every matching yields such a flow.
3.Why does LC 1349 admit a matching model?Answer
Color seats by column parity. Every conflict (left, right, upper-left, upper-right) joins an even column to an odd one, so the conflict graph is bipartite. The answer is a maximum independent set of free seats, which on a bipartite graph equals the number of free seats minus a maximum matching (Konig's theorem). A checkerboard coloring fails: diagonal neighbors share a color.
4.What stays deliberately excluded, and why can you stop?Answer
Dinic, push-relabel, general-graph matching and spectral methods: the section checkpoint needs recognition plus a small checked construction, and the section's leave-for-later list names the rest.
Practice
- LeetCode 1349: Maximum Students Taking Exam
The three listed examples (mixed boards with blocked seats)
Recognition framing only: state the column-parity reduction to bipartite matching, solve with a simple augmenting-path matcher, and verify against brute force on boards. Do not implement Dinic. After-attempt reference is Erickson Section 11.3.
You're done when
Your blank-file script prints max flow 5 with the capacity-5 cut, and you can reduce a new assignment narrative to source-sink-unit capacities or explain why it is not a flow problem.
Only when you can do this without notes.
Leads to
Notes
Resources · 1 for this unit, 4 more in the section
- Algorithms - graph chaptersJeff Erickson · required
Use the basic graph, depth-first search, minimum spanning tree, shortest path and flow chapters, and lecture note 11 Disjoint Sets for union-find, for correctness proofs and counterexamples to tempting wrong algorithms.
Also in this section
- DSA Handbook - graphsHandbook Academy · primary
Study all of Part 8 in order. For each algorithm, write the representation, invariant, forbidden input assumptions and independently checkable output before reading the implementation.
- AlgoMaster DSA - graph sliceAlgoMaster · required
Attempt Number of Islands, Course Schedule II and Network Delay Time cold. They cover traversal, dependency modeling and weighted shortest paths; add one narrative problem only if graph modeling remains weak.
- Hypothesis - generated graph testsHypothesis · support
Generate small sparse, dense, disconnected, cyclic, parallel-edge and weighted graphs. Compare optimized results with exhaustive or deliberately simple references and retain shrunk failures.
- NeetCode - unseen graph problemsNeetCode · optional
Use two unseen story problems without graph tags. Grade the model, assumptions, certificate and tests as well as the final answer.