Bipartite Matching. Unweighted Bipartite Matching.

Slides:



Advertisements
Similar presentations
Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Advertisements

Introduction to Algorithms NP-Complete
Social network partition Presenter: Xiaofei Cao Partick Berg.
Naveen Garg, CSE, IIT Delhi
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Midterm <  70 3.
(Algorithms in Bipartite Graphs). Introduction Algorithms in unweighted bipartite graph (Yehong & Gordon) Maximum matching A simple algorithm Hopcroft-Karp.
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.
What is the next line of the proof? a). Let G be a graph with k vertices. b). Assume the theorem holds for all graphs with k+1 vertices. c). Let G be a.
Matchings Lecture 3: Jan 18. Bipartite matchings revisited Greedy method doesn’t work (add an edge with both endpoints free)
Chapter 26 of CLSR Bipartite Matching By Dr. M. Sakalli, Sources: Levitin and many other CSE, Marmara Univ. May/2009.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
Maximum Bipartite Matching
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.
CSE 421 Algorithms Richard Anderson Lecture 4. What does it mean for an algorithm to be efficient?
1 Bipartite Matching Polytope, Stable Matching Polytope x1 x2 x3 Lecture 10: Feb 15.
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,
Matching Polytope, Stable Matching Polytope Lecture 8: Feb 2 x1 x2 x3 x1 x2 x3.
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,
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.
Chapter 10: Iterative Improvement Simplex Method The Design and Analysis of Algorithms.
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.
10.4 How to Find a Perfect Matching We have a condition for the existence of a perfect matching in a graph that is necessary and sufficient. Does this.
Lecture 16 Maximum Matching. Incremental Method Transform from a feasible solution to another feasible solution to increase (or decrease) the value of.
 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck.
Stable Matchings a.k.a. the Stable Marriage Problem
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
3.2 Matchings and Factors: Algorithms and Applications This copyrighted material is taken from Introduction to Graph Theory, 2 nd Ed., by Doug West; and.
Stable Matching Lecture 7: Oct 3. Matching A B C DE Boys Girls Today’s goal: to “match” the boys and the girls in a “good” way.
The Stable Marriage Problem
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.
Matching Lecture 19: Nov 23.
Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Introduction to Graph Theory
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
IOI/ACM ICPC Training 4 June 2005.
Matching Boys Girls A B C D E
Chapter 10 Iterative Improvement
Proof technique (pigeonhole principle)
Paths, Trees and Flowers
Bipartite Graphs What is a bipartite graph?
Algorithms and Networks
Lecture 16 Bipartite Matching
Maximum Flow - Best algorithms
Lectures on Network Flows
Various Graph Algorithms
Chapter 22: Elementary Graph Algorithms I
Lectures on Graph Algorithms: searching, testing and sorting
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.
Lecture 9 CSE 331 Sep 19, 2016.
Bipartite Matching By Dr. M
Youngki Kim Mobile R&D Laboratory KT, Korea
Piyush Kumar (Lecture 3: Stable Marriage)
Lecture 4: Matching Algorithms
Presentation transcript:

Bipartite Matching

Unweighted Bipartite Matching

Definitions Matching Free Vertex

Definitions Maximum Matching: matching with the largest number of edges

Definition Note that maximum matching is not unique.

Intuition Let the top set of vertices be men Let the bottom set of vertices be women Suppose each edge represents a pair of man and woman who like each other Maximum matching tries to maximize the number of couples!

Applications Matching has many applications. This lecture lets you know how to find maximum matching.

Alternating Path Alternating between matching and non-matching edges. a b cde f g hij d-h-e: alternating path a-f-b-h-d-i: alternating path starts and ends with free vertices f-b-h-e: not alternating path e-j: alternating path starts and ends with free vertices

Idea “Flip” augmenting path to get better matching Note: After flipping, the number of matched edges will increase by 1! 

Idea Theorem (Berge 1975): A matching M in G is maximum iff There 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!)

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.

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

