Stable Matching

Problem

Input: A set of hospitals and a set of students

  • Each hospital ranks students
  • Each student ranks hospitals

Definition (Matching)

A matching is a set of ordered pairs with and

  • Each hospital appears in at most one pair of
  • Each student appears in at most one pair of

A matching is perfect if

A matching is stable if it is a perfect matching with no unstable pairs

Definition (Unstable Pair)

Hospital and student form an unstable pair if both

  • prefers to one of its admitted students
  • prefers to assigned hospital

Note: Unstable pairs are the pair that the hospital and student would prefer. That means when a matching has unstable pairs, the actual unstable pairs are just associated with the matching, not actually in the matching.

Goal: Find a stable matching (if one exists)

Gale-Shapley Algorithm

One algorithm to find a stable matching

Algorithm

Hospitals propose to their top ranked student. Students accept if the proposing hospital is ranked higher than their existing accepted proposal and rejects their previously accepted proposal. If student rejects a proposal, hospital moves down their ranking.

M = empty matching
while some hopspital h is unmatched and hasn't proposed to every student
	s = first student on h's list to whom h has not yet proposed
	if s is unmatched
		add h-s matchig to M
	else if s prefers h to current partner h'
		replace h'-s with h-s in matching M
	else
		s rejects h
return stable matching M

Observations

  1. Hospitals propose to students in decreasing order of preference
  2. Once a student is matched, the student never becomes unmatched, only trades up

Properties

Claim

Gale-Shapley terminates after at most iterations of while loop

Proof: Each time through the while loop, a hospital proposes to a new student. There are students and hospitals, so possible proposals.

Claim

Gale-Shapley always outputs a matching

Proof: Hospitals propose only if unmatched. So every hospital is matched to at most 1 student.

Students keep only the best hospital. So every student is matched to a most 1 hospital.

Claim

In Gale-Shapley matching, all hospitals are matched.

Proof: Assume by way of contradiction, some hospital is unmatched upon termination. Then some student, say is unmatched upon termination. By observation 2, was never proposed to. But, proposes to every student, since ends up unmatched ↯

Claim

In Gale-Shapley matching, all students are matched.

Proof: By previous claim, all hospitals get matched. Thus, by counting, all students get matched.

Claim

In Gale-Shapley matching , there are no unstable pairs

Proof: Consider any pair Case 1: never proposed to prefers is current partner to Case 2: proposed to rejected (either right away or later) prefers current partner to is not an unstable pair of

Theorem (Gale-Shapley 1962)

The Gale-Shapely algorithm guarantees to find a stable matching for any problem instance

Proof: Follows from the above claims

Favoring the Proposer

Definition (Valid Partner)

Student is a valid partner for hospital if there exists any stable matching in which and are matched

Definition (Hospital-optimal Assignment)

Matching where each hospital receives its best valid partner

Definition (Student-pessimal Assignment)

Matching where each student receives its worst valid partner

Claim

Gale-Shapley matching is hospital-optimal

Intuition: If a student swaps, then the matching before that swap would have been unstable. Hospitals make proposals based on their preference, so each pair ends up being the best valid partner for the hospital.

Proof:

  • Assume by way of contradiction that a hospital is matched with a student other than the best valid partner.
  • Hospitals propose in decreasing order of preference, so some hospital is rejected by a valid partner during Gale-Shapley.
  • Let be the first such hospital that is rejected by a valid partner, and let be the first valid partner that rejects .
  • Let be a stable matching where and are matched.
  • When rejects in Gale-Shapely, forms (or re-affirms) commitment to a hospital, say . Hence, prefers to because students only trade up.
  • Let be partner of in
  • Because this is the first rejection by a valid partner, had not been rejected by any valid partner (including ) at the point when is rejected by .
  • Thus, had not yet proposed to when proposed to . So prefers to
  • Thus is a unstable pair in , a contradiction.
  • Hence, every hospital is matched with its best valid partner.

Corollary

Any hospital-optimal assignment is a stable matching

Theorem

Gale-Shapley finds student-pessimal stable matching

Proof: Suppose by way of contradiction that matched in but is not the worst valid partner for .

There exists stable matching in which is paired with a hospital, say , whom prefers less than , so prefers to .

Let be the partner of in .

By hospital-optimality, is the best valid partner for . So prefers to . Thus, is an unstable pair in , a contradiction.