Analysis of Algorithms Uri Zwick April 2014 Maximum matching 1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAA.

Slides:



Advertisements
Similar presentations
The Primal-Dual Method: Steiner Forest TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA A A AA A A A AA A A.
Advertisements

Min-Max Relations, Hall’s Theorem, and Matching-Algorithms Graphs & Algorithms Lecture 5 TexPoint fonts used in EMF. Read the TexPoint manual before you.
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Algorithms and Networks
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
Maurizio Patrignani seminar on the paper on the single-source unsplittable flow problem authored by Yefim Dinitz Naveen Garg Michel X. Goemans FOCS ‘98.
Lectures on Network Flows
Finding a Maximum Matching in Non-Bipartite Graphs Alicia Thilani Singham Goodwin /22/2013.
Yangjun Chen 1 Bipartite Graphs What is a bipartite graph? Properties of bipartite graphs Matching and maximum matching - alternative paths - augmenting.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Chapter 23 Minimum Spanning Trees
Data Transmission and Base Station Placement for Optimizing Network Lifetime. E. Arkin, V. Polishchuk, A. Efrat, S. Ramasubramanian,V. PolishchukA. EfratS.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Totally Unimodular Matrices Lecture 11: Feb 23 Simplex Algorithm Elliposid Algorithm.
Matchings Lecture 3: Jan 18. Bipartite matchings revisited Greedy method doesn’t work (add an edge with both endpoints free)
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Increasing graph connectivity from 1 to 2 Guy Kortsarz Joint work with Even and Nutov.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Yangjun Chen 1 Bipartite Graph 1.A graph G is bipartite if the node set V can be partitioned into two sets V 1 and V 2 in such a way that no nodes from.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
1 Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Algorithmic Game Theory and Internet Computing Vijay V. Vazirani Georgia Tech Dispelling an Old Myth about an Ancient Algorithm.
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
CSE, IIT KGP Matchings and Factors. CSE, IIT KGP Matchings A matching of size k in a graph G is a set of k pairwise disjoint edges.A matching of size.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Advanced Algorithms Piyush Kumar (Lecture 4: MaxFlow MinCut Applications) Welcome to COT5405.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
Bipartite Matching. Unweighted Bipartite Matching.
1 “Graph theory” Course for the master degree program “Geographic Information Systems” Yulia Burkatovskaya Department of Computer Engineering Associate.
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
Assignments and matchings Chapter 12 Presented by Yorai Geffen.
Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
1 Assignment #3 is posted: Due Thursday Nov. 15 at the beginning of class. Make sure you are also working on your projects. Come see me if you are unsure.
Connectivity. Graph Scanning Algorithm Input: A graph G and some vertex s. Output: The set R of vertices reachable from s and a set T ⊆ E(G) such that.
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Analysis of Algorithms
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Paths, Trees and Flowers
Bipartite Graphs What is a bipartite graph?
Algorithms and Networks
Algorithm Design and Analysis
Lectures on Network Flows
Chapter 5. Optimal Matchings
Minimum-Cost Spanning Tree
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Analysis of Algorithms
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Problem Solving 4.
Bipartite Graph 1. A graph G is bipartite if the node set V can be partitioned into two sets V1 and V2 in such a way that no nodes from the same set are.
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
Algorithms (2IL15) – Lecture 7
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Minimum-Cost Spanning Tree
Presentation transcript:

Analysis of Algorithms Uri Zwick April 2014 Maximum matching 1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAA

2 A subset of edges no two of which touch each other Maximal but not maximum matching Matching

3 A subset of edges no two of which touch each other An augmenting path Matching

4 A subset of edges no two of which touch each other A maximum (even perfect) matching

