Discrete MathematicsPlanarity, Coloring and Matching3 of 4
Planarity, Coloring and Matching · 3

Bipartite Matching and Hall's Theorem

When a group of people apply to jobs they are qualified for, we want to assign people to jobs so that nobody gets two jobs and no two people share a job.

Matchings in Bipartite Graphs
people\text{people}
A\text{A}
B\text{B}
C\text{C}
D\text{D}
E\text{E}
11
22
33
44
55
jobs\text{jobs}

Splitting the dots into people on the left and jobs on the right gives a bipartite graph, where every line goes from a person to a job they can do. A matching is any choice of highlighted lines where no two highlighted lines share a dot:

Matching⏟no person gets 2 jobs,no job gets 2 people⟶Complete matching⏟every person on theleft gets a job⟶Perfect matching⏟every dot on bothsides is matched\displaystyle \begin{aligned} & \underbrace{\text{Matching}}_{\substack{\text{no person gets } 2\text{ jobs,}\\\text{no job gets } 2\text{ people}}} \\[4pt] \longrightarrow\quad & \underbrace{\text{Complete matching}}_{\substack{\text{every person on the}\\\text{left gets a job}}} \\[4pt] \longrightarrow\quad & \underbrace{\text{Perfect matching}}_{\substack{\text{every dot on both}\\\text{sides is matched}}} \end{aligned}
Complete and perfect\text{Complete and perfect}
(5 people, 5 jobs)\text{(5 people, 5 jobs)}
A\text{A}
B\text{B}
C\text{C}
D\text{D}
E\text{E}
11
22
33
44
55
Complete, not perfect\text{Complete, not perfect}
(5 people, 8 jobs)\text{(5 people, 8 jobs)}
A\text{A}
B\text{B}
C\text{C}
D\text{D}
E\text{E}
11
22
33
44
55
66
77
88
1

Making a Matching Bigger with Augmenting Paths

If we hand out jobs one by one from the top of the list, we can get stuck when the next person's only qualified jobs are already taken. Instead of starting over, we look for an augmenting path: a zig-zag chain that alternates between unselected lines and currently highlighted lines to shift people over until someone moves into an empty job.

On our 55-person board, suppose we start by matching A–1\matched{A\text{–}1}, B–2\matched{B\text{–}2}, and C–3\matched{C\text{–}3}. How can we fit DD, who is only qualified for Job 22, into the matching?

Augmenting Paths
A\text{A}
B\text{B}
C\text{C}
D\text{D}
E\text{E}
11
22
33
44
55
??
Text solution
Trace the alternating path from the unmatched person to an empty jobStart at DD, cross unselected lines to go from left to right and currently highlighted lines to go from right to left, and stop as soon as you reach the empty Job 44.
D→unselected2→highlightedB→unselected3→highlightedC→unselected4⏟augmenting path\displaystyle \underbrace{\begin{aligned} D &\trail{\xrightarrow{\text{unselected}}} 2 \trail{\xrightarrow{\matched{\text{highlighted}}}} B \\ &\trail{\xrightarrow{\text{unselected}}} 3 \trail{\xrightarrow{\matched{\text{highlighted}}}} C \\ &\trail{\xrightarrow{\text{unselected}}} 4 \end{aligned}}_{\trail{\text{augmenting path}}}
Flip every line along the pathUn-highlight the old matched lines in the chain and highlight the unselected ones, while leaving A–1\matched{A\text{–}1} untouched.
Un-highlight: B–2,  C–3⟶Highlight: D–2,  B–3,  C–4\displaystyle \begin{aligned} \text{Un-highlight: } & B\text{–}2,\; C\text{–}3 \\ \longrightarrow\quad \text{Highlight: } & \matched{D\text{–}2},\; \matched{B\text{–}3},\; \matched{C\text{–}4} \end{aligned}
New matching: A–1,  D–2,  B–3,  C–4\displaystyle \begin{aligned} & \text{New matching: } \\ & \matched{A\text{–}1},\; \matched{D\text{–}2},\; \matched{B\text{–}3},\; \matched{C\text{–}4} \end{aligned}

