Skip to content

Commit c689d3a

Browse files
Added a long-form example of 7.24
1 parent 72ad37e commit c689d3a

2 files changed

Lines changed: 192 additions & 1 deletion

File tree

OMSCS/Courses/GA/06.2 - NP - Definitions.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ tags:
66
# 06.2 - NP - Definitions
77
> How do we prove that a problem is computationally difficult?
88
9-
109
## Outline
1110
- NP
1211
- NP-Complete
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 7.24 - Example Bipartite Matching
8+
This document shows how to find a maximal matching in a bipartite graph, following the definitions of "Alternating Paths", "Matching Set", "Covered Vertex", and "Maximal Matching" from Practice Problem [[7.24 - Example Bipartite Matching]].
9+
10+
Following an iterative procedure of modifying edges along an alternating path in G, we can start with any G that has a sub-maximal matching set $M$ and arrive at a maximal matching set for G.
11+
12+
We will start with this bipartite graph G, which has an empty matching set ($M=\emptyset$), and therefore no covered vertices.
13+
14+
```mermaid
15+
graph TD
16+
17+
A((A))
18+
B((B))
19+
C((C))
20+
D((D))
21+
E((E))
22+
F((F))
23+
G((G))
24+
H((H))
25+
I((I))
26+
27+
A <--> E
28+
A <--> H
29+
B <--> E
30+
B <--> F
31+
B <--> G
32+
C <--> G
33+
C <--> H
34+
C <--> I
35+
D <--> F
36+
```
37+
38+
In this graph, every pair of connected vertices is an Alternating Path (AP) in G. We can arbitrarily select $AP=[A,E]$ as our first AP in G. If we then take all of the edges $e \in AP$, we can add them to $M$ if $e \notin M$ or remove $e$ from $M$ if $e \in M$.
39+
40+
This results in the following graph. Edges in $M$ are bold. Covered vertices are shown as double circles.
41+
42+
```mermaid
43+
graph TD
44+
45+
A(((A)))
46+
B((B))
47+
C((C))
48+
D((D))
49+
E(((E)))
50+
F((F))
51+
G((G))
52+
H((H))
53+
I((I))
54+
55+
A <==> E
56+
A <--> H
57+
B <--> E
58+
B <--> F
59+
B <--> G
60+
C <--> G
61+
C <--> H
62+
C <--> I
63+
D <--> F
64+
```
65+
66+
We can then apply this procedure again, selecting 2 arbitrary uncovered vertices in G and finding an AP between them. For this iteration, we will pick another easy example: $AP=[H,C]$. Since $HC$ is not already in $M$, we can add it, resulting in the graph shown below.
67+
68+
```mermaid
69+
graph TD
70+
71+
A(((A)))
72+
B((B))
73+
C(((C)))
74+
D((D))
75+
E(((E)))
76+
F((F))
77+
G((G))
78+
H(((H)))
79+
I((I))
80+
81+
A <==> E
82+
A <--> H
83+
B <--> E
84+
B <--> F
85+
B <--> G
86+
C <--> G
87+
C <==> H
88+
C <--> I
89+
D <--> F
90+
```
91+
92+
There still exists APs in G, so we can apply this procedure again. Here are all of the APs that currently exist in G.
93+
94+
- $[G,B]$
95+
- $[B,F]$
96+
- $[D,F]$
97+
- $[I,C,H,A,E,B]$
98+
- $[G, C, H, A, E, B]$
99+
100+
This time we will pick a long AP: $AP=[I,C,H,A,E,B]$. For each of these edges, we alternate its membership within $M$
101+
102+
- Add $IC$ to $M$
103+
- Remove $CH$ from $M$
104+
- Add $HA$ to $M$
105+
- Remove $AE$ from $M$
106+
- Add $EB$ to $M$
107+
108+
This leaves us with the graph below.
109+
110+
```mermaid
111+
graph TD
112+
113+
A(((A)))
114+
B(((B)))
115+
C(((C)))
116+
D((D))
117+
E(((E)))
118+
F((F))
119+
G((G))
120+
H(((H)))
121+
I(((I)))
122+
123+
A <--> E
124+
A <==> H
125+
B <==> E
126+
B <--> F
127+
B <--> G
128+
C <--> G
129+
C <--> H
130+
C <==> I
131+
D <--> F
132+
```
133+
134+
Each time we apply this procedure, we first find an AP in G. An AP always has odd length, starts with an edge which is not in $M$, and ends with an edge that is not in $M$. For each subsequent edge in the AP, that edge alternates between being in $M$ and not in $M$. For a given AP of length $2k+1$, the AP has $k$ edges which are in $M$, and $k+1$ edges which are not in $M$. Therefore, we end up removing $k$ edges from $M$, and adding $k+1$ edges to $M$. This results in $|M|$ increasing by 1 each iteration. This also always results both of the endpoints of the AP becoming covered in G after applying this procedure.
135+
136+
Every step of the process increases the amount of G which is covered by $M$, without violating $M$ being defined as a "matching set."
137+
138+
After running the previous iteration, $[F,D]$ is the only AP which exists in G. Applying the procedure to this AP, we end up with this graph.
139+
140+
```mermaid
141+
graph TD
142+
143+
A(((A)))
144+
B(((B)))
145+
C(((C)))
146+
D(((D)))
147+
E(((E)))
148+
F(((F)))
149+
G((G))
150+
H(((H)))
151+
I(((I)))
152+
153+
A <--> E
154+
A <==> H
155+
B <==> E
156+
B <--> F
157+
B <--> G
158+
C <--> G
159+
C <--> H
160+
C <==> I
161+
D <==> F
162+
```
163+
164+
This leaves us with $M=[AG, EB, FD, CI]$. All **covered** vertices only appear once in $M$, meaning that $M$ is still a valid matching for $G$. We also have just vertex $G$ as the only **uncovered** vertex in G. There cannot exist any other APs in G, because an AP must have odd length. Since G is bipartite, we can't have an AP which starts and ends with a single vertex.
165+
166+
Therefore, $M=[AG, EB, FD, CI]$ is a "maximal matching" for G.
167+
168+
Other valid maximal matchings exist for $G$, including $M=[AE, BG, DF, CI]$, leaving $H$ as the only uncovered vertex in G.
169+
170+
```mermaid
171+
graph TD
172+
173+
A(((A)))
174+
B(((B)))
175+
C(((C)))
176+
D(((D)))
177+
E(((E)))
178+
F(((F)))
179+
G(((G)))
180+
H((H))
181+
I(((I)))
182+
183+
A <==> E
184+
A <--> H
185+
B <--> E
186+
B <--> F
187+
B <==> G
188+
C <--> G
189+
C <--> H
190+
C <==> I
191+
D <==> F
192+
```

0 commit comments

Comments
 (0)