5 Maximum matching The maximum matching problem in bipartite graphs can be easily reduced to a maximum network flow problem The problem in non-bipartite graphs is harder. First polynomial time algorithm given by [Edmonds (1965)] The bipartite case can be solved in O(mn 1/2 ) time [Hopcroft-Karp (1973)] ([Dinic (1970) ] [Even-Tarjan (1975)]) An O(mn α(m,n))-time implementation of Edmonds’ algorithm was given by [Gabow (1976)] An O(mn 1/2 )-time algorihm for the non-bipartite case given by [Micali-Vazirani (1980)] ([Vazirani (2014)]) and later also by [Gabow-Tarjan (1991)]

Alternating paths and cycles with respect to a given matching M An alternating path/cycle P is simple path such that among any two consecutive edges, one is in M and one is not Lemma: If P is an alternating path such that its endpoints are either unmatched, or matched by the edges touching them in P, then M  P is also a matching

Augmenting paths with respect to a given matching M An alternating path that starts and ends in unmatched vertices Theorem: [Petersen (1891)] [Kőnig (1931)] [Berge (1957)] M is a maximum matching if and only if there are no augmenting paths with respect to M. How do we find augmenting paths?

Proof of augmenting paths theorem Lemma 1: If M and M’ are matchings, then M  M’ is composed of isolated vertices, alternating paths and alternating cycles with respect to both M and M’. Lemma 2: If M and M’ are matchings and |M’|=|M|+k, where k  1, then there are at least k vertex disjoint alternating paths with respect to M. At least one of these augmenting paths is of length at most n/k−1. The theorem follows easily

Alternating forests Roots are unmatched Vertices in the forest are even or odd depending on the parity of their level All root to leaf paths are alternating even odd even odd Scan unmatched edges of even vertices; Scan matched edges of odd vertices; Until an augmenting path (or a blossom) is found, or until all appropriate edges are scanned

Extending an alternating forest Add an unmatched vertex as a root

Extending an alternating forest Augmenting path found An unmatched edge from an even vertex to an unmatched vertex

Unmatched edge between two even vertices in different trees Augmenting path found Extending an alternating forest

Matched edge between two odd vertices in different trees Augmenting path found Extending an alternating forest

Tree extended An unmatched edge from an even vertex to a matched vertex not already in the forest Extending an alternating forest

Tree extended A matched edge from an odd vertex to a vertex not in the forest Extending an alternating forest

Ignore (for the time being) A unmatched edge from an even vertex to an odd vertex Extending an alternating forest

An unmatched edge connecting two even vertices of the same tree Blossom found Extending an alternating forest

Blossom found A matched edge connecting two odd vertices of the same tree Extending an alternating forest

Scanning strategies In the generic algorithms for bipartite and non-bipartite graphs, the order in which edges are scanned is arbitrary Fewer cases arise if when scanning an unmatched edge leading to a matched vertex not in the forest, we immediately scan the matched edge and add it to the forest We can build the trees of the forest one by one in DFS order (again fewer cases to consider) We can build all trees simultaneously, level by level, in BFS order, to find shortest augmenting paths

Correctness Theorem: If there is an augmenting path, then the scanning algorithm, with any scanning order, finds either an augmenting path or a blossom If the scanning algorithm terminates, all vertices on the augmenting path must be labeled even or odd If the labels alternate, then one of the endpoints is odd and an augmenting path must have been found Otherwise, there must be an unmatched edge between two even vertices, or a matched edge between two odd vertices  augmenting path or a blossom found eoee

21 Vertex cover A set C  V is a vertex cover if at least one endpoint of each edge belongs to C For every matching M and vertex cover C: |M| ≤ |C|

22 Minimum vertex cover In general graphs, finding minimum vertex cover is an NP-hard problem. (C is a VC iff V−C is an independent set.) In bipartite graphs, a minimum vertex cover can be easily obtained from a maximum matching. Theorem: [Kőnig (1931)] [Egerváry (1931)] In a bipartite graph, the size of a maximum matching is equal to the size of a minimum vertex cover Special case of the max-flow min-cut theorem, which in turn is a special case of LP-duality

Maximum matching = Minimum vertex cover (in bipartite graphs) Construct a fully-grown alternating forest from all unmatched vertices of S G=(S,T,E) Take the T endpoints of the edges of M in the forest, and the S endpoints of the edges of M not in the forest

