0% found this document useful (0 votes)
17 views25 pages

Maximum Matching Bipartite Graph

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views25 pages

Maximum Matching Bipartite Graph

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Maximum Matching Bipartite Graph

Bipartite graph

• A bipartite graph separates the V vertices {1, 2, 3, a, b, c} into two distinct set of vertices,
V1 with subset {1, 2, 3}, and V2 with subset {a, b, c}.

• These disjoint sets V1, V2 need not to be same size.


• Each edge connects one vertex in subset V1 to one vertex in subset V2.
• Every vertex of V1 connects to every vertex of V2 in a full bipartite Graph.

1 a

2 b

3 c
Bipartite Matching

Matching is defined as connection the pair of vertices from two distinct set of vertices.
Property
• Bipartite Matching is Matching in a bipartite graph where each edge has unique endpoints
(vertex), i.e., no two edges share the same vertex.
E.g.,
• Let consider M employees and N jobs. Each employee is capable of performing some job.
Each employee is assigned job during the matching process.

1 a

2 b

3 c
• A matching in a graph is a subset of its edges with the property
that no two edges share a vertex.
• A maximum matching— a maximum cardinality matching—is a
matching with the largest number of edges.
• The maximum-matching problem is the problem of finding a
maximum matching in a given graph.
• In a bipartite graph, all the vertices can be partitioned into two
disjoint sets V and U , not necessarily of the same size, so that
every edge connects a vertex in one of these sets to a vertex in the
other set.
• A graph is bipartite if its vertices can be colored in two colors so
that every edge has its vertices colored in different colors; such
graphs are also said to be 2-colorable.
Maximum Bipartite Matching

• Maximum cardinality matching is a matching with the largest number of edges.


• Let’s consider M employees and N tasks.
• Assign the positions to the employees to get the most matching i.e., set the most employees to work. Once
find a maximum match, do not add any further edges, and any edges added are no longer matching.
• In bipartite graph, there may be more than one maximum matching.

• Dark line indicates


maximum matching
Maximum Bipartite Matching with Colors

• Vertices can be colored in two colors.


• So every edge has its vertices colored in different colors i.e.,
• No two edges connect the same color. This graph is called 2-colorable graph.
• Let’s consider M employees and N tasks.
• It is easy to prove that a graph is bipartite if and only if it does not have a cycle of an odd length.

• Red line indicates


maximum matching.

• All employee nodes


are connected to tasks
that utilize the
maximum matching of
the Graph.
Graph Coloring
• No adjacent states will be of same color.
• Finding of maximum colors.

A B

C D
Unweighted Bipartite Matching
Definitions

Matching

Free Vertex
Definitions

Maximum Matching: matching with the largest number of edges


Definition

Note that maximum matching is not unique.


Maximum Matching Problem
• Let M be the matching in bipartite graph G
• M= { (D,3), (E,4)} (Matching edge given in problem itself).
• Find the maximum matching.

A B C D E

1 2 3 4 5
Maximum Matching Problem
Solution: Find the free vertices
• X= {A, B, C, D, E}
• Y = { 1,2, 3, 4, 5}; The free vertices in X are A, B, C
The free vertices in Y are 1,2,5
• Given M= { (D,3), (E,4)}
• Let consider the node A. 𝑀𝑎 = {(A,1), (D,3), (E,4)}

A B C D E

1 2 3 4 5
Maximum Matching Problem
• 𝑀𝑎 = {(A,1), (D,3), (E,4)}.
• Let consider the node B. 𝑀𝑏 = (A,1), (D,3), (E,4), (B, 1). But, it is adjacent
edge to the (A,1) i.e., vertex 1 is shared by A and B. It is not satisfy the
property.
• So, update the matching as (A, 2), & (B, 1).

A B C D E

1 2 3 4 5
Maximum Matching Problem
• 𝑀𝑎={(A,1), (D,3), (E,4)}.
• Let consider the node B. 𝑀𝑏 = {(A,1), (D,3), (E,4), (B, 1)}. But, it is adjacent edge to the
(A,1)
• i.e., vertex 1 is shared by A and B. It is not satisfy the property.
• So, update the matching as (A, 2), & (B, 1).
• 𝑀𝑏 = {(D,3), (E,4), (A, 2), (B, 1)}.

A B C D E

1 2 3 4 5
Maximum Matching Problem
• 𝑀𝑏={(D,3), (E,4), (A, 2), (B, 1)}.
• Let consider the node C. (C,1) is not feasible. Check (C, 3). But, it is adjacent edge to the (D,
3) i.e., vertex 3 is shared by D. So, remove this match. Add the new match (C, 3).
• 𝑀𝑐 = {(E,4), (A, 2), (B, 1), (C, 3)}.

A B C D E

1 2 3 4 5
Maximum Matching Problem
• 𝑀𝑐={(E,4), (A, 2), (B, 1), (C, 3)}.
• Let consider the node D. (D, 4) is not feasible. But, it is adjacent edge to the (E, 4) i.e.,
vertex 4 is shared by E. Check (D, 5). Add the new match (D, 5).
• 𝑀𝑑 = {(E,4), (A, 2), (B, 1), (C, 3), (D, 5)}.

A B C D E

1 2 3 4 5
Maximum Matching Problem
• 𝑀𝑑 = {(E,4), (A, 2), (B, 1), (C, 3), (D, 5)}.
• Let consider the node E. (E, 4) is feasible.
• 𝑀𝑑 = {(E,4), (A, 2), (B, 1), (C, 3), (D, 5)}.

A B C D E

1 2 3 4 5

• Matching Md is not only a maximum matching but also perfect, i.e., a matching that matches
all the vertices of the graph.
Overall algorithm

Start with an arbitrary matching (e.g., empty matching)


Repeat forever
For all free vertices in the bottom,
do bfs to find augmenting paths
If found, then flip the edges
If fail to find, stop and report the maximum matching.
Practice Problems

Find the Maximum Matching in the following Bipartite Graphs.

1.
A B C D E

1 2 3 4 5
Answer

A B C D E

1 2 3 4 5
Time analysis

We can find at most |V| augmenting paths


To find an augmenting path, we use bfs! Time required = O( |V| + |E| )
Total time: O(|V|2 + |V| |E|)
Improvement
We can try to find augmenting paths in parallel for all free
nodes in every iteration.
Using such approach, the time complexity is improved to
O(|V|0.5 |E|)
References
1. Anany Levitin, “Introduction to the Design and Analysis of Algorithms”, Pearson
Education, Third Edition, 2017.
2. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein,
“Introduction to Algorithms”, MIT Press/PHI Learning Private Limited, Third Edition,
2012.
3. E. Horowiz, S. Sahni, S. Rajasekaran, “Fundamentals of Computer Algorithms”,
Universities Press, 2nd Ed, 2008.

You might also like