COMP251: Bipartite graphs

Similar documents
COMP251: Bipartite graphs

Consider a complete bipartite graph with sets A and B, each with n vertices.

Analysis of Algorithms Fall Some Representative Problems Stable Matching

Algorithms. [Knuth, TAOCP] An algorithm is a finite, definite, effective procedure, with some input and some output.

1. REPRESENTATIVE PROBLEMS

1. REPRESENTATIVE PROBLEMS

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012

CSC2556. Lecture 5. Matching - Stable Matching - Kidney Exchange [Slides : Ariel D. Procaccia]

Algorithm Design and Analysis

Bipartite Matchings and Stable Marriage

Matchings in Graphs. Definition 3 A matching N in G is said to be stable if it does not contain a blocking pair.

1. REPRESENTATIVE PROBLEMS

Ma/CS 6b Class 3: Stable Matchings

Introduction to Algorithms

Algorithm Design and Analysis

1. STABLE MATCHING. stable matching problem Gale Shapley algorithm hospital optimality context

CS320 Algorithms: Theory and Practice. Course Introduction

Introduction to Algorithms

Single Source Shortest Paths

Ma/CS 6b Class 3: Stable Matchings

1.1 First Problem: Stable Matching. Six medical students and four hospitals. Student Preferences. s6 h3 h1 h4 h2. Stable Matching Problem

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Introduction to Algorithms

Design and Analysis of Algorithms

Omega notation. Transitivity etc.

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Math 301: Matchings in Graphs

Single Source Shortest Paths

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

Matching Residents to Hospitals

Stable Marriage with Ties and Bounded Length Preference Lists

Algorithms: Lecture 12. Chalmers University of Technology

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

Introduction to Algorithms

PROBLEMS OF MARRIAGE Eugene Mukhin

What do you do when you can t use money to solve your problems?

Subramanian s stable matching algorithm

Breadth-First Search of Graphs

Lecture 2: Just married

Matching Problems. Roberto Lucchetti. Politecnico di Milano

Graph Theory. Thomas Bloom. February 6, 2015

Matching Theory and the Allocation of Kidney Transplantations

Two-Sided Matching. Terence Johnson. December 1, University of Notre Dame. Terence Johnson (ND) Two-Sided Matching December 1, / 47

CS711008Z Algorithm Design and Analysis

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

Game Theory: Lecture #5

Matching. Terence Johnson. April 17, University of Notre Dame. Terence Johnson (ND) Matching April 17, / 41

CS 253: Algorithms. Chapter 24. Shortest Paths. Credit: Dr. George Bebis

CS 6901 (Applied Algorithms) Lecture 2

CS 598RM: Algorithmic Game Theory, Spring Practice Exam Solutions

Matching Problems. Roberto Lucchetti. Politecnico di Milano

Algorithms and Data Structures (COMP 251) Midterm Solutions

STABLE MARRIAGE PROBLEM WITH TIES AND INCOMPLETE BOUNDED LENGTH PREFERENCE LIST UNDER SOCIAL STABILITY

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Stable matching. Carlos Hurtado. July 5th, Department of Economics University of Illinois at Urbana-Champaign

cs.washington.edu/417

Strategic Behavior and Manipulation in Gender- Neutral Matching Algorithms

Matching Theory. Mihai Manea. Based on slides by Fuhito Kojima. MIT

1 Definitions and Things You Know

Introduction to Algorithms

An improved approximation algorithm for the stable marriage problem with one-sided ties

Midterm 1. Your Exam Room: Name of Person Sitting on Your Left: Name of Person Sitting on Your Right: Name of Person Sitting in Front of You:

CSEP 521 Applied Algorithms. Richard Anderson Winter 2013 Lecture 1

Matching and Stable Matching

Two Algorithms for the Student-Project Allocation Problem

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

CSE 417, Winter Introduc6on, Examples, and Analysis. Ben Birnbaum Widad Machmouchi

Algorithm Design and Analysis

The Man-Exchange Stable Marriage Problem

Applying Predicate Detection to the Constrained Optimization Problems

Shortest Path Algorithms

Lecture 5: The Principle of Deferred Decisions. Chernoff Bounds

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Combinatorial Optimisation, Problems I, Solutions Term /2015

Advanced Algorithms. Lecture Notes for April 5, 2016 Dynamic programming, continued (HMMs); Iterative improvement Bernard Moret

Stable Matching Problems with Exchange Restrictions

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

The Complexity of the Comparator Circuit Value Problem

SOLUTION: SOLUTION: SOLUTION:

A (ln 4)-Approximation Algorithm for Maximum Stable Matching with One-Sided Ties and Incomplete Lists

Algorithms and Theory of Computation. Lecture 11: Network Flow

Stable Matching Existence, Computation, Convergence Correlated Preferences. Stable Matching. Algorithmic Game Theory.

Improving Man-Optimal Stable Matchings by Minimum Change of Preference Lists

Popular Matchings with Lower Quotas

An Efficient Algorithm for Batch Stability Testing

Assignment 3 Logic and Reasoning KEY

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Algorithms: COMP3121/3821/9101/9801

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