Maximum matching  Minimum vertex cover (in general graphs) But, stay tuned…

Equivalent formulation of the scanning algorithm for Bipartite graphs S T Direct unmatched edges from S to T Direct matched edges from T to S

Equivalent formulation of the scanning algorithm for Bipartite graphs Direct unmatched edges from S to T S T Direct matched edges from T to S Alternating path  Directed path Augmenting path  Directed path from an unmatched vertex in S to an unmatched vertex in T Residual flow network

27 The algorithm of Hopcroft-Karp (1973) for bipartite graphs Start with some (possibly empty) matching M In each phase, find a maximal collection of vertex disjoint shortest augmenting paths Number of phases is at most 2n 1/2 Each phase can be implemented in O(m) time Total running time is O(mn 1/2 )

Forest  Layered graph Grow the graph, level by level from all unmatched vertices of S Stop after completing the first level that contains unmatched vertices from T Find a maximal set of vertex disjoint shortest augmenting paths

Forest  Layered graph Grow the graph, level by level from all unmatched vertices of S Stop after completing the first level that contains unmatched vertices from T Find a maximal set of vertex disjoint shortest augmenting paths

Forest  Layered graph Grow the graph, level by level from all unmatched vertices of S Stop after completing the first level that contains unmatched vertices from T Find a maximal set of vertex disjoint shortest augmenting paths

Number of phases Lemma: If P be a shortest augmenting path w.r.t. M and let P’ be a shortest augmenting path w.r.t. M  P. Then, |P’|  |P|+2|P  P’|. N= (M  P)  P’ |N|= |M|+2 M  N = P  P’ contains two disjoint augmenting path P 1 and P 2 w.r.t. to M

Number of phases Lemma: If P 1,…,P k be a maximal collection of shortest augmenting path w.r.t. M. Let P’ be a shortest augmenting path w.r.t. M  P 1  P k. Then, |P’| > |P 1 |=…=|P k |. P k is an augmenting path w.r.t. M  P 1  P k−1. If P’ is disjoint from P 1,…,P k then P’ is also augmenting w.r.t. M Assume, w.l.o.g. that P’  P k . (Otherwise, reorder.) By the previous lemma, |P’|  |P k |+ 2|P’  P k | > |P k | By the maximality of the collection |P’| > |P 1 |=…=|P k |.

Number of phases Theorem: The algorithm of Hopcroft and Karp finishes after at most 2n 1/2 phases By previous lemma, the augmenting paths found in each phase get longer and longer After n 1/2 phases, if algorithm is not yet done, the augmenting paths are of length at least n 1/2 By Lemma 2 on slide 8, the number of edges missing in the current matching is at most n 1/2 Thus, a maximum matching is found after at most n 1/2 additional phases

Flowers and blossoms A flower with respect to M is composed of a stem, which is an alternating path of even length from an unmatched vertex r, called the root, to a vertex b, called the base, and an odd ‘alternating’ cycle B that passes through b, called the blossom r b B The stem may be empty, in which case b=r is unmatched An odd ‘alternating’ cycle is called a blossom only of it is a part of a flower

The challenge of blossoms ee e o o o e ee e e o o o o

ee e e o o o o o e ee e e o o o o o e oe

Shrinking (contracting) blossoms Contract the blossom and consider it to be a (super) even vertex Scan unmatched edges from all vertices of the blossom, including those that were originally odd

Augmenting path in contracted graph  Augmenting path in original graph B The matched edge must enter B at b. The blossom contains an even alternating path from b to c. Theorem: If there is an augmenting path P after shrinking a blossom B, then there is also an augmenting path before the shrinking B b c

Theorem: If there is an augmenting path P before shrinking a blossom B, then there is also an augmenting path after the shrinking If P does not pass though B, then P is also an augmenting path in the contracted graph What do we do if P does pass through B? Important to note that B is part of a flower and thus has a (possibly empty) stem Q Augmenting path in original graph  Augmenting path in contracted graph

