Algorithms IIT Delhi Tutorial 1

2
CSL356 Aug 4,5,7 TUTORIAL SHEET 1 1. Given two positive numbers a and b, use Euclid’s algorithm to find integers s, t such that s · a + t · b = GCD(a, b). Prove the correctness of your algorithm by induction. 2. (KT-Chapter 1) Decide whether the following statement is true or false: “In every instance of the stable matching problem, there is a stable matching containing a pair (m, w) such that m is ranked first in the preference list for w, and w is ranked first in the preference list of m”. 3. Give an instance of the stable matching problem for which the algorithm discussed in class takes Ω(n 2 ) time. 4. (KT-Chapter 1) Gale and Shapley published their paper on the stable marriage problem in 1962; but a version of their algorithm had already been in use for ten years by the National Resident Matching Program, for the problem of assigning medical residents to hospitals. Basically, the situation was the following. There were m hospitals, each with a certain number of available positions for hiring residents. There were n medical students graduating in a given year, each interested in joining one of the hospitals. Each hospital had a ranking of the students in order of preference, and each student had a ranking of the hospitals in order of preference. We will assume that there were more students graduating than there were slots available in the m hospitals. The interest, naturally, was in finding a way of assigning each student to at most one hospital, in such a way that all available positions in all hospitals were filled. (Since we are assuming a surplus of students, there would be some students who do not get assigned to any hospital.) We say that an assignment of students to hospitals is stable if neither of the following situations arises. – First type of instability: There are students s and s 0 , and a hospital h, so that (i) s is assigned to h, (ii) s 0 is unassigned, and (iii) h prefers s 0 to s. – Second type of instability: There are students s and s 0 , and hospitals h and h 0 , so that (i) s is assigned to h and s 0 is assigned to h 0 , (ii) h prefers s 0 to s, and s 0 prefers h to h 0 . So we basically have the stable marriage problem, except that (i) hospitals generally want more than one resident, and (ii) there is a surplus of medical students. Show that there is always a stable assignment of students to hospitals, and give an efficient algorithm to find one. The input size is θ(mn); ideally, you would like to find an algorithm with this running time. 1

description

COL351 IIT D course tutorial 1

Transcript of Algorithms IIT Delhi Tutorial 1

Page 1: Algorithms IIT Delhi Tutorial 1

CSL356 Aug 4,5,7

TUTORIAL SHEET 1

1. Given two positive numbers a and b, use Euclid’s algorithm to find integers s, t suchthat s · a+ t · b = GCD(a, b). Prove the correctness of your algorithm by induction.

2. (KT-Chapter 1) Decide whether the following statement is true or false: “In everyinstance of the stable matching problem, there is a stable matching containing a pair(m,w) such that m is ranked first in the preference list for w, and w is ranked first inthe preference list of m”.

3. Give an instance of the stable matching problem for which the algorithm discussed inclass takes Ω(n2) time.

4. (KT-Chapter 1) Gale and Shapley published their paper on the stable marriage problemin 1962; but a version of their algorithm had already been in use for ten years by theNational Resident Matching Program, for the problem of assigning medical residentsto hospitals.

Basically, the situation was the following. There were m hospitals, each with a certainnumber of available positions for hiring residents. There were n medical studentsgraduating in a given year, each interested in joining one of the hospitals. Each hospitalhad a ranking of the students in order of preference, and each student had a rankingof the hospitals in order of preference. We will assume that there were more studentsgraduating than there were slots available in the m hospitals. The interest, naturally,was in finding a way of assigning each student to at most one hospital, in such a waythat all available positions in all hospitals were filled. (Since we are assuming a surplusof students, there would be some students who do not get assigned to any hospital.)We say that an assignment of students to hospitals is stable if neither of the followingsituations arises.

– First type of instability: There are students s and s′, and a hospital h, so that(i) s is assigned to h, (ii) s′ is unassigned, and (iii) h prefers s′ to s.

– Second type of instability: There are students s and s′, and hospitals h andh′, so that (i) s is assigned to h and s′ is assigned to h′, (ii) h prefers s′ to s, ands′ prefers h to h′.

So we basically have the stable marriage problem, except that (i) hospitals generallywant more than one resident, and (ii) there is a surplus of medical students. Showthat there is always a stable assignment of students to hospitals, and give an efficientalgorithm to find one. The input size is θ(mn); ideally, you would like to find analgorithm with this running time.

1

Page 2: Algorithms IIT Delhi Tutorial 1

5. (KT-Chapter 4) Let us consider a long, quiet country road with houses scattered verysparsely along it. (We can picture the road as a long line segment, with an easternendpoint and a western endpoint.) Further, let’s suppose the residents of all thesehouses are avid cell phone users. You want to place cell phone base stations at certainpoints along the road, so that every house is within 4 kilometers of one of the basestations. Give an efficient algorithm that achieves this goal, using as few base stationsas possible. Prove the correctness of your algorithm.

6. (KT-Chapter 4) Consider the following variation on the Interval Scheduling Problemfrom lecture. You have a processor that can operate 24 hours a day, every day. Peoplesubmit requests to run daily jobs on the processor. Each such job comes with a starttime and an end time; if the job is accepted to run on the processor, it must runcontinuously, every day, for the period between its start and end times. (Note thatcertain jobs can begin before midnight and end after midnight; this makes for a typeof situation different from what we saw in the Interval Scheduling Problem.)

Given a list of n such jobs, your goal is to accept as many jobs as possible (regardlessof their length), subject to the constraint that the processor can run at most one jobat any given point in time. Provide an algorithm to do this with a running time thatis polynomial in n, the number of jobs. You may assume for simplicity that no twojobs have the same start or end times.

Example: Consider the following four jobs, specified by (start-time, end-time) pairs:(6 pm, 6 am), (9 pm, 4 am), (3 am, 2 pm), (1 pm, 7 pm). The unique solution would beto pick the two jobs (9 pm, 4 am) and (1 pm, 7 pm), which can be scheduled withoutoverlapping.

2