Breadth-First Search Algorithm for Augmented Path Use Breadth-First Search: LEVEL(0) = some unmatched vertex r for odd L > 0, LEVEL(L) = {u|{v,u}  E – M when v  LEVEL(L -1) and when u in no lower level} For even L > 0, LEVEL(L) = {u|{v,u}  M when v  LEVEL(L -1) and u in no lower level} Assume G is bipartite graph with matching M.

Proof of Breadth-First Search Algorithm for Augmented Path Cases (1) If for some odd L >0, LEVEL(L) contains an unmatched vertex u then the Breadth First Search tree T has an augmenting path from r to u (2) Otherwise no augmenting path exists, so M is maximal.

Labelling Algorithm Start with arbitrary matching

Labelling Algorithm Pick a free vertex in the bottom

Labelling Algorithm Run BFS

Labelling Algorithm Alternate unmatched/matched edges

Labelling Algorithm Until a augmenting path is found

Augmenting Tree

Flip!

Repeat Pick another free vertex in the bottom

Repeat Run BFS

Repeat Flip

Answer Since we cannot find any augmenting path, stop!

Overall algorithm Start with an arbitrary matching (e.g., empty matching) Repeat forever  For all free vertices in the bottom, do bfs to find augmenting paths  If found, then flip the edges  If fail to find, stop and report the maximum matching.

Time analysis We can find at most |V| augmenting paths (why?) To find an augmenting path, we use bfs! Time required = O( |V| + |E| ) Total time: O(|V| 2 + |V| |E|)

Improvement We can try to find augmenting paths in parallel for all free nodes in every iteration. Using such approach, the time complexity is improved to O(|V| 0.5 |E|)

Weighted Bipartite Graph

Weighted Matching Score: 6+3+1=10

Maximum Weighted Matching Score: =13

Augmenting Path (change of definition) Any alternating path such that total score of unmatched edges > that of matched edges The score of the augmenting path is  Score of unmatched edges – that of matched edges Note: augmenting path need not start and end at free vertices!

Idea for finding maximum weight matching Theorem: Let M be a matching of maximum weight among matchings of size |M|.  If P is an augmenting path for M of maximum weight,  Then, the matching formed by augmenting M by P is a matching of maximum weight among matchings of size |M|+1.

Overall Algorithm Start with an empty matching Repeat forever  Find an augmenting path P with maximum score  If the score > 0, then flip the edges  Otherwise, stop and report the maximum weight matching.

Time analysis The same! Time required = O(|V| 2 + |V| |E|)

Stable Marriage Problem

Given N men and N women, each person list in order of preference all the people of the opposite sex who would like to marry. Problem:  Engage all the women to all the men in such a way as to respect all their preferences as much as possible.

Stable? A set of marriages is unstable if  two people who are not married both prefer each other than their spouses E.g. Suppose we have A1 B3 C2 D4 E5. This is unstable since  A prefer 2 more than 1  2 prefer A more than C ABCDE E A D B C 2 D E B A C 3 A D B C E 4 C B D A E 5 D B C E A

Naïve solution Starting from a feasible solution. Check if it is stable.  If yes, done!  If not, remove an unstable couple. Is this work?

Naïve solution (2) Does not work! E.g.  A1 B3 C2 D4 E5  A2 B3 C1 D4 E5  A3 B2 C1 D4 E5  A3 B1 C2 D4 E5 ABCDE E A D B C 2 D E B A C 3 A D B C E 4 C B D A E 5 D B C E A

Solution 1. Let X be the first man. 2. X proposes to the best woman in the remaining on his list. (Initially, the first woman on his list!) 3. If α is not engaged  Pair up (X, α). Then, set X=next man and goto If α prefers X more than her fiancee Y,  Pair up (X, α). Then, set X=Y and goto Goto 1

Example ABCDE E A D B C 2 D E B A C 3 A D B C E 4 C B D A E 5 D B C E A ABCDE

Time analysis If there are N men and N women,  O(N 2 ) time