So DD gets Job 22, BB shifts to Job 33, and CC shifts to Job 44, growing our matching from 3\matched{3} lines to 4\matched{4}.

Because an augmenting path starts at an unmatched person on an unselected line and ends at an empty job on an unselected line, flipping the path always replaces k\matched{k} highlighted lines with k+1\matched{k + 1} highlighted lines without giving anyone two jobs.

Because an augmenting path starts and ends on unselected lines and alternates in between, flipping it always adds one more match without giving anyone two jobs.
2

Bottlenecks and Maximum Matchings

When an augmenting-path search runs out of new jobs to reach and hits a dead end, it exposes a bottleneck: a group of people on the left who together connect to fewer jobs on the right than there are people in the group. A bottleneck not only proves a complete matching is impossible, but also gives an upper bound on the size of the maximum matching, the largest matching the graph can hold.

Now that A–1\matched{A\text{–}1}, D–2\matched{D\text{–}2}, B–3\matched{B\text{–}3}, and C–4\matched{C\text{–}4} are matched, what happens when we try to match EE (who only connects to Jobs 11 and 22), and what is the largest possible matching on this board?

Bottlenecks and Maximum Matchings
A\text{A}
B\text{B}
C\text{C}
D\text{D}
E\text{E}
11
22
33
44
55
largest matching=  ?\text{largest matching} = \;?
Text solution
Count the people and jobs in the dead-end chainTrace every line leaving E\group{E} and the people holding E\group{E}'s jobs (A\group{A} and D\group{D}) to see how many jobs they connect to in total, then subtract to find how many people must go unmatched.
{A,D,E}⏟3 people  ⟶  {1,2}⏟2 jobs⟹3−2=1 person must be left out\displaystyle \begin{aligned} & \underbrace{\group{\{A, D, E\}}}_{\group{3\text{ people}}} \;\longrightarrow\; \underbrace{\jobsOf{\{1, 2\}}}_{\jobsOf{2\text{ jobs}}} \quad\Longrightarrow \\[4pt] & \group{3} - \jobsOf{2} = \leftOut{1}\text{ person must be left out} \end{aligned}
Bound the largest possible matchingSubtract that guaranteed unmatched person from the 55 total people on the left.
Largest possible matching size\displaystyle \text{Largest possible matching size} =5−1\displaystyle = 5 - \leftOut{1} =4\displaystyle = 4
Pair the bound with a matching of that sizeCombine the upper bound of 44 with the 44-line matching already on the board to prove we cannot do better.
Maximum matching (size 4): A–1,  D–2,  B–3,  C–4\displaystyle \begin{aligned} & \text{Maximum matching (size } 4\text{): } \\ & \matched{A\text{–}1},\; \matched{D\text{–}2},\; \matched{B\text{–}3},\; \matched{C\text{–}4} \end{aligned}

So 44 is the maximum matching size on this board, proved by a matching that reaches 44 and a bottleneck that rules out 55.

3

Hall's Theorem

A bottleneck clearly prevents a complete matching, and Hall's Theorem tells us the reverse is also true: a bottleneck is the only thing that can ever stop a complete matching. As long as every possible group of people on the left connects to at least as many jobs as there are people in that group, a complete matching is guaranteed.

Hall's Theorem
bottleneck  ⟹  can’t match everyonebottleneck  ⟸?  can’t match everyone\begin{aligned} \htmlClass{lc-orange}{\text{bottleneck}} &\;\Longrightarrow\; \text{can't match everyone} \\[2pt] \htmlClass{lc-orange}{\text{bottleneck}} &\;\overset{\textstyle ?}{\Longleftarrow}\; \text{can't match everyone} \end{aligned}

In symbols, Hall's Theorem says that a complete matching of the left side exists if and only if

for every subset S⏟group of peopleon the left,∣N(S)∣⏟number of jobsconnected to S  ≥  ∣S∣⏟number ofpeople in S\displaystyle \begin{aligned} & \text{for every subset } \underbrace{\group{S}}_{\substack{\text{group of people}\\\text{on the left}}}, \\[4pt] & \underbrace{|\jobsOf{N(S)}|}_{\substack{\text{number of jobs}\\\text{connected to } \group{S}}} \;\ge\; \underbrace{|\group{S}|}_{\substack{\text{number of}\\\text{people in } \group{S}}} \end{aligned}