We set up the basic model of two-sided, one-to-one matching

Minimization of Symmetric Submodular Functions under Hereditary Constraints

Chapter 7 Matchings and r-factors

d 2 -coloring of a Graph

Lecture 11. Single-Source Shortest Paths All-Pairs Shortest Paths

The Complexity and Proof Complexity of the Comparator Circuit Value Problem

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression

Algorithmics of Two-Sided Matching Problems

Cheating to Get Better Roommates in a Random Stable Matching

1 The Arthur-Merlin Story

Transcription:

COMP251: Bipartite graphs Jérôme Waldispühl School of Computer Science McGill University Based on slides fom M. Langer (McGill) & P. Beame (UofW)

Recap: Dijkstra s algorithm DIJKSTRA(V, E,w,s) INIT-SINGLE-SOURCE(V,s) S Q V while Q do u EXTRACT-MIN(Q) S S {u} for each vertex v Adj[u] do RELAX(u,v,w)

Recap: Correctness of Dijkstra Loop invariant: At the start of each iteration of the while loop, d[v] = δ(s,v) for all v S. Initialization: Initially, S =, so trivially true. Termination: At end, Q= S = V d[v] = δ(s,v) for all v V. Maintenance: Show that d[u] = δ(s,u) when u is added to S in each Iteration.

Recap: Correctness of Dijkstra Show that d[u] = δ(s,u) when u is added to S in each iteration. Suppose there exists u such that d[u] δ(s,u). Let u be the first vertex for which d[u] δ(s, u) when u is added to S. u s, since d[s] = δ(s,s) = 0. Therefore, s S, so S. There must be some path s u. Otherwise d[u] = δ(s,u) = by no-path property. So, there is a path s u. Thus, there is a shortest path p s u. p

Recap: Correctness of Dijkstra Show that d[u] = δ(s,u) when u is added to S in each iteration. Just before u is added to S, shortest path p connects a vertex in S (i.e., s) to a vertex in V S (i.e., u). Let y be first vertex along p that is in V S, and let x S be y is predecessor. p 2 s u p 1 S x y p 1 p 2 Decompose p into s x y u.

Recap: Correctness of Dijkstra Claim: d[y] = δ(s, y) when u is added to S. Proof: x S and u is the first vertex such that d[u] δ(s, u) when u is added to S d[x] = δ(s, x) when x is added to S. Relaxed (x, y) at that time, so by the convergence property, d[y] = δ(s, y). p 2 s u p 1 S x y

Recap: Correctness of Dijkstra Show that d[u] = δ(s,u) when u is added to S in each iteration. Now can get a contradiction to d[u] δ(s, u): y is on shortest path s d[y] = δ(s,y) δ(s,u) d[u] p u, and all edge weights are nonnegative. (from previous claim) (by sub-optimal paths property) (upper-bound property) In addition, since y and u were in Q when we chose u: d[u] d[y] d[u] = d[y]. But d[y] δ(s,u) d[u] d[y] = δ(s, u) = d[u]. Contradicts assumption that d[u] δ(s,u). n

Bipartite graphs A B Vertices are partitioned into 2 sets. All edges cross the sets.

Examples A Women Students People People Traditional marriage registration employment Have read/seen B Men Courses Companies Books/Movies

Counter-examples Easy to identify. But not always...

Cycles Claim: If a graph is bipartite if and only if does not contain an odd cycle. Proof: Exercise.

Is it a bipartite graph? Assuming G=(V,E) is an undirected connected graph. 1. Run DFS and use it to build a DFS tree. 2. Color vertices by layers (e.g. red & black) 3. If all non-tree edges join vertices of different color then the graph is bipartite. Non-tree edges in DFS tree cross 2 or more levels. Why?

Bipartite matching Consider an undirected bipartite graph. A B A matching is a subset of the edges { (α, β) } such that no two edges share a vertex. A B

Perfect matching A B Suppose we have a bipartite graph with n vertices in each A and B. A perfect matching is a matching that has n edges. Note: It is not always possible to find a perfect matching.

Complete bipartite graph A B A complete bipartite graph is a bipartite graph that has an edge for every pair of vertices (α, β) such that α A, β B.

The algorithm of happiness

Resident matching program Goal: Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and hospital y are unstable if: o x prefers y to their assigned hospital. o y prefers x to one of its admitted students. Stable assignment: Assignment with no unstable pairs. o Natural and desirable condition. o Individual self-interest will prevent any applicant/hospital deal from being made.

Stable matching problem Goal: Given n elements of A and n elements of B, find a "suitable" matching. Participants rate members of opposite set: Each element of A lists elements of B in order of preference from best to worst. Each element of B lists elements of A in order of preference from best to worst. A s preferences Xavier Alphabet Baidu Campbell Yulia Baidu Alphabet Campbell Zoran Alphabet Baidu Campbell B s preferences Alphabet Yulia Xavier Zoran Baidu Xavier Yulia Zoran Campbell Xavier Yulia Zoran

