40
Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Embed Size (px)

Citation preview

Page 1: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Section 2.1 “Matching in bipartite graphs”in Graph Theory

Handout for reading seminar

Page 2: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Matching Task: Find independent edges as many as

possible.• Independent edges: edges not sharing any vertex.

– Q: Are there independent edges containing all vertices?

Matching M E of U given G=(V,E) and U V – Every vertex in U is incident with an edge in M.

• A set M E of independent edges in graph G.

G Vertices in U are matched

by M1.

unmatchedU={v1, v2, v3, v4}

v1

v2v3 v4 Vertices in V are matched

by M2.

Page 3: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

k-factor k-factor: a k-regular spanning subgraph

– k-regular• graph any of whose vertex has the same degree k

– spanning subgraph • one having all vertices of the original graph

The followings are equivalent.– A subgraph H G=(V,E) is a 1-factor of G.– E(H) (a set of edges in H) is a matching of V.

G2-regular M2 (matched) unmatched

Page 4: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Notation in this section– G = (V, E): bipartite graph with bipartition {A, B}

• V=A B, A B = .

• a, a’,… represent vertices in A. No edge between a, a’.

• b, b’,… represent vertices in B. No edge between b, b’.

GA B

a

b

ab

A BA BExamples of matchings

Page 5: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Matching and augmenting paths (1/3) How can we find a (large) matching?

– By expanding a small one with augmenting paths.• Augmenting path

– Starts an unmatched vertex in A, and ends at an unmatched one in B.

– Vertices except 1st and last in the path are attached to edges in M.

– In finding an augmenting path, the followings are repeated:

» Move from A to B through an edge in E – M.

» Move from B to A through an edge in M.

A B A B

Matching M Augmenting path P

Page 6: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Matching and augmenting paths (2/3) How can we find a (large) matching?

– By expanding a small one with augmenting paths.• Suppose M and an augmenting path P are given.

• (E(P) M) (M E(P)) is also a matching.– Each vertex on P is incident with just one edge in E(P) M. Then

E(P) M is a matching.

– M E(P) is obviously a matching.

– These sets do not share any vertex, so the union is also a matching.

A B A B A B

Matching M Matching M’Augmenting path P

Page 7: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Matching and augmenting paths (3/3) How can we find a matching?

– By expanding a small one with augmenting paths.• Two new vertices (the first and the last vertices in the path)

are included in the new matching with one expansion.

Alternating path– Augmenting one w/o the condition on the end vertex.

• The end is not necessarily an unmatched vertex in B.

A B A B A B

Matching M Matching M’Augmenting path P

Page 8: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Exercise 1 Suppose that M is a matching not maximal.

– M has less edges than some other matching M’ in G. Then G contains an augmenting path w.r.t. M. Proof

– A edge e in M’ – M is an augmenting path. What happens when M is not maximum but

maximal? (HW)

A B

G

A B

Matching M

A B

Aug. path w.r.t. M

A B

New matching M’

Page 9: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Vertex cover A set U E is a vertex cover of E if every edge

of G is incident with a vertex in U.

A B

G

A Bv. cover

A B

G not a v. coverA B

not a v. coverv. cover

Page 10: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (1/6) Let M and U be a maximum matching and a

minimum vertex cover in G=(A B, E). Then, |M| = |U|.

Its proof consists of three parts.– Show that |M| |U’|, where U’ is any vertex cover.– Construct U from M, where |U|=|M|.

• If U is a vertex cover, it is the minimum since |M| |U’|.

– Show that U is a (minimum) vertex cover.

Page 11: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (2/6) Proof for |M| |U’| (showing |M||T||U’|)

– www.cs.mcgill.ca/~kaleigh/teaching/360_tutorials/tutorial_07.html

– All the endpoints of the edges in M are distinct. -- (1)• By definition of matching.

– A vertex cover T of M requires at least one end for each edge in M. -- (2)

– T then has to have at least |M| vertices (|M||T|). – G contains at least the same edges of M.– To cover edges in M, |U’| (vc of G) must be at least |

T|.

(1) (2)

T

G

U’

Page 12: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (3/6) Construction of U from M

– We will construct a vertex cover U from M as follows:• Choose one end a or b from each edge ab M as follows:

• Choose b in B if some alternating path ends in the vertex.

• Choose a in A otherwise.

A B A B A B A B

Alternating paths Vertex cover

Page 13: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (4/6) Proof that U is a vertex cover

– For any edge abE(G), show aU or bU (that is, ab is covered by U) (*).

ab E ab M?

ab M

ab M By the construction ofU, aU or bU (*).

Any matching incident with a or b ?

ab’ M for some b’

a’b M for some a’ab’ M and a’b M for any a’ and b’

{ab}M is a matching. This contradicts with that M is maximum.

b’

a’a

b

a

b

a

b

Page 14: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (5/6) Proof that U is a vertex cover

– For any edge abE(G), show aU or bU (that is, ab is covered by U) (*).

ab E

ab’M forsome b’

a’b Mfor some a’

impossible

Any matching incident witha or b ? ab is an alt. path.

Since a’bM, bU by def. of U. (*)

aU?

aU (*)

aU

b’U since ab’M.Since b’ is selected,there must be an alt. path P ending at b’ by definition of U.

a b’

b

a’a

b

Pai bj ak b’

Page 15: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (6/6) Proof that U is a vertex cover

– For any edge abE(G), show aU or bU (that is, ab is covered by U) (*).

ab E aU?

aU

b’U since ab’M.b’ is selected, thenthere must be an alt. path P ending at b’ by definition of U.

P’=Pb

P’=Pb’ab

M is not maximum. Then, a must be in U.

From P, we can create an alt. path P’ ending at b.

Pai bj ak b’ ai bj ak b’

ai bj ak b’b

(if bP)

Pa b

(if bP)

P’ is anaug. pathending at b.

A matching larger than M can be obtained with P’.

a b’

b

Page 16: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Conditions for the existence of 1-factor Consider a matching containing all vertices in A. Necessary condition

– |N(S)||S| for all S A (the marriage condition; MC), where

• S: any subset of A

• N(S): neighbors of vertices in S

The condition is in fact a sufficient condition.

{a, a’, a’’}

{a’’}

{a’, a’’}

|N(S)|311

|S|321

S{a, a’, a’’}

{a’’}

{a’, a’’}

|N(S)|322

|S|321

Matching of A unavailable

Page 17: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.2 (Hall 1935) (1/5) G contains a matching M of A iff |N(S)||S| for all

S A. ()

– a A has at least one neighbor, i.e., |N({a})||{a}|=1.

• For any aA, there is an edge ab in M for some bB.

– Neighbors of a and a’ in M can be distinct if a a’.• We can choose the other ends of a, a’ in M as the neighbors.

– For any S, at least |S| distinct neighbors can be found.• That is, |N(S)||S| for all S A.

Page 18: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.2 (Hall 1935) (2/5) G contains a matching iff |N(S)||S| for all S A.

– We follow here the third proof in the textbook. ()

– Consider a spanning subgraph H of G that • satisfies the marriage condition (MC), and

• is edge-minimal with MC.

– Note dH(a)=|NH(a)||{a}|=1for every aA by MC.

– We show dH(a) =1 for every aA.• Then, E(H) forms a matching of A.

– MC guarantees that no two such edges can share a vertex in B.dH(a)=1

dH(a’)=1 a’

a |{a1,a2}|=2,|N({a1,a2})|=1.

Page 19: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.2 (Hall 1935) (3/5) G contains a matching iff |N(S)||S| for all S A. ()

– Proof by contradiction on H

– Suppose dH(a) 2, and the neighbors are b1 and b2.

– Since the edge of H is minimal for MC, H – ab1 and H – ab2 should violate MC for some A1, A2 A.

– Bi :=NH – abi(Ai).

a

b1

b2

A1

a

b1

b2

A2B1 B2

|A1|=| NH (A1) |

|A1|>| NH – ab1(A1)|= |B1|

|A2|=| NH (A2) |

|A2|>| NH – ab2(A2)|= |B2|

Page 20: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.2 (Hall 1935) (4/5) G contains a matching iff |N(S)||S| for all S A. ()

– |NH(A1A2 –{a})| |NH-ab1-ab2(A1A2)|

– |NH-ab1-ab2(A1 ) NH-ab1-ab2(A2)|