Is P an augmenting path in the contracted graph? B b P is not necessarily a simple path in the contracted graph P is not necessarily an alternating path in the contracted graph P

Theorem: If there is an augmenting path P before shrinking a blossom B, then there is also an augmenting path after the shrinking B b Easy case: B has an empty stem Let P’ be the subpath of P that starts at an endpoint a of P that is not b and continues until the first encounter with B P’ is an augmenting path from a to B in the contracted graph P’ a B is unmatched in the contracted graph Rest of P c Augmenting path in original graph  Augmenting path in contracted graph

B b Hard(er) case: B has a non-empty stem If the first encounter of P with the flower is at B, and not at the stem Q, than this is again an easy sub-case P’ a r Rest of P c

B b Hard(er) case: B has a non-empty stem If the first encounter of P with the flower is at B, and not at the stem Q, than this is again an easy sub-case But, what if P, from both its sides, first encounters the flower at its stem? P’ a r Rest of P c We can either face the problem head on, or bypass it

Hard(er) case: B has a non-empty stem Let G B be the contracted graph Easy solution for hard(er) case B br Q Let Q be a stem of the flower with blossom B Let M B = M−B be the matching in the contracted graph Let M’= M  Q

Hard(er) case: B has a non-empty stem Let G B be the contracted graph B br Q Let Q be a stem of the flower with blossom B Let M B = M−B be the matching in the contracted graph Let M’= M  Q |M’|= |M| and |M B |= |M’ B | B is a blossom with an empty stem w.r.t. M’ By the easy case, there is an augmenting path w.r.t. M’ B, and hence also w.r.t. M B M’ Easy solution for hard(er) case

Hard(er) case: B has a non-empty stem First encounters of P with the flower are at the stem Q B b r P’ a Start with an endpoint a of P that is not r P’ is the subpath of P until first encounter with the stem If P’ meets the stem at an even vertex c, that is again an easy sub-case c Direct solution for hard(er) case Q

Hard(er) case: B has a non-empty stem First encounters of P with the flower are at the stem Q B b r P’ a Start with an endpoint a of P that is not r P’ is the subpath of P until first encounter with the stem If P’ meets the stem at an even vertex c, that is again an easy sub-case c Direct solution for hard(er) case Q

P first encounters stem at odd vertices If P does not enter B, then P remains an augmenting path Let P’ be the subpath of P until first encounter with the stem Let P’’ be the subpath of P from the last time it leaves B B b r P’ a c P’’ Do we always get an augmenting path P’, (c to B), P’’ ??? Unfortunately not. (Why?) Hard(er) case: B has a non-empty stem Direct solution for hard(er) case

A challenging example Where is the augmenting path? Not in the picture… B b P’ P’’ r a c

If P be an augmenting path, and let Q be a stem of B such that P first meets Q as close as possible to B P’’ be cannot intersect the path (c to B) B b r P’ a c P’’ We thus get an augmenting path P’, (c to B), P’’ Hard(er) case: B has a non-empty stem Direct solution for hard(er) case

Nested blossoms Number of vertices k in a (nested) blossom is always odd Number of matched edges in the blossom is (k−1)/2 Only vertex unmatched inside a blossom is its base There is an even alternating path from the base to any other vertex in the blossom

An augmenting path through nested blossoms

An augmenting path through nested blossoms How do we find such a path?

Nested blossoms

Nested blossoms

56 Odd Vertex cover A set C  V and a collection of subsets B 1,…,B k  V is an odd vertex cover if for every edge e either e  C≠  or e  B i for some i The cost of the odd vertex cover is defined to be Without loss of generality, we may assume that all the sets B i are of odd size, hence the name, and that C and B 1,…,B k are disjoint

57 Odd Vertex cover Theorem: In any graph, the size of the maximum matching is equal to the cost of the minimum odd vertex cover To prove equality we look at the alternating forest constructed using the last (failed) iteration of Edmonds’ algorithm For every matching M and every odd vertex cover C and B 1,…,B k we have