Stable matching problem Context: Candidates apply to companies. Perfect matching: everyone is matched with a single company. o Each candidate gets exactly one company. o Each company gets exactly one candidate. Stability: no incentive for some pair of participants to undermine assignment by joint action. o In matching M, an unmatched pair!-" is unstable if candidate! and company " prefer each other to current match. o Unstable pair!-" could each improve by escaping. Stable matching: perfect matching with no unstable pairs. Stable matching problem: Given the preference lists of n candidates and n companies, find a stable matching (if one exists).

Example Q: Is X-C, Y-B, Z-A a good assignment? X A Candidates Y B Companies Z C Candidates preferences Xavier Alphabet Baidu Campbell Yulia Baidu Alphabet Campbell Zoran Alphabet Baidu Campbell Companies preferences Alphabet Yulia Xavier Zoran Baidu Xavier Yulia Zoran Campbell Xavier Yulia Zoran

Example Q: Is X-C, Y-B, Z-A a good assignment? A: No! Xavier and Baidu will hook up X A Candidates Y B Companies Z C Candidates preferences Xavier Alphabet Baidu Campbell Yulia Baidu Alphabet Campbell Zoran Alphabet Baidu Campbell Companies preferences Alphabet Yulia Xavier Zoran Baidu Xavier Yulia Zoran Campbell Xavier Yulia Zoran

Example Q: Is X-A, Y-B, Z-C a good assignment? A: Yes! X A Candidates Y B Companies Z C Candidates preferences Xavier Alphabet Baidu Campbell Yulia Baidu Alphabet Campbell Zoran Alphabet Baidu Campbell Companies preferences Alphabet Yulia Xavier Zoran Baidu Xavier Yulia Zoran Campbell Xavier Yulia Zoran

Stable matching problem Consider a complete bipartite graph such that A = B =n. Each member of A has a preference ordering of members of B. Each member of B has a preference ordering of members of A. Algorithm for finding a matching: Each A member offer to a B, in preference order. Each B member accepts the first offer from an A, but then rejects that offer if/when it receives a offer from a A that it prefers more. In our example: Candidates applies to companies. Companies accept the first offer they receive, but companies will drop their applicant when/if a preferred candidate applies after. Note the asymmetry between A and B.

Gale-Shapley algorithm For each α A, let pref[α] be the ordering of its preferences in B For each β B, let pref[β] be the ordering of its preferences in A Let matching be a set of crossing edges between A and B matching Æ while there is α A not yet matched do β pref[α].removefirst() if β not yet matched then matching matchingè{(α,β)} else γ β s current match if β prefers α over γ then matching matching-{(γ,β)}è{(α,β)} return matching

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Men s preferences Companies preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Example X A Candidates Y B Companies Z C Candidates preferences Xavier Baidu Alphabet Campbell Yulia Baidu Campbell Alphabet Zoran Alphabet Campbell Baidu Companies preferences Alphabet Zoran Xavier Yulia Baidu Yulia Zoran Xavier Campbell Xavier Yulia Zoran

Correctness (termination) Observations: 1. Candidates apply to companies in decreasing order of preference. 2. Once a company is matched, it never becomes unmatched; it only "trades up." Claim: Algorithm terminates after at most n 2 iterations of while loop (i.e. O(n 2 ) running time). Proof: Each time through the while loop a candidate applies to a new company. There are only n 2 possible matches. n

Correctness (perfection) Claim: All candidates and companies get matched. Proof: (by contradiction) Suppose, for sake of contradiction, that Zoran is not matched upon termination of algorithm. Then some company, say Alphabet, is not matched upon termination. By Observation 2 (only trading up, never becoming unmatched), Alphabet never received any application. But, Zoran applies everywhere. Contradiction. n

Correctness (stability) Claim: No unstable pairs. Proof: (by contradiction) Suppose Z-A is an unstable pair: they prefer each other to the association made in Gale-Shapley matching. Case 1: Z never applied to A. Z prefers his GS match to A. Z-A is stable. Case 2: Z applied to A. A rejected Z (right away or later) A prefers its GS match to Z. Z-A is stable. In either case Z-A is stable. Contradiction. n

Optimality Definition: Candidate! is a valid partner of company " if there exists some stable matching in which they are matched. Applicant-optimal assignment: Each candidate receives best valid match (according to his preferences). Claim: All executions of GS yield a applicant-optimal assignment, which is a stable matching!

Applicant-Optimality Claim: GS matching S* is applicant-optimal. Proof: (by contradiction) Suppose some candidate is paired with someone other than his best option. Candidates apply in decreasing order of preference some candidate is rejected by a valid match. Let Y be first such candidate, and let A be the first valid company that rejects him (i.e. A-Y is optimal). Let S be a stable matching (not from GS) where A and Y are matched. In GS, when Y is rejected, A forms (or reaffirms) engagement with a candidate, say Z, whom it prefers to Y (i.e. A prefers Z to Y) Let B be Z's match in S (i.e. B-Z is optimal). In GS, Z is not rejected by any valid match at the point when Y is rejected by A. Thus, Z prefers A to B (because B-Z is optimal). But A prefers Z to Y. Thus A-Z would be preferred in S (i.e. A-Y and B-Z are unstable).