Notice that N(S)\jobsOf{N(S)} counts each job connected to S\group{S} once, even if several people in S\group{S} have lines going to that same job.

Adding people to S\group{S} whose lines only go to already-highlighted jobs in N(S)\jobsOf{N(S)} makes ∣S∣|\group{S}| grow while ∣N(S)∣|\jobsOf{N(S)}| stays fixed, exposing a bottleneck the moment ∣N(S)∣<∣S∣|\jobsOf{N(S)}| \fails{<} |\group{S}|.

When you add people who only connect to jobs the group already reaches, the group grows while its job count stays the same, creating a bottleneck as soon as there are fewer jobs than people.
4

Systems of Distinct Representatives

Many problems never mention people, jobs, or bipartite graphs at all: instead, they give a list of sets and ask for a system of distinct representatives, which means picking one unique item from each set with no repeats. Turning the sets into the left side of a bipartite graph and the items into the right side makes this a complete matching problem.

Given the five sets A={1,2}A = \{1, 2\}, B={2,3}B = \{2, 3\}, C={1,3}C = \{1, 3\}, D={1,2,3}D = \{1, 2, 3\}, and E={2,4,5}E = \{2, 4, 5\}, can we pick one number from each set so that no number is picked twice?

Systems of Distinct Representatives
A={1,2}B={2,3}C={1,3}D={1,2,3}E={2,4,5}\displaystyle \begin{aligned} A &= \{1, 2\} \\ B &= \{2, 3\} \\ C &= \{1, 3\} \\ D &= \{1, 2, 3\} \\ E &= \{2, 4, 5\} \end{aligned}
one number from each set,no number picked twice?\displaystyle \begin{gathered}\text{one number from each set,} \\ \text{no number picked twice?}\end{gathered}
A\text{A}
B\text{B}
C\text{C}
D\text{D}
E\text{E}
11
22
33
44
55
∣S∣=4|\htmlClass{lc-blue}{S}| = 4
∣N(S)∣=3|\htmlClass{lc-violet}{N(S)}| = 3
Text solution
Turn the sets and numbers into a bipartite graphPut the sets A,B,C,D,EA, B, C, D, E as dots on the left and the numbers 1,2,3,4,51, 2, 3, 4, 5 as dots on the right, drawing a line from each set to the numbers inside it.
Left side: {A,B,C,D,E}Right side: {1,2,3,4,5}\displaystyle \begin{aligned} \text{Left side: } & \{A, B, C, D, E\} \\ \text{Right side: } & \{1, 2, 3, 4, 5\} \end{aligned}
Collect the neighbors of the sets that share a small group of numbersTake the subset of the first four sets S={A,B,C,D}\group{S} = \group{\{A, B, C, D\}} and list all the numbers that appear in any of them to find N(S)\jobsOf{N(S)}.
S={A,B,C,D}  ⟹  ∣S∣=4,N(S)={1,2,3}  ⟹  ∣N(S)∣=3\displaystyle \begin{aligned} \group{S} &= \group{\{A, B, C, D\}} \\ &\implies |\group{S}| = 4, \\[4pt] \jobsOf{N(S)} &= \jobsOf{\{1, 2, 3\}} \\ &\implies |\jobsOf{N(S)}| = 3 \end{aligned}
Compare the sizes using Hall's TheoremCheck whether the number of available representatives in N(S)\jobsOf{N(S)} is at least the number of sets in S\group{S}.
∣N(S)∣\displaystyle |\jobsOf{N(S)}| =3<4\displaystyle = 3 \fails{<} 4 =∣S∣\displaystyle = |\group{S}|

Because those 4\group{4} sets only contain 3\jobsOf{3} numbers between them, Hall's Theorem tells us a system of distinct representatives is impossible (whereas changing DD to {1,2,3,4}\{1, 2, 3, 4\} removes the bottleneck and lets us pick A–1\matched{A\text{–}1}, B–2\matched{B\text{–}2}, C–3\matched{C\text{–}3}, D–4\matched{D\text{–}4}, and E–5\matched{E\text{–}5}).

