Tutorial Questions for COMP9007 Algorithms - 2019 Semester 1, Exercises of Algorithms and Programming

[Week 2] Tutorial 1 -- Gale Shapley Algorithm, Asymptotic Growth

Typology: Exercises

2018/2019

Uploaded on 04/20/2019

kefart
kefart 🇺🇸

4.4

(11)

55 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Tutorial questionsCOMP9007 Algorithms
2019 Semester 1 Tutorial 1
The University of Sydney
School of Computer Science
Problem 1
Consider the problem of assigning four players {A, B, C, D}to four teams {W, X, Y, Z }. Each player has
a preference for which team they want to be assigned to, and each team has a preference for which players
they take. These are listed in the preference tables below:
Player 1st 2nd 3rd 4th Team 1st 2nd 3rd 4th
A X W Z Y W B D C A
B Z Y X W X B D A C
C Y X Z W Y A B C D
D X Z W Y Z B C D A
a) Compute the stable matching determined by the Gale-Shapley algorithm for these preferences when the
Players propose to the Teams.
b) Compute the stable matching determined by the G-S algorithm when the Teams propose to the Players.
c) What, if anything, can these two answers tell us about the sets of valid partners of the players and teams?
Solution:
a) A:W,B:Z,C:Y,D:X
b) W:C,X:D,Y:A,Z:B
c) Recall that a pairing is valid if there is a stable matching where the pair are matched.
An important observation about the G-S algorithm is that proposers always end up with
their best (under their preference) valid partner and proposees always end up with their
worst valid partner. So the answer given in a) matches each team with their worst valid
player (and each player with their best valid team). Since Bis the best (valid or invalid)
partner for Z, this immediately tells us that no other partner for Zcan be valid so Z’s
set of valid partners is exactly {B}. Combining the rest of the results with the answer
for b) where each team is matched with their best valid partner tells us that:
W’s set of valid partners must lie between Aand C(inclusive), so is exactly {A, C}.
X’s set of valid partners must lie between Dand D, so it is exactly {D}.
Y’s set of valid partners must lie between Cand A, so it is a subset of {A, B, C }.
We can refine this with a bit of extra reasoning: since Bmust be matched with Z
in any stable matching, and Aand Cdo occur as partners for Y, we conclude that
Y’s set of valid partners is exactly {A, C}.
A similar argument for the players (or by observing the symmetry of the situation) yields:
A’s set of valid partners is {W,Y }.
B’s set of valid partners is {Z}.
C’s set of valid partners is {W,Y }.
D’s set of valid partners is {X}.
1
pf3

Partial preview of the text

Download Tutorial Questions for COMP9007 Algorithms - 2019 Semester 1 and more Exercises Algorithms and Programming in PDF only on Docsity!

COMP9007 Algorithms Tutorial questions 2019 Semester 1 Tutorial 1

The University of Sydney School of Computer Science

Problem 1

Consider the problem of assigning four players {A, B, C, D} to four teams {W, X, Y, Z}. Each player has a preference for which team they want to be assigned to, and each team has a preference for which players they take. These are listed in the preference tables below:

Player 1st 2nd 3rd 4th Team 1st 2nd 3rd 4th

A X W Z Y W B D C A B Z Y X W X B D A C C Y X Z W Y A B C D D X Z W Y Z B C D A

a) Compute the stable matching determined by the Gale-Shapley algorithm for these preferences when the Players propose to the Teams.

b) Compute the stable matching determined by the G-S algorithm when the Teams propose to the Players.

c) What, if anything, can these two answers tell us about the sets of valid partners of the players and teams?

Solution:

a) A:W , B:Z, C:Y , D:X

b) W :C, X:D, Y :A, Z:B

c) Recall that a pairing is valid if there is a stable matching where the pair are matched. An important observation about the G-S algorithm is that proposers always end up with their best (under their preference) valid partner and proposees always end up with their worst valid partner. So the answer given in a) matches each team with their worst valid player (and each player with their best valid team). Since B is the best (valid or invalid) partner for Z, this immediately tells us that no other partner for Z can be valid – so Z’s set of valid partners is exactly {B}. Combining the rest of the results with the answer for b) – where each team is matched with their best valid partner – tells us that:

  • W ’s set of valid partners must lie between A and C (inclusive), so is exactly {A, C}.
  • X’s set of valid partners must lie between D and D, so it is exactly {D}.
  • Y ’s set of valid partners must lie between C and A, so it is a subset of {A, B, C}. We can refine this with a bit of extra reasoning: since B must be matched with Z in any stable matching, and A and C do occur as partners for Y , we conclude that Y ’s set of valid partners is exactly {A, C}.

A similar argument for the players (or by observing the symmetry of the situation) yields:

  • A’s set of valid partners is {W, Y }.
  • B’s set of valid partners is {Z}.
  • C’s set of valid partners is {W, Y }.
  • D’s set of valid partners is {X}.

Problem 2

Sort the following functions in increasing order of asymptotic growth

n, n^3 , n log n,

n log n

n log^2 n

n,

n^3

Solution: Answer should be: √ n,

n log^2 n

n log n

, n, n log n,

n^3 , n^3

Problem 3

Sort the following function in decreasing order of asymptotic growth

n^1.^5 , 2 n,

n 2 n^

2 n n^10

, n!, 1. 5 n, 2 log^ n

Solution: Answer should be:

n!, 2 n,

2 n n^10

, 1. 5 n, n^1.^5 , 2 log^ n,

n 2 n

To compare 2

n n^10 and 1.^5

n (^) observe that 1.5 = (^24) 3 , so 1. 5 n^ = 2

n ( 43 )n^

. Since an exponential grows faster than any polynomial (as mentioned in the lecture slides), we have that 2

n n^10 is asymptotically faster than 1. 5 n.

Problem 4

Which of the following is largest asymptotically

log 3 n, log 2 n, log 10 n

Solution: They are all equal. This is because:

logb a =

logd a logd b

Problem 5 Prove that the sum S(n) of the first n natural numbers is n(n + 1)/2.

Solution: Proof is by induction on n. Base case: If n = 1 then the claim is trivially true. Induction hypothesis: Assume that the sum of the first n natural is n(n + 1)/2. Induction step: Next we want to prove the statement for n+1. From the definition of S(n) we know S(n+1) = S(n)+n+1, and from the induction hypothesis we know S(n) = n(n+1)/2, and therefore S(n + 1) = S(n) + n + 1 = n(n + 1)/2 + n + 1 = (n + 2)(n + 1)/2.