– = |B1 B2|

– = |B1| + |B2| – |B1 B2|

– = …b1

b2

A1

a

b1

b2

A2

NH(A1A2 –{a}) B1B2

a |B1B2| |B1| |B2| |B1 B2|

= + –

Page 21: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.2 (Hall 1935) (5/5) G contains a matching iff |N(S)||S| for all S A. ()

– |NH( A1A2 –{a})| …– |B1| + |B2| – |B1 B2|– |A1| – 1+ |A2| – 1– |A1 A2|

• By the definition of Ai and Bi (|Ai| > |Bi| |Ai| – 1 |Bi|)

– = |A1| + |A2|– |A1 A2| – 2– = |A1A2 | – 2 = |A1A2 –{a}| – 1.– Hence H violates the marriage condition, contrary to the

assumption.– Therefore, dH(a) =1 for every aA.

Page 22: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Corollary 2.1.3 If G is k-regular with k 1, then G has a 1-factor.

– k-factor: a k-regular spanning subgraph• k-regular

– graph any of whose vertex has the same degree k

• spanning subgraph – one having all vertices of the original graph

– A 1-factor is also called a perfect matching.2-regular 3-regularIts 1-factor Its 1-factor

Page 23: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof of Corollary 2.1.3 (1/2) |A|=|B|.

– Since G is k-regular, dA=vAd(v)=k|A| and dB=vBd(v)=k|B|.

– Since G is bipartite, each edge connects a vertex in A to a vertex in B. Then, dA= dB, that is, k|A|=k|B|.

We will see that |N(S)||S| for all S A.– By Theorem 2.1.2, G then has a 1-factor (perfect

matching).

dA

=3*4dB

=3*4

Page 24: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof of Corollary 2.1.3 (2/2) We will see that |N(S)||S| for all S A.

– Every set S A is joined to N(S) by k|S| edges.– These k|S| edges ( ) are among the k|N(S)| edges ( )

of G incident with N(S). – Then, k|S| k|N(S)| for any S, which satisfies the

condition of Theorem 2.1.2. Since |A|=|B|, every vertex is included in the

matching.

S

N(N(S))N(S)

N(N(S))

k|N(S)| edges

SN(S) N(S)

k|S| edges

Page 25: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Stable matching (1/2) Suppose a graph G and its preference are given. For example, the following matching is unstable.

– Because choosing pair (A, M) as a matching makes both A and M happier.

• A and M might be going to break the current matching (engagement) for their preference.

A matching is called stable if it has no such pair.

Alice (A)

Bill (B)Charles (C)

David (D)

Kathy (K)

Lucy (L)Mary (M)

Nancy (N)This example was taken from a transcript of a lecture: http://www.misojiro.t.u-tokyo.ac.jp/~iwata/dmi/dmi03j.pdf

ranks of preference

A K M NB L KC L MD M N L

K B AL D B CM A C DN D A

Page 26: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Stable matching (2/2) A stable matching M is defined as follows:

– For any e =(a, b) in E – M, there exists some f M s.t• f a e or f b e,

– where f a e denotes the order of preference for edges of a.

• In the example below, (A, K) A (A, M) A (A, N).

ranks of preference

A K M NB L KC L MD M N L

K B AL D B CM A C DN D A

Alice (A)

Bill (B)Charles (C)

David (D)

Kathy (K)

Lucy (L)Mary (M)

Nancy (N)This example was taken from a transcript of a lecture: http://www.misojiro.t.u-tokyo.ac.jp/~iwata/dmi/dmi03j.pdf

Page 27: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.4 (Gale and Shapley 1962) For every set of preferences, G has a stable

matching. Its proof is based on an algorithm called the Gale-

Shapley algorithm to find a stable matching for G.– The algorithm finds a male-optimal matching.

• By interchanging a set of males and a set of females, it is also able to find a female-optimal matching.

Note that a stable matching is not unique.– There might be another stable matching having them

happier.• It depends on the definition of “happiness.”

Page 28: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Gale-Shapley algorithm Algorithm GS(G) # G=({A,B}, E)

– Mu:=A; – while Mu

• for each aMu # a is an unengaged man – Mu:= proposal(a, b) s.t. bB is highest-ranked not yet proposed to for a)

