You are on page 1of 2

*CSE 591 Foundations of Algorithms*

Mid Term, Spring 2016


Closed Books, Closed Notes
Time: 50 minutes
Each question carries 10 pts.
Problem 1: Suppose there is a set A of men and a set B of women. Each set contain n
elements. There exist two n n arrays P and Q such that P (i, j) is the preference of man i
for woman j and Q is the preference of woman i for man j . Give an algorithm which finds a
pairing of men and women such that the following condition is not satisfied.
There is an element ai A that has a higher preference for an element bk B over the element
bj B with which ai is paired, and bk B has a higher preference for ai A over the element
al A with which bk is paired.
Prove the correctness of your algorithm (i.e., it ensures that the given condition isnt satisfied).
Problem 2: The activity selection problem (ASP) is described as follows: Suppose we have a
set A = {a1 , . . . , an } of n proposed activities that wish to use a resource, such as lecture hall,
which can be used by only one activity at a time. Each activity i has a start time si and a finish
time fi , where si fi , . If selected, activity i takes place during the half-open time interval [si ,
fi ). Activities i and j are compatible if the intervals [si , fi ) and [sj , fj ) do not overlap (i.e.,
i and j are compatible if si fj or sj fi . In one version of the activity selection problem
the objective is to select a largest set of mutually compatible activities. In a second version of
the problem the objective is to find the smallest number of resources (lecture halls) needed to
schedule all the activities.
Suppose the following algorithm is used to solve the second version of the ASP problem.
Assume that the activities are ordered by monotonically increasing start times s1 s2
s3 . . . sn . If not, we can sort them into this order in time O(n lg n), breaking ties arbitrarily.
Suppose the following algorithm is used to solve the second version of the ASP problem. The
algorithm loops between two phases until all the activities are scheduled. In phase I, a set of
compatible activities are identified using the Algorithm Activity Selection (AAS). In phase II,
this set of compatible activities is assigned to a resource (e.g., a lecture hall). The algorithm removes this set of activities from further consideration and among the remaining set of activities,
finds another set of compatible activities using AAS. The process continues till all the activities
are assigned to a resource.

Algorithm Activity Selection (AAS)


begin
n |A| where A = {a1 , . . . , an };
CA {a1 };
i 1;
for j := 2 to n do
if sj fi then
begin
CA CA {aj }
i j;

end
return CA
end
Algorithm Resource Allocation
begin
A = {a1 , . . . , an }; (A is the set of activities)
R := 0; (R is the number of resources used)
do until (A = )
begin
Using Algorithm Activity Selection, find a set of compatible activities CA;
Assign a resource to this set of compatible activities and increment R (R := R + 1);
A := A CA
end
return R
end
Question: Is this algorithm always going to find a smallest number of resources in which all
the activities can be scheduled? If your answer is yes then prove it by providing arguments
in support of your answer. If your answer is no then provide an instance of the problem,
where the algorithm fails to find a smallest number of resources in which all the activities can
be scheduled.

You might also like