Learn
Lesson · Networks: Flows, Paths and Assignments · Paths, cuts and matchings

Bipartite Matching and Hall's Condition

A matching is a flow. Put a unit arc from a source to every applicant, keep every original edge at capacity one, and put a unit arc from every job to a sink: a flow of value k is a matching of size k, and it comes out whole because of the matrix. Then the minimum cut is not just a bound — it names a set of applicants whose jobs between them are too few, which is Hall's condition failing, and it is a certificate anybody can check by counting.

matching: a set of edges no two of which share a vertex the reduction: src>each applicant at 1, each edge at 1, each job>snk at 1 a flow of value k on that network is a matching of size k, and it is whole Hall: a matching saturating X exists ⟺ every S ⊆ X has |N(S)| ≥ |S| if the matching falls short, S = the applicants on the source side of the min cut Koenig: smallest vertex cover = largest matching the Hungarian cover, again
The reduction, the theorem, and where the violating set comes from

Core ideas

What this lesson establishes

The reduction is three lines and the integrality is already proved. What this lesson adds is that the failure comes with a reason attached.

1

A matching is a flow, and the flow is whole for a reason

Unit arcs from a source to the applicants, the original edges at capacity one, unit arcs from the jobs to a sink. Any integral flow of value k saturates k of the source arcs and k of the sink arcs and uses k edges no two of which share an endpoint — a matching. And the flow is integral because the constraint matrix is the one already swept for total unimodularity: half an applicant is excluded by the matrix, not by the algorithm.

2

Hall's condition is necessary for an obvious reason and sufficient for a hard one

If some set S of applicants has fewer jobs between them than there are members of S, clearly not all of S can be placed. That direction is counting. The content of the theorem is the converse, and the flow argument supplies it constructively: when the maximum matching falls short, the minimum cut produces the violating S.

3

The certificate is a set, and checking it is counting

The lab prints S, its neighbourhood N(S) and the difference. Verifying the claim means listing the jobs those applicants are willing to take and counting them — no algorithm, no trust. That is the same shape as a cut certifying a flow and a critical path certifying a project length, which by now is the point of the whole course.

The material

Matchings as flows, and the set the cut hands back

The reduction, then the theorem, then the three instances: one where every job is filled and somebody is still left out, one where the deficient set is small, and one where nothing is deficient.

Definition · Matchings, and Hall's condition

In a bipartite graph with parts X and Y, a matching is a set of edges no two of which share a vertex. It saturates X when every member of X is in one of its edges.

For S ⊆ X, write N(S) for the set of vertices in Y joined to at least one member of S. Hall's condition is that |N(S)| ≥ |S| for every S ⊆ X.

Theorem · Hall's marriage theorem

A bipartite graph has a matching saturating X if and only if |N(S)| ≥ |S| for every subset S of X.

Discrete Mathematics states this in “Bipartite Graphs” and does not prove the sufficient direction. This lesson supplies it as a consequence of max-flow min-cut, and does so constructively: when the maximum matching misses a vertex, the minimum cut of the flow network exhibits the violating S.

The reduction is short enough to keep in your head. Add a source with a capacity-one arc to each member of X; keep every edge of the graph as an arc of capacity one; add a sink with a capacity-one arc from each member of Y. On a three-applicant, two-job instance that is seven nodes and eleven arcs.

the graph 1-a 1-b 2-a 2-b 3-a 3-b the network src>1 src>2 src>3 each capacity 1 1>a 1>b 2>a 2>b 3>a 3>b each capacity 1 a>snk b>snk each capacity 1 7 nodes, 11 arcs maximum flow 2 and the linear programme agrees: 2 maximum matching 2 of 3 minimum cut {src, 1, 2, 3, a, b} capacity 2 S = the applicants on the source side = {1, 2, 3} N(S) = {a, b} |N(S)| - |S| = -1 Hall FAILS on S

Both jobs are filled, and an applicant is still left out. Those two sentences are not in tension: there are three applicants and two jobs, and a matching saturating the applicants would need three distinct jobs. The certificate is the whole of X here, and it takes one sentence to check — all three applicants will take only a or b, and there are two of those.

The deficient set need not be everybody

Example · Three sharing one job, and a fourth with three of its own

Edges 1-a, 2-a, 3-a, 4-b, 4-c, 4-d. The maximum matching has two edges out of a possible four, the minimum cut has capacity 2, and the deficient set the cut names is S = {1, 2, 3} with N(S) = {a}.

Three applicants, one job between them, a shortfall of two. Applicant 4 is not part of the certificate at all — it has three jobs to itself and is doing nothing wrong. A reader who expects the violating set to be all of X will not find it here, and the searching that follows is exactly what the minimum cut saves.

Example · Nothing deficient, and nothing to produce

Edges 1-a, 1-b, 2-b, 2-c, 3-c, 3-d, 4-d, 4-a: four applicants in a ring with four jobs. The maximum matching has four edges, every applicant is placed, and the minimum cut has capacity 4 — the set {src} alone.

S and N(S) come back empty and the lab reports that Hall's condition holds on every subset. There is nothing to certify: the alternating search that produces the violating set starts from the unmatched applicants, and here there are none. Remove one edge and the certificate appears.

The same theorem, a third time

König's theorem — that in a bipartite graph the smallest vertex cover has exactly as many vertices as the largest matching — is the same statement again. The lab computes the cover from the matching, and it is the cover the Hungarian method was counting when it drew lines through the zeros. On the three-applicant instance the cover is the two jobs; on the three-sharing-one instance it is applicant 4 together with job a.

So the assignment lesson's cover step, this lesson's deficient set, and the maximum-flow theorem are three readings of one fact. That is not a coincidence worth admiring; it is the reason the assignment problem can be solved by a method with a stopping proof, and the reason that method's most delicate step is the one this lesson has now justified.

