Gale-Shapley Algorithm: Stable Matching and Running Time Analysis, Assignments of Algorithms and Programming

Solutions to problem 1 using the gale-shapley algorithm for different proposing orders between males and females, and includes an algorithm and argument for problem 2 to find two integers a, b such that a/b = v. The document also analyzes the running time of the given algorithm and compares it with a faster algorithm after sorting the array a.

Typology: Assignments

2019/2020

Uploaded on 04/25/2020

yuhao-wu
yuhao-wu 🇦🇺

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Problem 1
a) Compute the stable matching determined by Gale-Shapley algorithm for these
preferences when the Males propose to the Females.
Answer: A-W, B-V, C-X, D-Y, E-Z
b) Compute the stable matching determined by Gale-Shapley algorithm for these
preferences when the Females propose to the Males.
Answer: V-B, W-A, X-C, Y-D, Z-E
Problem 2
a) Describe an algorithm that solves the problem and give a brief argument as to why
your algorithm is correct.
Algorithm:
for (X in A){ loop every value in array A, store in variable X
for (Y in A){ loop every value in array A, store in variable Y
if (Y/X =V) test Y divided by X , if the result equal V
print X,Y print out X,Y , the printed results are two integers a, b
}
}
Argument:
For example:
Assume array A=[1,3,7,6],v=2;
when I loop X as 3 and loop Y as 6,
the result of Y divider by X is 2(equal to v)
so, 3,6 is the integers a,b.
b) Analyse the running time of your algorithm.
assume the amount of value in array A is nrunning time
inner for-loop is performed n times
outer for-loop is performed n times
Total 𝑇(𝑛)= 𝑂(𝑛 𝑛)= 𝑂(𝑛2)
pf2

Partial preview of the text

Download Gale-Shapley Algorithm: Stable Matching and Running Time Analysis and more Assignments Algorithms and Programming in PDF only on Docsity!

Problem 1

a) Compute the stable matching determined by Gale-Shapley algorithm for these

preferences when the Males propose to the Females.

Answer: A-W, B-V, C-X, D-Y, E-Z

b) Compute the stable matching determined by Gale-Shapley algorithm for these

preferences when the Females propose to the Males.

Answer: V-B, W-A, X-C, Y-D, Z-E

Problem 2

a) Describe an algorithm that solves the problem and give a brief argument as to why

your algorithm is correct.

Algorithm:

for (X in A){ loop every value in array A, store in variable X

for (Y in A){ loop every value in array A, store in variable Y

if (Y/X =V) test Y divided by X , if the result equal V

print X,Y print out X,Y , the printed results are two integers a, b

Argument:

For example:

Assume array A=[1,3,7,6],v=2;

when I loop X as 3 and loop Y as 6,

the result of Y divider by X is 2(equal to v)

so, 3,6 is the integers a,b.

b) Analyse the running time of your algorithm.

assume the amount of value in array A is n,running time:

 inner for-loop is performed n times

 outer for-loop is performed n times

 Total 𝑇

2

c) Suppose we sort A as our first step in the algorithm, does this allow for a faster

algorithm? If so, give this algorithm and analyse its running time. If not, explain why

( 1 )if sort A as first step, and use divide-and-conquer algorithm:

Step: explain:

Sort(A) sort array A, ascending from lift to right

for ( X in A){ loop the value of array A, store in X variable

for ( Y in the median of the rest array A) use divide-and-conquer algorithm to search Y

if (Y/X<v)

the rest array A = the value of the rest array A over than median

elseif (Y/X>v)

the rest array A= the value of the rest array A less than median

elseif(Y/X==v)

print out (X,Y) the printed results are two integers a, b

( 2 )Assume the amount of value in array A is n,running time:

 outer for-loop is performed n times

 inner for-loop is performed :

assume total looping time is 𝑘, each times the number to search is:

𝑛

2

𝑛

4

𝑛

2

𝑘

and

𝑛

2

𝑘

= 1 ,so 𝑘 = log 𝑛

 Total 𝑇(𝑛) = 𝑂(𝑛 ∗ log 𝑛) = 𝑂(𝑛 log 𝑛)

( 3 )compare with the algorithm in a):

𝑂(𝑛 log 𝑛) < 𝑂(𝑛

2

So, “sort A as our first step” is a faster algorithm and can reduce running time.