1 of 34

CSE 421 Section 1

Stable Matching

2 of 34

Administrivia & Introductions

3 of 34

Homework

  • Submissions
    • LaTeX (highly encouraged)
      • overleaf.com
      • template and LaTeX guide posted on course website!
    • Word Editor that supports mathematical equations
    • Handwritten (not preferred, but fine as long as clear)
  • All homeworks will be turned in via Gradescope
  • Homeworks due on Thursdays at 11.59pm

  • You get 6 late days for the quarter, and can use a maximum of 3 on any HW

4 of 34

Announcements & Reminders

  • Section Materials
    • Handouts will be provided in at each section
    • Worksheets and sample solutions will be available on the class website later this evening

  • HW1
    • Due Thursday 10/2 at 11.59pm

5 of 34

Stable Matching

6 of 34

Stable Matching

  •  

7 of 34

Gale-Shapley Algorithm

Algorithm to find a stable matching:

Initially all 𝑟 in 𝑅 and in 𝐻 are free

while there is a free 𝑟

Let be highest on 𝑟’s list that 𝑟 has not proposed to

if is free

match (𝑟,ℎ)

else // is not free

Let 𝑟′ be the current match of

if prefers 𝑟 to 𝑟′

unmatch (𝑟′,ℎ)

match (𝑟,ℎ)

8 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

Consider the following stable matching instance:

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

9 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

10 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

11 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

12 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

13 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r2 chooses h1 (r1, h3), (r2, h1), (r3, h2)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

14 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r2 chooses h1 (r1, h3), (r2, h1), (r3, h2)

r4 chooses h3 (r1, h3), (r2, h1), (r3, h2), (r4, h3)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

15 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r2 chooses h1 (r1, h3), (r2, h1), (r3, h2)

r4 chooses h3 (r1, h3), (r2, h1), (r3, h2), (r4, h3)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

16 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r2 chooses h1 (r1, h3), (r2, h1), (r3, h2)

r4 chooses h3 (r1, h3), (r2, h1), (r3, h2), (r4, h3)

r4 chooses h4 (r1, h3), (r2, h1), (r3, h2), (r4, h4)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

17 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the instance above. When choosing which free rider to propose next, always choose the one with the smallest index (e.g., if r1 and r2 are both free, always choose r1).

r1 chooses h3 (r1, h3)

r2 chooses h2 (r1, h3), (r2, h2)

r3 chooses h2 (r1, h3), (r2, h2), (r3, h2)

r2 chooses h1 (r1, h3), (r2, h1), (r3, h2)

r4 chooses h3 (r1, h3), (r2, h1), (r3, h2), (r4, h3)

r4 chooses h4 (r1, h3), (r2, h1), (r3, h2), (r4, h4)

(r1, h3), (r2, h1), (r3, h2), (r4, h4)

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

18 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the same instance. But now, when choosing which free rider to propose next, always choose the one with the largest index. Do you get the same result?
  1. Now run the algorithm with horses proposing, breaking ties by taking the free horse with the smallest index. Do you get the same result?

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

Work on parts b and c of this problem with the people around you, and then we’ll go over it together!

19 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the same instance. But now, when choosing which free rider to propose next, always choose the one with the largest index. Do you get the same result?

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

20 of 34

Problem 1 – Gale-Shapley

  1. Run the Gale-Shapley Algorithm with riders proposing on the same instance. But now, when choosing which free rider to propose next, always choose the one with the largest index. Do you get the same result?

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

The steps of the Gale-Shapley Algorithm with the rider with highest index proposing first:

r4 chooses h3 (r4, h3)

r3 chooses h2 (r3, h2),(r4, h3)

r2 chooses h2 (r3, h2),(r4, h3)

r2 chooses h1 (r2, h1),(r3, h2),(r4, h3)

r1 chooses h3 (r1, h3),(r2, h1),(r3, h2)

r4 chooses h4 (r1, h3),(r2, h1),(r3, h2),(r4, h4)

We ended up with the same result!

21 of 34

Problem 1 – Gale-Shapley

  1. Now run the algorithm with horses proposing, breaking ties by taking the free horse with the smallest index. Do you get the same result?

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

22 of 34

Problem 1 – Gale-Shapley

  1. Now run the algorithm with horses proposing, breaking ties by taking the free horse with the smallest index. Do you get the same result?

r1: h3, h1, h2, h4

r2: h2, h1, h4, h3

r3: h2, h3, h1, h4

r4: h3, h4, h1, h2

h1: r4, r1, r3, r2

h2: r1, r3, r2, r4

h3: r1, r3, r4, r2

h4: r3, r1, r2, r4

The steps of the Gale-Shapley Algorithm with horses proposing:

h1 chooses r4 (r4, h1)

h2 chooses r1 (r1, h2),(r4, h1)

h3 chooses r1 (r1, h3),(r4, h1)

h2 chooses r3 (r1, h3),(r3, h2),(r4, h1)

h4 chooses r3 (r1, h3),(r3, h2),(r4, h1)

h4 chooses r1 (r1, h3),(r3, h2),(r4, h1)

h4 chooses r2 (r1, h3),(r2, h4),(r3, h2),(r4, h1)

No, the result is different when we have the horses propose as opposed to the riders.

23 of 34

Induction

24 of 34

Induction

  • You will be writing lots of induction proofs in this class in order to prove that your algorithms are correct.

  • The style requirements for proofs in this class are less stringent than the style requirements from 311
    • there is a style guide doc on the course website (here) about how 421 proofs are different than what you did in 311

25 of 34

Induction Template

  •  

26 of 34

Problem 3 – Induction Review

  •  

27 of 34

Problem 3 – Induction Review

  •  

Work on this problem with the people around you, and then we’ll go over it together!

28 of 34

Problem 3 – Induction Review

  •  

29 of 34

Problem 3 – Induction Review

  •  

 

30 of 34

KEY Induction Concept

  •  

31 of 34

Problem 3 – Induction Review

  •  

Work on this problem with the people around you, and then we’ll go over it together!

32 of 34

Problem 3 – Induction Review

  1. Prove the claim by induction.

 

33 of 34

Problem 3 – Induction Review

  1. Prove the claim by induction.

 

34 of 34

That’s All, Folks!

Thanks for coming to section this week!

Any questions?