Algorithm Design
Algorithm Design
Algorithm Design
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
194<br />
Chapter 4 Greedy <strong>Algorithm</strong>s<br />
The Problem. Given a set of n streams, each specified by its number of<br />
bits bi and its time duration ti, as well as the link parameter r, determine<br />
whether there exists a valid schedule.<br />
Example. Suppose we have n = 3 streams, with<br />
(hi, q) = (2000, 1), (b2, t2) = (6000, 2), (b3, t3) = (2000, 1),<br />
and suppose the link’s parameter is r = 5000. Then the schedule that runs<br />
the streams in the order 1, 2, 3, is valid, since the constraint (.) is satisfied:<br />
t = 1: the whole first stream has been sent, and 2000 < 5000.1<br />
t = 2: half of the second stream has also been sent,<br />
and 2000+ 5000 5000- 2<br />
Similar calcalations hold for t = 3 and t = 4.<br />
(a) Consider the following claim:<br />
(b)<br />
Claim: There exists a valid schedule if and only if each stream i satisfies<br />
b i < rt i.<br />
Decide whether you think the claim is true or false, and give a proof<br />
of either the claim or its negation.<br />
Give an algorithm that takes a set of n streams, each specified by its<br />
number of bits bi and its time duration ti, as well as the link parameter<br />
r, and determines whether there exists a valid schedule. The rtmning<br />
time of your algorithm should be polynomial in n.<br />
A small business--say, a photocopying service with a single large<br />
machine--faces the following scheduling problem. Each morning they<br />
get a set of jobs from customers. They want to do the jobs on their single<br />
machine in an order that keeps their customers happiest. Customer i’s<br />
job will take ti time to complete. Given a schedule (i.e., an ordering of the<br />
jobs), let Ci denote the finishing time of job i. For example, if job j is the<br />
first to be donel we would have Ci = tj; and ff job j is done right after job<br />
i, we would have Ci = Q + ti. Each customer i also has a given weight wg<br />
~sents his or her importance to the business. The happiness of<br />
customer i is expected to be dependent o~ the finishing time of i’s job.<br />
So the company decides that they want to order the jobs to mJnimlze the<br />
weighted sum of the completion times, ~,n i=1 wiCi"<br />
<strong>Design</strong> an efficient algorithm to solve this problem. That is, you are<br />
given a set of n jobs with a processing time ti and a weight w~ for each<br />
job. You want to order the jobs so as to minimize the weighted sum of<br />
the completion times, ~P=I wiCi-<br />
Example. Suppose there are two jobs: the first takes time q = ! and has<br />
weight wl = !0, while the second job takes time t 2 = 3 and has weight<br />
14.<br />
Exercises<br />
w2 = 2. Then doing job 1 first would yield a weighted completion time<br />
of 10.1 + 2.4 = 18, while doing the second job first would yield the larger<br />
weighted completion time of 10.4 + 2.3 = 46.<br />
You’re working with a group of security consultants who are helping to<br />
monitor a large computer system. There’s particular interest in keeping<br />
track of processes that are labeled "sensitive." Each such process has a<br />
designated start time and finish time, and it rtms continuously between<br />
these times; the consultants have a list of the planned start and finish<br />
times of al! sensitive processes that will be run that day.<br />
As a simple first step, they’ve written a program called s~ca~;us_check<br />
that, when invoked, runs for a few seconds and records various pieces<br />
of logging information about all the sensitive processes running on the<br />
system at that moment. (We’ll model each invocation of status_check<br />
as lasting for only this single point in time.) What they’d like to do is to<br />
run status_check as few times as possible during the day, but enough<br />
that for each sensitive process P, status_check is invoked at least once<br />
during the execution of process P.<br />
(a) Give an efficient algorithm that, given the start and finish times of<br />
all the sensitive processes, finds as small a set of times as possible<br />
at which to invoke s~;a~cus_check, subject to the requirement<br />
that s~a~cus_check is invoked at least once during each sensitive<br />
process P.<br />
(b) WtKle you were designing your algorithm, the security consultants<br />
were engaging in a little back-of-the-envelope reasoning. "Suppose<br />
we can find a set of k sensitive processes with the property that no<br />
two are ever running at the same time. Then clearly your algorithm<br />
will need to invoke s~ca~;us_check at least k times: no one invocation<br />
of s~a~cus_check can handle more than one of these processes."<br />
This is true, of course, and after some further discussion, you al!<br />
begin wondering whether something stronger is true as well, a kind<br />
of converse to the above argument. Suppose that k* is the largest<br />
value of k such that one can find a set of k sensitive processes with<br />
no two ever running at the same time. Is it the ~ase that there must<br />
be a set of k* times at which you can run s~a~;us_check so that some<br />
invocation occurs during the execution of each sensitive process? (In<br />
other words, the kind of argument in the previous paragraph is really<br />
the only thing forcing you to need a lot of invocations of<br />
check.) Decide whether you think this claim is true or false, and give<br />
a proof or a counterexample.<br />
195