5

Counting Lines with Hall's Theorem

Sometimes we aren't given the graph at all, only rules about how many lines leave each person and how many lines go to each job. Even without seeing where the lines go, we can test Hall's Theorem for any group of k\group{k} people by counting the lines leaving that group.

If every person in a bipartite graph applies to exactly 33 jobs, and every job gets exactly 33 applicants, is a complete matching guaranteed?

Counting Lines with Hall's Theorem
⋮\htmlClass{lc-mute}{\vdots}
⋮\htmlClass{lc-mute}{\vdots}
?\htmlClass{lc-mute}{?}
1.   every person appliesto exactly 3 jobs\begin{aligned} 1.\;\, & \text{every person applies} \\ & \text{to exactly 3 jobs} \end{aligned}
2.   every job getsexactly 3 applicants\begin{aligned} 2.\;\, & \text{every job gets} \\ & \text{exactly 3 applicants} \end{aligned}
complete matching ?\text{complete matching}\,?
Text solution
Count the lines leaving any group of k\group{k} peoplePick any subset S\group{S} of k\group{k} people on the left, where each person has 33 lines coming out of them.
∣S∣\displaystyle |\group{S}| =k  ⟹  Lines leaving S\displaystyle = \group{k} \implies \text{Lines leaving } \group{S} =3k\displaystyle = 3\group{k}
Bound how many jobs are needed to receive those linesEvery line leaving S\group{S} goes to a job in N(S)\jobsOf{N(S)}, and since each job can receive at most 33 of those lines, divide by 33 to find the minimum number of jobs in N(S)\jobsOf{N(S)}.
∣N(S)∣\displaystyle |\jobsOf{N(S)}| ≥3k3\displaystyle \ge \frac{3\group{k}}{3} =k\displaystyle = \group{k} =∣S∣\displaystyle = |\group{S}|

Because ∣N(S)∣≥∣S∣|\jobsOf{N(S)}| \ge |\group{S}| holds for every possible subset S\group{S}, a bottleneck can never happen, and Hall's Theorem guarantees a complete matching before we even see the graph.

Key concepts

When you are working with a specific bipartite graph (or a collection of sets turned into a graph, with sets on the left and numbers on the right), your approach depends on whether you are building a matching or proving one cannot get any bigger:

To grow a matching that got stuck

trace an augmenting path from an unmatched person to an empty job by alternating unselected lines (left to right) and highlighted lines (right to left), then flip every line on the path (D→2→B→3→C→4D \trail{\to} 2 \trail{\to} B \trail{\to} 3 \trail{\to} C \trail{\to} 4 replaces 2\matched{2} matched lines with 3\matched{3}). If you can already spot a distinct match for everyone directly, just write the matching down; you do not need to check subsets with Hall's Theorem.

To prove a complete matching is impossible

you never need to check every subset: you only need to show one bottleneck where ∣N(S)∣<∣S∣|\jobsOf{N(S)}| \fails{<} |\group{S}| (such as S={A,D,E}\group{S} = \group{\{A, D, E\}} connecting only to N(S)={1,2}\jobsOf{N(S)} = \jobsOf{\{1, 2\}}, where ∣N(S)∣=2<3=∣S∣|\jobsOf{N(S)}| = 2 \fails{<} 3 = |\group{S}|).

To prove a matching has the maximum possible size

pair two pieces of evidence: a bottleneck showing that at least ∣S∣−∣N(S)∣|\group{S}| - |\jobsOf{N(S)}| people must go unmatched (with 55 people total, 3−2=1\group{3} - \jobsOf{2} = \leftOut{1} person left out limits any matching to at most 5−1=45 - \leftOut{1} = 4), and an actual matching of that size (A–1,D–2,B–3,C–4\matched{A\text{–}1}, \matched{D\text{–}2}, \matched{B\text{–}3}, \matched{C\text{–}4}) showing that a size of 44 is reachable.

To guarantee a complete matching when you only have line counts

