





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






A graph G=(V,E)G = (V, E)G=(V,E) is bipartite if its vertices can be partitioned into two independent sets UUU and VVV, such that every edge has one endpoint in UUU and one endpoint in VVV.cs161-stanford.github
A matching is a set of edges with no shared endpoints. A perfect matching matches every vertex exactly once. In a bipartite graph with parts V1V_1V1 and V2V_2V2, a perfect matching requires ∣V1∣=∣V2∣|V_1| = |V_2|∣V1∣=∣V2∣. stanford-cs161.github+
An alternating path alternates between unmatched and matched edges. An augmenting path is an alternating path that begins and ends at unmatched vertices; flipping its edges increases the matching size by 1.columbia
10 points
Design an algorithm that determines whether an undirected graph G=(V,E)G = (V, E)G=(V,E) is bipartite. State its running time and prove correctness.
Use BFS or DFS with two colors.
text IS-BIPARTITE(G): color every vertex as uncolored
for each vertex s in V: if s is uncolored: color[s] = RED queue = [s]
while queue is not empty: u = dequeue(queue)
for each neighbor v of u: if v is uncolored: color[v] = opposite(color[u]) enqueue(queue, v) else if color[v] = color[u]: return False
return True
If GGG is bipartite, let UUU and VVV be its two parts. Color every vertex in UUU red and every vertex in VVV blue. Every edge connects different colors, so the algorithm never finds a same-color edge.
If the algorithm returns False, it found an edge (u,v)(u, v)(u,v) whose endpoints have the same color. In a BFS or DFS tree, adjacent vertices differ by one level in parity. A same-color edge therefore creates an odd cycle, and a graph with an odd cycle cannot be bipartite.
With adjacency lists, BFS visits each vertex once and examines each edge a constant number of times:
Θ(n+m)\Theta(n + m)Θ(n+m)
Stanford’s CS 161 section materials describe exactly this coloring approach using DFS, with the same odd-cycle logic.cs161-stanford.github
15 points
20 points
Let MMM be a matching in a bipartite graph GGG.
Define an alternating path.
Define an augmenting path.
Explain why augmenting along an augmenting path increases the size of the matching by exactly
State the central theorem connecting augmenting paths and maximum matchings.
An alternating path is a path whose edges alternate between edges not in the current matching MMM and edges in MMM.columbia
An augmenting path is an alternating path that begins and ends at unmatched vertices.columbia
Suppose an augmenting path has kkk unmatched edges and k−1k - 1k−1 matched edges. Flip the membership of every edge on the path:
Remove the k−1k - 1k−1 matched edges from MMM. Add the kkk unmatched edges to MMM.
The new matching has size:
∣M∣−(k−1)+k=∣M∣+1|M| - (k - 1) + k = |M| + 1∣M∣−(k−1)+k=∣M∣+
Thus, augmentation increases the matching size by exactly 1.columbia
A matching MMM is maximum if and only if there is no augmenting path with respect to MMM.
Therefore, a standard maximum-matching algorithm starts with the empty matching and repeatedly finds an augmenting path until none remains.columbia
20 points
Let G=(V1∪V2,E)G = (V_1 \cup V_2, E)G=(V1∪V2,E) be an unweighted bipartite graph with ∣V1∣=∣V2∣=n|V_1| = |V_2| = n∣V1∣=∣V2∣=n and mmm edges.
Describe how to determine whether GGG has a perfect matching using a max-flow reduction. State the flow-network construction, the correctness argument, and the running time.
Construct a directed flow network HHH:
Then compute a maximum sss-ttt flow using Ford-Fulkerson.stanford-cs161.github+
If GGG has a perfect matching MMM, send 1 unit of flow along each matched path:
text Gale-Shapley(doctors, hospitals): initialize every doctor and hospital as free
while some doctor i is free and has not applied to every hospital: j = highest-ranked hospital to which i has not yet applied i applies to j
if j is free: match i and j else if j prefers i to its current doctor k: match i and j make k free else: j rejects i
This is the Deferred Acceptance Algorithm, also called Gale-Shapley.stanford-cs161.github+
Each doctor applies to each hospital at most once. With nnn doctors and nnn hospitals, there are at most:
n2n^2n
applications total. Therefore, the algorithm terminates after at most O(n2)O(n^2)O(n2) iterations.stanford-cs161.github
Suppose doctor iii and hospital jjj form an unstable pair. Then iii prefers jjj to their assigned hospital, and jjj prefers iii to its assigned doctor.
But if iii preferred jjj, then iii must have applied to jjj earlier. If jjj preferred iii, then jjj would not have rejected iii in favor of a less-preferred doctor. This contradicts the algorithm’s behavior.
Therefore, no blocking pair exists, and the returned matching is stable.stanford-cs161.github+
20 points
Let G=(V1∪V2,E)G = (V_1 \cup V_2, E)G=(V1∪V2,E) be a bipartite graph with nnn vertices on each side and mmm edges.
For each statement, determine whether it is True or False.
Bipartiteness can be tested in O(n+m)O(n + m)O(n+m) time.
A maximum bipartite matching can be found by reducing to max flow.
Using Ford-Fulkerson, the bipartite perfect-matching decision problem can be solved in O(mn)O(mn)O(mn) time.
Gale-Shapley always terminates in O(n)O(n)O(n) time for nnn doctors and nnn hospitals.
True. BFS or DFS coloring examines each vertex and edge a constant number of times, giving O(n+m)O(n + m)O(n+m).cs161-stanford.github
True. Add a source, sink, and unit-capacity edges. A maximum flow corresponds to a maximum matching.stanford-cs161.github+
True. The maximum flow value is at most nnn, so Ford-Fulkerson performs at most nnn