Maximum matching = Minimum odd vertex cover Every even node in the forest is possibly a nested blossom The set C is composed of the odd vertices in the forest, plus an arbitrary vertex not in the forest Each blossom becomes a set B i. The vertices not in the forest, except one, become the last set B k |C| is equal to the number of edges of M not contained in the B i ’s. The cost of each B i is equal to the number of edges of M in it.

59 Tutte-Berge Theorem [Tutte (1947)] [Berge (1958)] Theorem: In any graph, the size of the maximum matching is equal to Proof: Take X to be the set of odd vertices in the final alternating tree where odd(G−X) is the number of connected components in G−X with an odd number of vertices

Using an explicit representation of the blossoms we can get an O(n 3 ) implementation If v is in a (nested) blossom, then find(v) returns its base. If v is not in a blossom, then find(v)=v Efficient Implementation To get an O(mn α(m,n)) implementation we represent the blossoms implicitly using a union-find data structure When a new blossom is found, we perform the appropriate union operations, making sure that the base is the representative item returned by find operations An edge (u,v) in the original graph corresponds to an edge (u’,v’) in the contracted graph, where u’=find(u) and v’=find(v)

mate[v] – the vertex to which v is currently matched, if there is one. Otherwise mate[v]=null. (If v is matched, (v,mate[v])  M.) Efficient Implementation pred[v] – the parent of v in the alternating forest. If v is a root, or not in the forest, then pred[v]=null. (We define pred[v] only for odd vertices.) label[v] – the parity (even or odd) of v in the alternating forest. If v is not in the forest, then label[v]=null. pred[v] and label[v] are not changed when a blossom is formed bridge[v] – the bridge (see below) that formed the first blossom containing the odd vertex v

Efficient Implementation Q – a list of vertices to be scanned, i.e., even forest vertices and vertices contained in blossoms Initially, either a single unmatched vertex, or all unmatched vertices are placed in Q By letting Q be a queue or a stack, we can implement BFS or DFS search strategies

Shrinking a blossom v w v0v0 v1v1 b=v 2 =w 1 w0w0 When (v,w) is examined: v 0 = find(v) w 0 = find(w) As v 0 and w 0 are both even, and are in the same tree, a blossom is found Find the base of the new blossom v 1 = find( pred[mate[v 0 ]] ) v 2 = find( pred[mate[v 1 ]] ) …

Shrinking a blossom v w v0v0 v1v1 b=v 2 =w 1 w0w0 Climb up from v 0 and w 0, alternatingly. First vertex already visited is b. For every i do: union(b,mate[v i ]) bridge[mate[v i ]]  (v,w) insert(Q,mate[v i ]) union(b,v i ) For every j do: union(b,mate[w j ]) bridge[mate[w j ]]  (w,v) insert(Q,mate[w j ]) union(b, w j )

Shrinking a blossom v w v0v0 v1v1 b=v 2 =w 1 w0w0 Time proportional to size of new blossom, and does not depend on sizes of the sub-blossoms

Find-path find-path(s,t) finds an even alternating path from s to t, starting with a matched edge, provided that s’,t’ are even and s’ was a descendant of t in the alternating forest at some stage If (v,w) is scanned, where w is unmatched vertex, and r is the root of the tree containing v, then (w,v) + find-path(v,r) is an augmenting path If (v,w) is scanned, where v,w are even vertices in different trees, and r and r’ are their roots, then reverse(find-path(v,r) + (v,w) + find-path(w,r’) is an augmenting path

Find-path find-path(s,t) finds an even alternating path from s to t, starting with a matched edge, provided that s’,t’ are even and s’ was a descendant of t in the alternating forest at some stage If s is even, we go two steps up the tree using the edges (s,mate[s]) and (mate[s],pred[mate[s]]). We then use find-path(pred[mate[s]],t)

Find-path + denotes catenation of lists How do we implement reverse ?