Discussion 11: Using DFS for Bipartite Matching
Solutions
Draw the graph of this scenario:
- Pilots:
Alpha,Bravo,Charlie,Delta,Echo - Planes:
P1,P2,P3,P4,P5 Alphacan flyP1&P2Bravocan flyP1&P3Charliecan flyP2&P4Deltacan flyP3&P4Echocan flyP4&P5
Find a matching contains the edge (Charlie, P4).
(Charlie, P4) \(\}\) is such a matching. Adding other edges with distinct endpoints results in other such matchings.
Find a matching with size 3 (i.e., that contains 3 edges) that contains the edge (Echo, P4).
(Echo, P4), (Alpha, P1), (Bravo,P3) \(\}\) is one such matching.
Find a matching that has the largest possible size (i.e., a maximum matching). What is the maximum number of flights able to run (size of the maximum matching)? Which pilots would fly which planes? (If you have extra time, try to find a second maximum matching)
\(\{\) (Alpha, P1), (Bravo, P3), (Charlie, P2), (Delta, P4), (Echo, P5) \(\}\)
\(\{\) (Alpha, P2), (Bravo, P1), (Charlie, P4), (Delta, P3), (Echo, P5) \(\}\)
Which pilot(s) are currently unmatched?
Charlie is currently unmatched.
Which plane(s) are currently unmatched?
P1 is currently unmatched.
Find an augmenting path for this matching.
Charlie \(\to\) P2 \(\to\) Alpha \(\to\) P1
or
Charlie \(\to\) P4 \(\to\) Delta \(\to\) P3 \(\to\) Bravo \(\to\) P1
Now, update the matching by taking the augmenting path (reversing the edges from matched to unmatched and vice versa). What is your new matching? How does this affect the number of pairings?
\(\{\)
(Alpha, P1), (Bravo, P3), (Charlie, P2), (Delta, P4), (Echo, P5) \(\}\)or \(\{\)
(Alpha, P2), (Bravo, P1), (Charlie, P4), (Delta, P3), (Echo, P5) \(\}\)depending on which augmenting path was chosen in part (c). In either case, the size of the matching increased by 1 from 4 to 5.
augment() method, which takes in the augmenting path and the matching and returns the bigger matching gained from taking the augmenting path.
|
|
|
|
dfsRecursive()
Implement dfsRecursive(), a helper method for findAugmentingPath() that leverages DFS (for more info on DFS, refer to Lecture 22) to locate an augmenting path starting at a particular vertex. We encourage you to make use of the provided scaffolding for this method.
|
|
|
|
maxMatching()
Implement maxMatching(). This method contains the main loop that iteratively locates augmenting paths and calls the augment helper method described above.
|
|
|
|