Section 4.6 Matching in Bipartite Graphs
¶Investigate!
Given a bipartite graph, a matching is a subset of the edges for which every vertex belongs to exactly one of the edges. Our goal in this activity is to discover some criterion for when a bipartite graph has a matching.
Does the graph below contain a matching? If so, find one.
Not all bipartite graphs have matchings. Draw as many fundamentally different examples of bipartite graphs which do NOT have matchings. Your goal is to find all the possible obstructions to a graph having a perfect matching. Write down the necessary conditions for a graph to have a matching (that is, fill in the blank: If a graph has a matching, then ). Then ask yourself whether these conditions are sufficient (is it true that if , then the graph has a matching?).
We conclude with one more example of a graph theory problem to illustrate the variety and vastness of the subject.
Suppose you have a bipartite graph \(G\text{.}\) This will consist of two sets of vertices \(A\) and \(B\) with some edges connecting some vertices of \(A\) to some vertices in \(B\) (but of course, no edges between two vertices both in \(A\) or both in \(B\)). A matching of \(A\) is a subset of the edges for which each vertex of \(A\) belongs to exactly one edge of the subset, and no vertex in \(B\) belongs to more than one edge in the subset. In practice we will assume that \(|A| = |B|\) (the two sets have the same number of vertices) so this says that every vertex in the graph belongs to exactly one edge in the matching. 10 Note: what we are calling a matching is sometimes called a perfect matching or complete matching. This is because in it interesting to look at non-perfect matchings as well. We will call those partial matchings.
Some context might make this easier to understand. Think of the vertices in \(A\) as representing students in a class, and the vertices in \(B\) as representing presentation topics. We put an edge from a vertex \(a \in A\) to a vertex \(b \in B\) if student \(a\) would like to present on topic \(b\text{.}\) Of course, some students would want to present on more than one topic, so their vertex would have degree greater than 1. As the teacher, you want to assign each student their own unique topic. Thus you want to find a matching of \(A\text{:}\) you pick some subset of the edges so that each student gets matched up with exactly one topic, and no topic gets matched to two students. 11 The standard example for matchings used to be the marriage problem in which \(A\) consisted of the men in the town, \(B\) the women, and an edge represented a marriage that was agreeable to both parties. A matching then represented a way for the town elders to marry off everyone in the town, no polygamy allowed. We have chosen a more progressive context for the sake of political correctness.
The question is: when does a bipartite graph contain a matching of \(A\text{?}\) To begin to answer this question, consider what could prevent the graph from containing a matching. This will not necessarily tell us a condition when the graph does have a matching, but at least it is a start.
One way \(G\) could not have a matching is if there is a vertex in \(A\) not adjacent to any vertex in \(B\) (so having degree 0). What else? What if two students both like the same one topic, and no others? Then after assigning that one topic to the first student, there is nothing left for the second student to like, so it is very much as if the second student has degree 0. Or what if three students like only two topics between them. Again, after assigning one student a topic, we reduce this down to the previous case of two students liking only one topic. We can continue this way with more and more students.
It should be clear at this point that if there is every a group of \(n\) students who as a group like \(n-1\) or fewer topics, then no matching is possible. This is true for any value of \(n\text{,}\) and any group of \(n\) students.
To make this more graph-theoretic, say you have a set \(S \subseteq A\) of vertices. Define \(N(S)\) to be the set of all the neighbors of vertices in \(S\text{.}\) That is, \(N(S)\) contains all the vertices (in \(B\)) which are adjacent to at least one of the vertices in \(S\text{.}\) (In the student/topic graph, \(N(S)\) is the set of topics liked by the students of \(S\text{.}\)) Our discussion above can be summarized as follows:
Matching Condition.
If a bipartite graph \(G = \{A, B\}\) has a matching of \(A\text{,}\) then
for all \(S \subseteq A\text{.}\)
Is the converse true? Suppose \(G\) satisfies the matching condition \(|N(S)| \ge |S|\) for all \(S \subseteq A\) (every set of vertices has at least as many neighbors than vertices in the set). Does that mean that there is a matching? Surprisingly, yes. The obvious necessary condition is also sufficient. 12 This happens often in graph theory. If you can avoid the obvious counterexamples, you often get what you want. This is a theorem first proved by Philip Hall in 1935. 13 There is also an infinite version of the theorem which was proved by Marshal Hall, Jr. The name is a coincidence though as the two Halls are not related.
Theorem 4.6.1. Hall's Marriage Theorem.
Let \(G\) be a bipartite graph with sets \(A\) and \(B\text{.}\) Then \(G\) has a matching of \(A\) if and only if
for all \(S \subseteq A\text{.}\)
There are quite a few different proofs of this theorem – a quick internet search will get you started.
In addition to its application to marriage and student presentation topics, matchings have applications all over the place. We conclude with one such example.
Example 4.6.2.
Suppose you deal 52 regular playing cards into 13 piles of 4 cards each. Prove that you can always select one card from each pile to get one of each of the 13 card values Ace, 2, 3, …, 10, Jack, Queen, and King.
Doing this directly would be difficult, but we can use the matching condition to help. Construct a graph \(G\) with 13 vertices in the set \(A\text{,}\) each representing one of the 13 card values, and 13 vertices in the set \(B\text{,}\) each representing one of the 13 piles. Draw an edge between a vertex \(a \in A\) to a vertex \(b \in B\) if a card with value \(a\) is in the pile \(b\text{.}\) Notice that we are just looking for a matching of \(A\text{;}\) each value needs to be found in the piles exactly once.
We will have a matching if the matching condition holds. Given any set of card values (a set \(S \subseteq A\)) we must show that \(|N(S)| \ge |S|\text{.}\) That is, the number of piles that contain those values is at least the number of different values. But what if it wasn't? Say \(|S| = k\text{.}\) If \(|N(S)| \lt k\text{,}\) then we would have fewer than \(4k\) different cards in those piles (since each pile contains 4 cards). But there are \(4k\) cards with the \(k\) different values, so at least one of these cards must be in another pile, a contradiction. Thus the matching condition holds, so there is a matching, as required.
Exercises Exercises
¶1.
Find a matching of the bipartite graphs below or explain why no matching exists.
The first and third graphs have a matching, shown in bold (there are other matchings as well). The middle graph does not have a matching. If you look at the three circled vertices, you see that they only have two neighbors, which violates the matching condition \(\card{N(S)} \ge \card{S}\) (the three circled vertices form the set \(S\)).
2.
A bipartite graph that doesn't have a matching might still have a partial matching. By this we mean a set of edges for which no vertex belongs to more than one edge (but possibly belongs to none). Every bipartite graph (with at least one edge) has a partial matching, so we can look for the largest partial matching in a graph.
Your “friend” claims that she has found the largest partial matching for the graph below (her matching is in bold). She explains that no other edge can be added, because all the edges not used in her partial matching are connected to matched vertices. Is she correct?
3.
One way you might check to see whether a partial matching is maximal is to construct an alternating path. This is a sequence of adjacent edges, which alternate between edges in the matching and edges not in the matching (no edge can be used more than once). If an alternating path starts and stops with an edge not in the matching, then it is called an augmenting path.
-
Find the largest possible alternating path for the partial matching of your friend's graph. Is it an augmenting path? How would this help you find a larger matching?
-
Find the largest possible alternating path for the partial matching below. Are there any augmenting paths? Is the partial matching the largest one that exists in the graph?
4.
The two richest families in Westeros have decided to enter into an alliance by marriage. The first family has 10 sons, the second has 10 girls. The ages of the kids in the two families match up. To avoid impropriety, the families insist that each child must marry someone either their own age, or someone one position younger or older. In fact, the graph representing agreeable marriages looks like this:
The question: how many different acceptable marriage arrangements which marry off all 20 children are possible?
How many marriage arrangements are possible if we insist that there are exactly 6 boys marry girls not their own age?
Could you generalize the previous answer to arrive at the total number of marriage arrangements?
How do you know you are correct? Try counting in a different way. Look at smaller family sizes and get a sequence.
Can you give a recurrence relation that fits the problem?
5.
We say that a set of vertices \(A \subseteq V\) is a vertex cover if every edge of the graph is incident to a vertex in the cover (so a vertex cover covers the edges). Since \(V\) itself is a vertex cover, every graph has a vertex cover. The interesting question is about finding a minimal vertex cover, one that uses the fewest possible number of vertices.
- Suppose you had a matching of a graph. How can you use that to get a minimal vertex cover? Will your method always work?
- Suppose you had a minimal vertex cover for a graph. How can you use that to get a partial matching? Will your method always work?
- What is the relationship between the size of the minimal vertex cover and the size of the maximal partial matching in a graph?
6.
For many applications of matchings, it makes sense to use bipartite graphs. You might wonder, however, whether there is a way to find matchings in graphs in general.
- For which \(n\) does the complete graph \(K_n\) have a matching?
- Prove that if a graph has a matching, then \(\card{V}\) is even.
- Is the converse true? That is, do all graphs with \(\card{V}\) even have a matching?
- What if we also require the matching condition? Prove or disprove: If a graph with an even number of vertices satisfies \(\card{N(S)} \ge \card{S}\) for all \(S \subseteq V\text{,}\) then the graph has a matching.