• end-for– end-while

– function proposal(a, b)• if b is engaged with someone, say, a’

– if a <b a’ then b is engaged with a; Mu:=Mu {a’} {a} – # else b keeps the engagement with a’

• else b is engaged with a; Mu:=Mu {a}

– return Mu

Page 29: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Example of results by the G-S algorithm

A K M NB L KC L MD M N L

K B AL D B CM A C DN D A

A K M NB L KC L MD M N L

K B AL D B CM A C DN D A

Each of A, B, C, and D proposed to 1st-ranked female.

C failed to find his fiance.

C proposed to the highest-rankedfemale not yet proposed to.

M changed her fiance, and D then lost his fiance.

A K M NB L KC L MD M N L

K B AL D B CM A C DN D A

D proposed to the highest-ranked female not yet

proposed to. Then, each of them has found

her/his fiance.

Page 30: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof for Theorem 2.1.4 (1/2) We will see G-S finds a stable matching by

following the transcript.– It terminates in finite steps because the number of

candidates for proposal is monotonically decreased in the while loop of the G-S algorithm.

– The matching the G-S algorithm finds is stable.• Suppose that there is an unstable pair in the result of G-S.

– The pair (a, b’), where (a, b’) a (a, b), (a, b’) b’ (a’, b).

• In the matching by G-S, (a, b) and (a’, b’) are selected.

a

a’

b

b’ a b’ ba’ b’

b a b’ a a’

Page 31: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof for Theorem 2.1.4 (2/2)– Suppose that there is an unstable pair in the result of G-S.

• The pair (a, b’), where (a, b’) A (a, b), (a, b’) b’ (a’, b’).

• In the matching by G-S, (a, b) and (a’, b’) were selected.

– By the construction of G-S, it must be that the proposed to b’ by a must be taken place before the proposal to b by a.

– This case can be occurred only when (1) or (2).• (1) b’ refused the proposal from a.

– (1) never happens because (a, b’) b’ (a’, b’), and then b also should refuse the proposal from a’.

• (2) b’ accepted the proposal from a’ by breaking the relation with a.– (2) never happens because b’ should engage with a, not a’ when a’

proposed to b.

– From these observations, any matching by G-S is always stable.

a b’ ba’ b’

b a b’ a a’

Page 32: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Corollary 2.1.5 Every regular graph G of positive even degree 2k

has a 2-factor.

Proof consists of three steps.– G contains an Euler tour.– Every vertex in G is replaced by a pair (v+, v).

• The resulting graph is k-regular bipartite graph.

• By Corollary 2.1.3, a k-regular bipartite graph has a 1-factor.

– Every pair is collapsed into a single vertex.• The 1-factor graph is turned into a 2-factor graph.

Page 33: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof of Corollary 2.1.5 (1/3) G contains an Euler tour by Theorem 1.8.1.

– Theorem 1.8.1: A connected graph is Eulerian iff every vertex has even degree.

• If G is not a connected graph, we consider each connected subgraph for the corollary.

4-regular Former and latter halves of an Euler tour

Page 34: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof of Corollary 2.1.5 (2/3) Every vertex in G is replaced by a pair (v+, v).

– Edge (vi, vi+1) by (v+i, v

i+1).

– The resulting graph is a k-regular bipartite graph.: +:

Page 35: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Proof of Corollary 2.1.5 (3/3) Every vertex in G is replaced by a pair (v+, v).

– The resulting graph is a k-regular bipartite graph.• By Corollary 2.1.3, a k-regular bipartite graph has a 1-

factor.

Every pair is collapsed into a single vertex.– The 1-factor graph is turned into a 2-factor graph.

: +

:

1-factork-regular bipartite 2-factor

Page 36: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Any Questions?

Page 37: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Theorem 2.1.1 (König 1931) (3/6) Construction of U from M

– We will construct a vertex cover U from M as follows:• Choose one end a or b from each edge ab M as follows:

• Choose b in B if some alternating path ends in the vertex.– Some edge in E– M is incident with b.

• Choose a in A otherwise.

A BA B A B

Page 38: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Any Questions?

Page 39: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Any Questions?

Page 40: Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar

Any Questions?