1 / 32

Lecture 15 Maximum Matching

Lecture 15 Maximum Matching. The Hungarian tree method for bipartite graphs. Definitions. An edge is matched if it is in a matching M , and free otherwise. A vertex is matched if it is incident to a matched edge, and free otherwise.

jalia
Download Presentation

Lecture 15 Maximum Matching

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 15 Maximum Matching • The Hungarian tree method for bipartite graphs

  2. Definitions An edge is matched if it is in a matching M, and free otherwise. A vertex is matched if it is incident to a matched edge, and free otherwise. A vertex in X is called an x-vertex; a vertex in Y is called a y-vertex. Matching Free Vertex matched Vertex

  3. Alternating Path • Alternating path (with respect to M): A simple path that consists of alternating matched and unmatched edges. • Augmenting path (with respect to M): An alternating path with both endpoints free. a c d e b f h i j g d-h-e: alternating path a-f-b-h-d-i: augmenting path f-b-h-e: not alternating path e-j: augmenting path

  4. Algorithm’s idea • “Flip” augmenting path to get better matching • Note: After flipping, the number of matched edges will increase by 1! 

  5. Idea • Theorem (Berge 1975): A matching M in G is maximum iffthere is no augmenting path Proof: • () If there is an augmenting path, clearly not maximum. (Flip matching and non-matching edges in that path to get a “better” matching!)

  6. Proof for the other direction • () Suppose M is not maximum. Let M’ be a maximum matching such that |M’|>|M|. • Consider H = MM’ = (MM’)-(MM’)i.e. a set of edges in M or M’ but not both • H has two properties: • Within H, number of edges belong to M’ > number of edges belong to M. • H can be decomposed into a set of paths. All paths should be alternating between edges in M and M’. • There should exist a path with more edges from M’. Also, it is alternating with respect to M.

  7. c a d e b Edge in M’ Edge in M z y h i x b c a e Edges in MM’ x h y i

  8. Idea of Algorithm • Start with an arbitrary matching • While we still can find an augmenting path • Find the augmenting path P • Flip the edges in P

  9. Labelling Algorithm • Start with arbitrary matching

  10. Labelling Algorithm • Pick a free x-vertex, say r, and label it outer . r(o)

  11. Labelling Algorithm • Run BFS along alternating unmatched and matched edges r(o)

  12. Labelling Algorithm • Label a y-vertex inner if it is adjacent to r through a free edge, and grow this breadth-first tree along alternating unmatched and matched edges. Label the vertices encountered outer and inner alternatively. b(i) a(i) r(o)

  13. Labelling Algorithm b(i) a(i) c(o) d(o) r(o)

  14. Labelling Algorithm e(i) b(i) a(i) c(o) d(o) r(o)

  15. Alternating Tree Until find an augmenting path (i.e., by encountering an inner vertex which is free ), e.g., r-a-c-e. r(o) e(i) b(i) a(i) b(i) a(i) d(o) c(o) c(o) d(o) r(o) e(i)

  16. Flip!

  17. Alternating Tree or the tree is blocked, i.e., cannot be extended any more. In this case, the alternating tree is called a Hungarian tree. r(o) b(i) a(i) b(i) a(i) d(o) c(o) c(o) d(o) r(o)

  18. Hungarian Tree • Notice: if there is an edge (x, y), x T, and yT, then x must • be an inner vertex. Otherwise, the tree should be extended through • (x,y) to y. It follows that • no vertex in a Hungarian tree can occur in an augmenting path P. • Both ends of P are free vertices, so, they cannot be in T • (the root of T cannot be the end of P). Then P • “enters” T through an inner vertex and an unmatched edge. Then • P must follow some alternating path in T until it “leaves” T • also through an inner vertex but through a matched edge. A contradiction. x(i) a(i) c(o) d(o) r(o) y

  19. Hungarian Tree • Observation:If, in the process of searching for an augmenting path, a Hungarian tree is found, then it can be removed permanently without affecting the search. x(i) a(i) c(o) d(o) r(o) y

  20. Hungarian Tree • Observation:If, in the process of searching for an augmenting path, a Hungarian tree is found, then it can be removed permanently without affecting the search. e(i) f(i) y(o)

  21. Hungarian Tree Another augmenting path y-f is found. Flip. e(i) f(i) y(o)

  22. Hungarian Tree In the remaining graph, no x-vertex is free, stop.

  23. Overall algorithm • Input:Abipartite graph (XY, E) • Output: A maximum matching M in G. • 1. Initialize Mto any arbitrary (possibly empty) matching • 2.while there exists a free x-vertex and a free y-vertex • 3. let r be a free x-vertex. Using breadth-first search, grow an alternating tree T rooted at r • 4. if T is a Hungarian tree then let GG-T • 5. else find an augmenting path p in T and let M=MP. • 6. end while. • O(V2+VE)—running BFS once costs O(V+E) time, and there are at most O(V) free x-vertices.

  24. An O(n2.5)-algorithm-Hopcroft and Karp

  25. An O(n2.5)-algorithm • Lemma 17.2 Let M be a matching, p an augmenting path with respect to M, and p’ an augmenting path with respect to M  p. Let M’=M p p’. Then, M M’=p p’. • Proof. We only need to consider edges in p  p’. Let e be an edge in p  p’. If e is in p  p’, then its status (matched or unmatched ) in M is different from its status in M’ since its status will change only once: either by p or p’. Consequently, e is in M M’. On the other hand, if e is in pp’, then its status is the same in both M and M’ since its status will change twice:first by p and then by p’, that is , e is not in M M’. Consequently, M M’=p p’.

  26. An O(n2.5)-algorithm • Lemma 17.3 Let M be a matching, p a shortest augmenting path with respect to M, and p’ an augmenting path with respect to M  p. Then, |p’|  |p|+2|pp’|. Proof. Let M’= M p p’. By lemma 17.1, M’ is a matching and |M’|=|M|+2. By Theorem 17.1, MM’ contains two vertex-disjoint augmenting paths p1 and p2 with respect to M. Since, by Lemma 17.2, M M’=p p’, we have |p p’| |p1|+|p2|. Since p is of shortest length, |p1||p| and |p2||p|. Therefore, |p p’|2|p|. From the identity |p p’|=|p|+|p’|-|pp’|, we obtain |p’||p|+2|pp’|.

  27. An O(n2.5)-algorithm • Let M be matching, k the length of a shortest augmenting path with respect to M and S a maximal set of vertex-disjoint augmenting paths with respect to M of length k. Let M’ be obtained from M by augmenting M by all the augmenting paths in S. Let p be an augmenting path in M’. We have the following corollary of Lemma 17.3. • Corollary 17.2. |p|  k + 2. • Theorem 17.5 The number of phases required to find a maximum matching in a bipartite graph is at most .

  28. Theorem 17.5 The number of phases required to find a maximum matching in a bipartite graph is at most . • proof. Let Mbe the matching obtained after at least phases and M* a maximum matching. Since the length of augmenting paths increases from one phase to the next by at least 2, the length of any augmenting path in M is at least +1. BY theorem 17.1, there are exactly |M*|-|M| vertex-disjoint augmenting paths with respect to M. Since the length of each path is at least +1, and hence each path consists of at least +2 vertices, we must have . Since each phase contributes at least one augmenting path, the remaining number of phases is at most . It follows that the total number of phases required by the algorithm is at most

  29. Algorithm BIMATCH3 • Start with the empty matching M={}. • Maximumfalse • While not maximum (construct a dag D) • L0Set of free vertices in X • L1{yY |(x,y)  E for some x  L0} • E0 = {(x,y)  E | x  L0, y  L1} • Mark all vertices in L0 and L1 • i0 • while Li+1 contains no free vertices and is not empty • ii+2 • Li{x X | x is unmarked and is joined by a matched edge to a vertex y  Li-1} • Ei-1 = {(x,y)  E | y  Li-1, x  Li} • Li+1{yY | y is unmarked and is joined by an unmatched edge to a vertex x  Li } • Ei = {(x,y) E | x  Li, y  Li+1} • mark all vertices in Li and Li+1 • end while • if Li+1 is empty then maximum true • else • for each free vertex y  Li+1 {augment} Starting at y, use depth-first search to find an augmenting path p that ends at a free vertex x  L0. Remove all vertices on p and incident edges from the dag D. Set M= Mp. • end for. • end if • end while.

More Related