Lecture 1
Logistics & Stable Matching
CSE 421 Autumn 2026
1
Course Logistics
2
Instructor
Andrea Coladangelo (you can call me Andrea)
Research focus: Quantum information
Office: Gates 212
Office Hours: Wednesday 4.30pm, Gates 371
3
TAs
4
Day 1 checklist
5
How to succeed in this class
6
Designing algorithms is almost like an art: you cannot learn this skill by just listening to lectures or reading a textbook. You have to spend time trying.
Coursework
7
Late submissions
8
Exams and grading scheme
9
Textbook
10
Goals & structure
11
The two main goals:
High-level course structure:
Properties of an algorithm
What should we be optimizing for?
12
Today
13
Stable Matching
14
The matching problem
15
The matching problem
16
We will simplify and consider: hospitals, residents
The matching problem, more formally
17
A matching is an assignment of each resident to one hospital (and viceversa).
What does it mean for a matching to be stable?
We say that an unmatched pair is unstable if both and prefer each other to their current match.
The matching problem, more formally
18
A matching is an assignment of each resident to one hospital (and viceversa).
What does it mean for a matching to be stable?
We say that an unmatched pair is unstable if both and prefer each other to their current match.
We say that a matching is stable if it contains no unstable pair.
Why stability? It’s a desirable condition: no side-deals are incentivized.
Questions
19
Does a stable matching always exist?
Can we find a stable matching efficiently?
We’ll explore these two questions in the rest of this lecture, and the next.
Turns out the answer is yes.
Turns out the answer is yes.
Key idea: “propose and reject”
Gale-Shapley algorithm (1962)
Gale-Shapley algorithm (1962)
Initially all in and in are free
while there is a free
Let be highest on s list that has not proposed to yet
if is free
match
else // is not free
Let be the current match of .
if prefers to
unmatch
match
Questions:
1. Does the algorithm terminate (if so, what’s the running time?)
2. Does it find a stable matching?
Let and be the sets of hospitals and residents respectively.
Gale-Shapley: example walkthrough
Gale-Shapley: analysis
(This is where we prove that the algorithm has the desired properties)
Questions:
1. Does the algorithm terminate (if so, what’s the running time?)
2. Does it find a stable matching?
We’ll start with Question 1. We’ll answer/analyze Question 2 in the next lecture.
Gale-Shapley: proof of termination
Claim 1: if some has proposed to the last resident on their list,�then all residents are matched.
Proof: Notice that once a resident is matched, they remain matched forever.
Claim 2: The algorithm terminates after proposals.
Proof: Since we never repeat a proposal, and each hospital has a list of length , it takes at most proposals until the first hospital has proposed to the last resident on its list.
Since proposes to residents in order of preference, when proposes to the last resident on its list, it must have proposed to every other resident already. So, every other resident is already matched (and the last resident is free).
Gale-Shapley: proof of termination
Claim 1: if some has proposed to the last resident on their list,�then all residents are matched.
Proof: Notice that once a resident is matched, they remain matched forever.
Claim 2: The algorithm terminates after proposals.
Proof: Since we never repeat a proposal, and each hospital has a list of length , it takes at most proposals until the first hospital has proposed to the last resident on its list.
At that point, by Claim 1, all other residents are matched. So this last proposal will be accepted, and everyone will be matched.
Since proposes to residents in order of preference, when proposes to the last resident on its list, it must have proposed to every other resident already. So, every other resident is already matched (and the last resident is free).
Gale-Shapley: proof of termination
How does one come up with this proof?
There isn’t a recipe.. but one thing that helps:
Gale-Shapley: wrapping up runtime
We have shown that the algorithm takes at most proposals to terminate.
But how long does each proposal take to run?
For each proposal, we might need to do a comparison: check whether a resident prefers or . How long does a comparison take?
If we do things naively, we have to go through the resident’s preference list until we encounter or . This could take time , which would result in an overall runtime for the entire algorithm.
Is there a better way?
Yes, the idea is to start by pre-computing a table of “inverses”.
Gale-Shapley: wrapping up runtime
Key idea to implement comparisons efficiently: start by pre-computing a table of “inverses”.
Inv[i][j] answers the question: “resident , what rank is hospital in your list?”
Crucially, we compute this table once at the beginning, and after this each comparison only takes time .
How long does it take to compute the table of inverses?
This only takes time (you should convince yourself of this)
So, overall running time = (pre-computation time) + (#proposals)(comparison time)
=
Measuring efficiency: The word-RAM model
For this course, we will assume we are working in the word-RAM model (unless specified otherwise):
The history of the propose and reject algorithm
Gale and Shapley 1962
31
Shapley winning the 2012 Economics Nobel Prize (with Roth)