Algorithms IIT Delhi Tutorial 1
Algorithms IIT Delhi Tutorial 1
Algorithms IIT Delhi Tutorial 1
Aug 4,5,7
TUTORIAL SHEET 1
1. Given two positive numbers a and b, use Euclids 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 (n2 ) 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 s0 , and a hospital h, so that
(i) s is assigned to h, (ii) s0 is unassigned, and (iii) h prefers s0 to s.
Second type of instability: There are students s and s0 , and hospitals h and
h0 , so that (i) s is assigned to h and s0 is assigned to h0 , (ii) h prefers s0 to s, and
s0 prefers h to h0 .
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
5. (KT-Chapter 4) Let us consider a long, quiet country road with houses scattered very
sparsely along it. (We can picture the road as a long line segment, with an eastern
endpoint and a western endpoint.) Further, lets suppose the residents of all these
houses are avid cell phone users. You want to place cell phone base stations at certain
points along the road, so that every house is within 4 kilometers of one of the base
stations. Give an efficient algorithm that achieves this goal, using as few base stations
as possible. Prove the correctness of your algorithm.
6. (KT-Chapter 4) Consider the following variation on the Interval Scheduling Problem
from lecture. You have a processor that can operate 24 hours a day, every day. People
submit requests to run daily jobs on the processor. Each such job comes with a start
time and an end time; if the job is accepted to run on the processor, it must run
continuously, every day, for the period between its start and end times. (Note that
certain jobs can begin before midnight and end after midnight; this makes for a type
of 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 (regardless
of their length), subject to the constraint that the processor can run at most one job
at any given point in time. Provide an algorithm to do this with a running time that
is polynomial in n, the number of jobs. You may assume for simplicity that no two
jobs 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 be
to pick the two jobs (9 pm, 4 am) and (1 pm, 7 pm), which can be scheduled without
overlapping.