COMP251: Bipartite graphs

Similar documents
COMP251: Bipartite graphs

Analysis of Algorithms Fall Some Representative Problems Stable Matching

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

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

Single Source Shortest Paths

Introduction to Algorithms

1. REPRESENTATIVE PROBLEMS

Introduction to Algorithms

Bipartite Matchings and Stable Marriage

Design and Analysis of Algorithms

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

CS 4407 Algorithms Lecture: Shortest Path Algorithms

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

Single Source Shortest Paths

Ma/CS 6b Class 3: Stable Matchings

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

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

CS320 Algorithms: Theory and Practice. Course Introduction

Algorithm Design and Analysis

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

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

Ma/CS 6b Class 3: Stable Matchings

Introduction to Algorithms

Math 301: Matchings in Graphs

Matching Residents to Hospitals

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

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

Algorithms: Lecture 12. Chalmers University of Technology

Omega notation. Transitivity etc.

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

Breadth-First Search of Graphs

Stable Marriage with Ties and Bounded Length Preference Lists

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

Subramanian s stable matching algorithm

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

PROBLEMS OF MARRIAGE Eugene Mukhin

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

Game Theory: Lecture #5

Lecture 2: Just married

Matching Theory and the Allocation of Kidney Transplantations

Algorithm Design and Analysis

CS 6901 (Applied Algorithms) Lecture 2

Matching Problems. Roberto Lucchetti. Politecnico di Milano

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

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

Graph Theory. Thomas Bloom. February 6, 2015

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Matching Problems. Roberto Lucchetti. Politecnico di Milano

Algorithm Design and Analysis

1 Definitions and Things You Know

Shortest Path Algorithms

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

cs.washington.edu/417

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

CS711008Z Algorithm Design and Analysis

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

Algorithms and Data Structures (COMP 251) Midterm Solutions

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

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

CMU Lecture 4: Informed Search. Teacher: Gianni A. Di Caro

PGSS Discrete Math Solutions to Problem Set #4. Note: signifies the end of a problem, and signifies the end of a proof.

Introduction to Algorithms

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

Strategic Behavior and Manipulation in Gender- Neutral Matching Algorithms

Matching and Stable Matching

Applying Predicate Detection to the Constrained Optimization Problems

CSEP 521 Applied Algorithms. Richard Anderson Winter 2013 Lecture 1

Assignment 3 Logic and Reasoning KEY

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

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

The Man-Exchange Stable Marriage Problem

Lecture 5: The Principle of Deferred Decisions. Chernoff Bounds

Recall: Matchings. Examples. K n,m, K n, Petersen graph, Q k ; graphs without perfect matching

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

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:

Branch-and-Bound for the Travelling Salesman Problem

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

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

Two Algorithms for the Student-Project Allocation Problem

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

The Complexity of the Comparator Circuit Value Problem

Stable Matching Problems with Exchange Restrictions

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

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

An Efficient Algorithm for Batch Stability Testing

Popular Matchings with Lower Quotas

Housing Markets with Indifferences: a Tale of Two Mechanisms

Slides credited from Hsueh-I Lu & Hsu-Chun Hsiao

Cheating to Get Better Roommates in a Random Stable Matching

Combinatorial Optimisation, Problems I, Solutions Term /2015

d 2 -coloring of a Graph

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

MA015: Graph Algorithms

Algorithms: COMP3121/3821/9101/9801

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

what will be the value of d[v] after relaxation of the edge (u,v)? 12 9 17 7 None of the values proposed

We want to calculate the shortest paths from s in a DAG with negative weight edges. Is it ok? Yes because there are no negative weight cycles. Not a problem. Negative weight edges cannot be reached from the source. This is wrong! Negative weight edges are forbidden even in case of a DAG.

Let u be a vertex extracted from the queue during the execution of the Dijkstra's algorithm. What would happen if we use a First- In-First-Out queue instead of a min priority queue? We cannot guarantee that the shortest-path estimate of u is the shortest path from s to u. Relaxing the outgoing edges of u is useless (i.e. it will not change the shortest path estimates). It does not matter. We can use a FIFO queue.

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: Q5 of assignment 2.

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 marriage 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 marriage 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 marriage 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).