230 likes | 692 Views
Matching in bipartite graphs. initial matching. extending alternating path. Given: non-weighted bipartite graph. not covered node. Algorithm: so-called “extending alternating path”, we start with a not covered node; next step: node from the matching (maybe several edges)
E N D
Matching in bipartite graphs initial matching extending alternating path • Given: non-weighted bipartite graph not covered node Algorithm: so-called “extending alternating path”, we start with a not covered node; next step: node from the matching (maybe several edges) in this case: no extending alternating path; result: perfect matching
Vertex Cover Problem • In general graphs is NP-hard (best approximation known - 2-approximation) • In bipartite graphs exact algorithm (we can for sure find optimal matching with maximum # of edges) 1 2 minimum cardinality matching M 3 OPT = minimum vertex cover |OPT| |M| Proof: we need at least 1 vertex in OPT per edge in M
Vertex Cover Problem • In bipartite graphs |Maximum matching| = |Minimum vertex cover| • Algorithm (also the proof): Pick a node that covers red and blue edge (red=from M, blue=not from M) (except - last case) - such blue edge that has one endpoint not covered by the matching. If such blue edge does not exist, we have perfect matching (from that point on, all nodes are covered by the matching). Every time we have isolated node, we “drop” it
Vertex Cover Problem • In case of perfect matching take one part of the bipartite graph • In general graphs - not true Example: minimum cover maximum matching
Homework solutions w2 Problem 1: Translate node weighted graph G= (G,V,w), where w: V R+,intoedge weighted graph G’=(V,E,w’), w: E R+, then apply Dijkstra on G’. w1+w2 w(e)= w1+w3 2 2 e w1 w3 v1 w6 w4 w5 For any edge e=vivk E we define w’(e)=1/2 [w(vi)+w(vk)]. Then length(v0v1...vn-path in G)=length (v0v1...vn-path in G’)+ 1/2 w(v0) + 1/2 w(vn) (v0=source, vn= sink). The minimum weight path in G corresponds to a minimum weight path in G’.
Homework solutions v1 v2 v3 V w(v2) =1 v2 2 Problem 2: For G=(V,E,w) we define a bipartite graph G’= (V+V’,E’,w’) : 2 1 3 3 2 2 3 3 V’ 3 v3 v1 v1’ v2’ v3’ • For each v V define a “copy” v’ and an edge (v,v’), where • w(v,v’)=w(v) (corresponds to a loop in v in graph G) • Every edge (u,v) E replace by 2 edges: (u,v’) and (u’,v) • with the same weight as (u,v) • G’ is bipartite (every edge has 1 end in V, other in V’) • Every path from v1 to vn = even • Every path from v1 to vn’ (“copy” of vn) = odd
Homework solutions Problem 3: • G=(V,E,w). For each v V define k “copies” : v1,v2,..., vk • Then create a directed graph G’=(V’,E’,w’), where V’=V V1 ... Vk , vi1V1, ....vjkVk v u 1 1 For each edge (u,v) E define edges (u,v1), (u1,v2), (u2,v3), ... (u(k-1),vk) with the same edge weight as (u,v). We look at all paths from v1(source) to vn(sink) or any copy ofvn. All such paths have at most k edges. 2 2 k k k k edges shortest paths