CMPSCI 311: Theory of Algorithms
First Midterm Exam
David Mix Barrington
5 October 2006
- Answer the problems on the exam pages.
- There are seven problems for 100 total points.
Actual scale was A = 85, C = 55.
- No books, notes, calculators, or collaboration.
- The exam had a time limit of 120 minutes, though it was
not intended that you would need all the time.
- Questions 1, 2, and 3 are
"true/false with explanation" -- you get five points
for a correct boolean answer, and up to five additional points for a convincing
Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 20 points
Q5: 15 points
Q6: 15 points
Q7: 20 points
Total: 100 points
- Questions 1 and 2 concern the weighted interval scheduling
problem. Here the input is a set of n jobs, each with a start time
, finish time, and reward. Our task is to schedule some
of these jobs on a single machine. The output is a non-overlapping
subset of the jobs, and the goal is to maximize the total reward
from the jobs in the set.
- Question 1 (10):
True or false with justification: The following greedy algorithm
always gets the maximum possible reward: Sort the jobs by reward and schedule
them one by one starting with the highest reward, rejecting any that overlap
with jobs already scheduled.
- Question 2 (10):
True or false with justification: Now assume that the reward of each
job is proportional to its length. The following greedy algorithm
always maximizes the total reward: First schedule the job that starts earliest,
then keep scheduling the earliest-starting job that does not overlap with jobs
- Question 3 (15):
True or false with justification: Suppose that in the Huffman algorithm
to create an optimal prefix code, there is one letter of the alphabet that has
a frequency probability of 0.5 or greater. Then that letter will definitely
be assigned a one-bit code word.
- Question 4 (20):
Let G = (V,E) be a connected, undirected graph where each edge has a positive
weight and let X be a non-empty proper subset of V (a set of vertices that is
not equal to either ∅ or to V). Consider the set Z of edges that have
one endpoint in X and one not in X, and let e be an edge in Z that has smaller
weight than any other edge in Z. What does the Cut Property say
about e and minimum spanning trees for G? Prove that this Cut Property is true.
- Question 5 (15):
Let G = (V,E) be a connected undirected graph and let v be a vertex in G.
Let T by the depth-first search tree of G starting from v, and let U be the
breadth-first search tree of G starting from v. Prove that the depth of T is
at least as great as the depth of U.
- Question 6 (15):
Recall that an independent set of an undirected graph G is a set X of
vertices such that no edge of G has both endpoints in X. Describe an algorithm
that takes G and a number k as input, and finds an independent set of size k
in G if one exists. Let n be the number of vertices in G. Analyze the big-O
running time of your algorithm as a function of both n and k -- for full credit
your algorithm should take O(nkk2) time.
- Question 7 (20):
Here we have a scheduling problem slightly different from the others we have
seen. Each job has a length and a preferred finish time, and
we must schedule all the jobs on a single machine without overlapping.
(There is a single start time at which all the jobs become available
at once.) If we complete a job before the preferred time, we get a reward
equal to the time we have saved. If we complete it after the preferred time,
we pay a penalty equal to the amount of time that we are late. Our total
reward (which we want to maximize) is the sum of all rewards for early
completion minus the sum of all penalties for late completion.
Argue carefully that there is an optimal schedule that has no idle time
(actually, we want to argue that every optimal schedule has no idle time). That
is, every optimal schedule always has one job start at the same time the
previous job finishes. (Hint: Show how to change any schedule with idle time
to another schedule that has no idle time and gets at least more reward.)
Consider the greedy algorithm where we sort the jobs by length and
schedule them in that order, shortest job first, with no idle time. Prove that
this achieves a net reward at least as great as that of any schedule. (Note:
In lecture we proved that a different greedy algorithm is optimal for
a different goal, that of minimizing the maximum lateness. You cannot
simply quote that result because it does not apply to this algorithm or to these
rewards and penalties. But a similar exchange argument will work in
this new case.
Last modified 9 October 2006