

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
[Week 2] Tutorial 1 -- Gale Shapley Algorithm, Asymptotic Growth
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!


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:
A similar argument for the players (or by observing the symmetry of the situation) yields:
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.