One limitation to state plainly. All of this is about bipartite graphs. Matching in a general graph is a genuinely harder problem with a different theory, its own theorem about odd sets, and an algorithm this path does not contain. The boundary is exactly the odd cycle that broke total unimodularity in the integrality lesson, which is a pleasing place for a course to end.

Interactive

Bipartite matching and Hall's theorem

When the matching falls short, the minimum cut hands you the set with too few neighbours

Hall's condition, read off the cutif a maximum matching misses a vertex, the cut hands you S with |N(S)| < |S|
an edge in the matchingthe source side of the cutan arc crossing the cut

Method

Deciding whether everyone can be placed, and proving it either way

Build the network, find the flow, and then take whichever of the two certificates the answer offers you.

1

Build the unit-capacity network

Source to every applicant at capacity one, every edge at capacity one, every job to the sink at capacity one. Every capacity is one; a capacity of two anywhere means somebody is being allowed two jobs, and that is a different problem.

2

Find a maximum flow, and read the matching off it

The arcs between the two sides carrying one unit are the matched pairs. The flow is whole automatically — this is a network, and its matrix is totally unimodular — so there is no rounding step and no half-matched applicant to interpret.

3

Compare the matching's size with the number of applicants

Equal, and everybody is placed. Short, and there is a certificate to produce, which is the interesting case and the one most write-ups skip.

4

If it is short, take S from the minimum cut

S is the set of applicants on the source side of the minimum cut. Write it down with N(S), and check the count: |N(S)| < |S|. That inequality is the answer to “why can they not all be placed”, and it is checkable without re-running anything.

5

If it is not short, say what has been proved and what has not

A saturating matching exists and you have one. Hall's condition holds on every subset, but you have not checked every subset and you do not need to: the matching itself is the certificate in this direction.

The reduction, the certificate, and what it does not say

Score 0 / 0

Three graphs: one certificate, a smaller certificate, and none

Each block is the maximum matching, the minimum cut of the flow network, and the deficient set the cut names. All of it is what the lab reports.

GRAPH 1 1-a, 1-b, 2-a, 2-b, 3-a, 3-b 3 applicants, 2 jobs network 7 nodes, 11 arcs, every capacity 1 maximum flow 2 LP on the same network: 2 matching 2 of 3 minimum cut {src, 1, 2, 3, a, b} capacity 2 S = {1, 2, 3} N(S) = {a, b} |N(S)| - |S| = -1 minimum vertex cover {a, b}, size 2 = the matching Koenig GRAPH 2 1-a, 2-a, 3-a, 4-b, 4-c, 4-d 4 applicants, 4 jobs network 10 nodes, 14 arcs matching 2 of 4 minimum cut {src, 1, 2, 3, a} capacity 2 S = {1, 2, 3} N(S) = {a} |N(S)| - |S| = -2 applicant 4 is NOT in the certificate; it has three jobs to itself minimum vertex cover {4, a}, size 2 GRAPH 3 1-a, 1-b, 2-b, 2-c, 3-c, 3-d, 4-d, 4-a network 10 nodes, 16 arcs matching 4 of 4 every applicant placed minimum cut {src} capacity 4 S = {} N(S) = {} nothing to certify minimum vertex cover {1, 2, 3, 4}, size 4 REFUSALS an edge without a dash is refused six vertices on one side is refused: the drawing takes five

Graph 1 is the one that catches people. Every job is filled — the matching saturates the jobs perfectly — and an applicant is still left out, because saturating the applicants is a different requirement. The certificate is about the applicants, and it says the whole of X has only two jobs between it.

For a rehearsal, take graph 2 and add the edge 1-b. The matching goes to three and the certificate shrinks: the deficient set is now {2, 3} with a single job between them. Keep adding edges and watch the set contract until it disappears.

The harder rehearsal: take graph 3 and remove 4-a. Everybody is still placed, because the ring had slack in it. Remove 4-d as well and applicant 4 has nothing left; the certificate that appears is S = {4} with N(S) empty, which is the smallest violation there is.

Common mistakes

1
Expecting the deficient set to be all of the applicantsIt sometimes is and usually is not. On the lab's second instance it is three of the four, and adding the fourth would destroy the inequality rather than strengthen it. The certificate is a particular subset, the minimum cut produces it, and guessing is what the reduction exists to avoid.
2
Reading a matching that fills every job as a matching that places every applicantThe lab's first instance fills both jobs and leaves an applicant out. Saturating Y and saturating X are different conditions, and Hall's theorem is about the side you are trying to place. Say which side you mean before claiming anything about the answer.
3
Carrying the theorem across to general graphsHall's condition and the whole flow reduction are about bipartite graphs. Matching in a general graph has a different characterisation, a different algorithm, and no unit-capacity network that captures it — the obstruction is the odd cycle, the same one whose incidence matrix failed total unimodularity earlier on this course.

Check your understanding

✓
Finish when you can decide a placement question and hand back the right certificate for whichever answer you get.

You should be able to build the unit-capacity network from a bipartite graph, read a matching off a flow, explain why the flow is whole, produce the deficient set from the minimum cut when the matching falls short, check |N(S)| < |S| by counting, and say why a saturating matching needs no further certificate.

Note: That is the course: one linear programme, one matrix, and four duals that turned out to be a set of prices, a chain of activities, a set of nodes and a set of applicants. The next course keeps the linear programme and throws away the matrix. Integer Programming is what remains when the corners are not lattice points — when rounding is not an answer, when a relaxation is only a bound, and when the honest deliverable stops being a certificate of optimality and becomes a gap.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.