use Hall's Theorem (for every subset S\text{for every subset } \group{S}, ∣N(S)∣≥∣S∣|\jobsOf{N(S)}| \ge |\group{S}|) on a general group of k\group{k} people: multiply k\group{k} by the minimum number of lines leaving each person, and divide by the maximum number of lines each job can receive (3k3\group{k} lines with at most 33 per job forces ∣N(S)∣≥3k3=k|\jobsOf{N(S)}| \ge \tfrac{3\group{k}}{3} = \group{k}). Once a complete matching is guaranteed, check whether both sides have the same total number of dots before calling it a perfect matching (55 people matched into 88 jobs is complete, not perfect).

6

Practice

1

Four people (A,B,C,DA, B, C, D) apply to four jobs (1,2,3,41, 2, 3, 4) with the following qualifications: AA can do 1,21, 2; BB can do 2,32, 3; CC can do 1,3,41, 3, 4; and DD can do 11. Starting from the matching A–1\matched{A\text{–}1}, B–2\matched{B\text{–}2}, C–3\matched{C\text{–}3} (with DD unmatched and Job 44 empty), find an augmenting path from DD to Job 44 and give the new matching after flipping the path.

DD's only line goes to Job 11. Who currently holds Job 11 in the matching, and which other job can that person move to?

Starting from DD, we follow the unselected line to Job 11. (Watch out: CC is also qualified for Job 11, so it is tempting to jump from 11 straight to CC and then to 44, giving the path D→1→C→4\slip{D \to 1 \to C \to 4}. That mistake follows an unselected line from right to left instead of a currently highlighted line, so flipping it would give Job 11 to DD and to CC while AA still holds it.) Following the highlighted line from 11 back to AA and continuing to alternate unselected and highlighted lines gives the augmenting path
D→1→A→2→B→3→C→4\displaystyle D \trail{\to} 1 \trail{\to} A \trail{\to} 2 \trail{\to} B \trail{\to} 3 \trail{\to} C \trail{\to} 4
Flipping the path un-highlights A–1A\text{–}1, B–2B\text{–}2, and C–3C\text{–}3 and highlights the unselected lines, giving the perfect matching D–1\matched{D\text{–}1}, A–2\matched{A\text{–}2}, B–3\matched{B\text{–}3}, and C–4\matched{C\text{–}4}.
2

Consider the five sets A={1,4}A = \{1, 4\}, B={2,5}B = \{2, 5\}, C={1,6}C = \{1, 6\}, D={1,4,6}D = \{1, 4, 6\}, and E={4,6}E = \{4, 6\}. Can you choose a system of distinct representatives (one number from each set with no repeats)? If so, list one; if not, use Hall's Theorem to prove it is impossible.

Look at which numbers each set uses: is there a group of sets that never uses 22 or 55?

Check the sets that only use numbers from {1,4,6}\jobsOf{\{1, 4, 6\}}. (Watch out: if you only check all five sets together as S={A,B,C,D,E}\group{S} = \group{\{A, B, C, D, E\}}, you get ∣S∣=5|\group{S}| = 5 and N(S)\jobsOf{N(S)} == {1,2,4,5,6}\jobsOf{\{1, 2, 4, 5, 6\}} with ∣N(S)∣=5|\jobsOf{N(S)}| = 5, which hides the bottleneck because set BB brings in the two extra numbers 22 and 55.) Leaving BB out and taking S={A,C,D,E}\group{S} = \group{\{A, C, D, E\}} gives ∣S∣=4|\group{S}| = 4, while the numbers appearing in those sets are N(S)={1,4,6}\jobsOf{N(S)} = \jobsOf{\{1, 4, 6\}}, so ∣N(S)∣=3|\jobsOf{N(S)}| = 3. Since ∣N(S)∣=3<4=∣S∣|\jobsOf{N(S)}| = 3 \fails{<} 4 = |\group{S}|, by Hall's Theorem a system of distinct representatives is impossible.
3

Six people (A,B,C,D,E,FA, B, C, D, E, F) apply to six jobs (1,2,3,4,5,61, 2, 3, 4, 5, 6). Their qualifications are: AA can do 1,21, 2; BB can do 1,21, 2; CC can do 22; DD can do 1,3,41, 3, 4; EE can do 1,21, 2; and FF can do 3,5,63, 5, 6. What is the size of the largest possible matching on this graph? Prove your answer using both a matching and a bottleneck.

