CS 70 Discrete Mathematics and Probability Theory
HW 2
Sundry
Before you start your homework, write down your team. Who else did you work with on this
homework? List names and email addresses. (In case of homework party, you can also just describe
the group.) How did you work on this homework? Working in groups of 3-5 will earn credit for
your "Sundry" grade.
Please copy the following statement and sign next to it:
I certify that all solutions are entirely in my words and that I have not looked at another student’s
solutions. I have credited all external sources in this write up.
1 Induction
Prove the following identity for all positive integers n and k.
n
∑
j=1
j(j +1)(j +2)···(j +k −1) = n(n+1)(n+2)···(n+k)
k +1
2 Finite Number of Solutions
Prove that for every positive integer k, the following is true:
For every real number r 0, there are only finitely many solutions in positive integers
to
1
n1
+···+
1
nk
= r.
In other words, there exists some number m (that depends on k and r) such that there are at most
m ways of choosing a positive integer n1, and a (possibly different) positive integer n2, etc., that
satisfy the equation.
CS 70, Fall 2017, HW 2 1
3 Induction with Two Directions
Pacman is walking on an infinite 2D grid. He starts at some location (i, j) ∈ N
2
in the first quadrant,
and is constrained to stay in the first quadrant (say, by walls along the x and y axes). Every second
he does one of the following (if possible):
(i) Walk one inch down, to (i, j −1).
(ii) Walk one inch left, to (i−1, j).
For example, if he is at (5,0), his only option is to walk left to (4,0).
Prove that no matter how he walks, he will always reach (0,0) in finite time.
4 Stable Marriage
Consider a set of four men and four women with the following preferences:
men preferences women preferences
A 1234 1 DABC
B 1324 2 ABCD
C 1324 3 ABCD
D 3124 4 ABDC
(a) Run on this instance the stable matching algorithm presented in class. Show each stage of the
algorithm, and give the resulting matching, expressed as {(M,W),...}.
(b) We know that there can be no more than n
2
stages of the algorithm, because at least one woman
is deleted from at least one list at each stage. Can you construct an instance with n men and n
women so that at least n
2/2 stages are required?
(c) Suppose we relax the rules for the men, so that each unpaired man proposes to the next woman
on his list at a time of his choice (some men might procrastinate for several days, while others
might propose and get rejected several times in a single day). Can the order of the proposals
change the resulting pairing? Give an example of such a change or prove that the pairing that
results is the same.
5 The Better Stable Matching
In this problem we examine a simple way to merge two different solutions to a stable marriage
problem. Let R, R
0 be two distinct stable matchings. Define the new matching R∧R
0
as follows:
For every man m, m’s date in R∧R
0
is whichever is better (according to m’s preference
list) of his dates in R and R
0
.
CS 70, Fall 2017, HW 2 2
Also, we will say that a man/woman prefers a matching R to a matching R
0
if he/she prefers his/her
date in R to his/her date in R
0
. We will use the following example:
men preferences women preferences
A 1234 1 DCBA
B 2143 2 CDAB
C 3412 3 BADC
D 4321 4 ABDC
(a) R = {(A,4),(B,3),(C,1),(D,2)} and R
0 = {(A,3),(B,4),(C,2),(D,1)} are stable matchings
for the example given above. Calculate R∧R
0
and show that it is also stable.
(b) Prove that, for any matchings R, R
0
, no man prefers R or R
0
to R∧R
0
.
(c) Prove that, for any stable matchings R, R
0 where m and w are dates in R but not in R
0
, one of
the following holds:
• m prefers R to R
0
and w prefers R
0
to R; or
• m prefers R
0
to R and w prefers R to R
0
.
[Hint: Let M and W denote the sets of mens and women respectively that prefer R to R
0
, and M0
and W0
the sets of men and women that prefer R
0
to R. Note that |M|+|M0
| = |W|+|W0
|. (Why
is this?) Show that |M| ≤ |W0
| and that |M0
| ≤ |W|. Deduce that |M0
| = |W| and |M| = |W0
|.
The claim should now follow quite easily.]
(You may assume this result in subsequent parts even if you don’t prove it here.)
(d) Prove an interesting result: for any stable matchings R, R
0
, (i) R∧R
0
is a matching [Hint: use
the results from (c)], and (ii) it is also stable.
6 Stable Matching for Classes!
Let’s consider the system for getting into classes. We are given n students and m discussion sections. Each discussion section u has some number, qu of seats, and we assume that the total number
of students is larger than the total number of seats (i.e. ∑
m
u=1
qu < n). Each student ranks the m
discussion sections in order of preference, and the instructor for each discussion ranks the n students. Our goal is to find an assignment of students to seats (one student per seat) that is stable in
the following sense:
• There is no student-section pair (s,u) such that s prefers u to her allocated discussion section
and the instructor for u prefers s to one of the students assigned to u. (This is like the stability
criterion for Stable Marriage: it says there is no student-section pair that would like to change
the assignment.)
• There is no discussion section u for which the instructor prefers some unassigned student s
to one of the students assigned to u. (This extends the stability criterion to take account of
the fact that some students are not assigned to discussions.)
CS 70, Fall 2017, HW 2 3
Note that this problem is almost the same as the Stable Marriage Problem, with two differences:
(i) there are more students than seats; and (ii) each discussion section can have more than one seat.
(a) Explain how to modify the propose-and-reject algorithm so that it finds a stable assignment of
students to seats. [Hint: What roles of students/instructors will be in the propose-and-reject
algorithm? What does "women have men on a string" mean in this setting?]
(b) State a version of the Improvement Lemma (see Lecture Note 4) that applies to your algorithm,
and prove that it holds.
(c) Use your Improvement Lemma to give a proof that your algorithm terminates, that every seat
is filled, and that the assignment your algorithm returns is stable.
CS 70, Fall 2017, HW 2 4