Four of the people only connect to Jobs 11 and 22. How many of those four must go unmatched, and how many of the 66 total people can still get a job?

The subset S={A,B,C,E}\group{S} = \group{\{A, B, C, E\}} has ∣S∣=4|\group{S}| = 4 people who only connect to N(S)={1,2}\jobsOf{N(S)} = \jobsOf{\{1, 2\}}, so ∣N(S)∣=2|\jobsOf{N(S)}| = 2. At least ∣S∣−∣N(S)∣|\group{S}| - |\jobsOf{N(S)}| == 4−2\group{4} - \jobsOf{2} == 2\leftOut{2} of these people must go unmatched. (Watch out: 2\leftOut{2} is the number of people left out, not the size of the maximum matching. Stopping at 2\leftOut{2} forgets to subtract those 2\leftOut{2} unmatched people from the 66 total people on the left.) Subtracting from the 66 people total shows no matching can have size greater than 6−2=46 - \leftOut{2} = 4, and a matching of size 44 is achieved by A–1\matched{A\text{–}1}, C–2\matched{C\text{–}2}, D–4\matched{D\text{–}4}, and F–5\matched{F\text{–}5}, so the maximum matching has size 44.
4

In a bipartite graph with 66 people on the left and 88 jobs on the right, every person applies to at least 44 jobs, and every job receives at most 33 applicants. Use Hall's Theorem to determine whether a complete matching is guaranteed, and explain whether a perfect matching is possible.

For any group of kk people, find the minimum number of lines leaving the group, and then compare the total number of dots on the two sides of the graph.

For any subset S\group{S} of k\group{k} people, at least 4k4\group{k} lines leave S\group{S}. Since each job in N(S)\jobsOf{N(S)} can receive at most 33 of those lines, there must be at least 4k3\tfrac{4\group{k}}{3} jobs in N(S)\jobsOf{N(S)}. (Watch out: dividing the wrong way gives 3k4<k\slip{\tfrac{3k}{4}} < \group{k}, which swaps lines leaving per person with lines arriving per job.) Because ∣N(S)∣≥43k≥k=∣S∣|\jobsOf{N(S)}| \ge \frac{4}{3}\group{k} \ge \group{k} = |\group{S}| for every subset S\group{S}, Hall's Theorem guarantees a complete matching. However, a perfect matching is impossible because the two sides have different sizes (66 people and 88 jobs), leaving 2\leftOut{2} jobs unmatched in every complete matching.
5

Suppose there are 55 people and 55 jobs, every person applies to at least 22 jobs, and every job receives at most 33 applicants. Does this guarantee a complete matching? Either prove that it does or give an example of a graph following these rules that has a bottleneck.

A group of kk people has at least 2k2k lines leaving it, and each job can take up to 33 lines. What is the smallest kk where 2k2k lines can fit into fewer than kk jobs?

For a group of k\group{k} people, at least 2k2\group{k} lines leave the group, which only forces at least 2k3\tfrac{2\group{k}}{3} jobs in N(S)\jobsOf{N(S)}, and when k=3\group{k} = 3, 23(3)=2<3\frac{2}{3}(3) = 2 \fails{<} 3. To build a counterexample, have A,B,C\group{A, B, C} each apply to Jobs 1\jobsOf{1} and 2\jobsOf{2}. (Watch out: you still have to give DD and EE at least 22 jobs each without connecting them to Jobs 1\jobsOf{1} or 2\jobsOf{2}, because Jobs 1\jobsOf{1} and 2\jobsOf{2} already have 33 applicants each.) Having DD and EE each apply to Jobs 3,4,3, 4, and 55 obeys both rules while giving S={A,B,C}\group{S} = \group{\{A, B, C\}} with ∣S∣=3|\group{S}| = 3 and N(S)={1,2}\jobsOf{N(S)} = \jobsOf{\{1, 2\}} with ∣N(S)∣=2<3|\jobsOf{N(S)}| = 2 \fails{<} 3, so a complete matching is not guaranteed.