You are on page 1of 5

Algorithms: CSE 202 — Final Examination

March 2015

Maximum points: 40 + 7 make-up points

Due March 15th, 2016. 11:00 AM. Submit the solutions at CSE 4246. No late submissions.
No electronic submissions.

Instructions:

1. Solve exactly four problems so that for 1 ≤ i ≤ 4 you select exactly one of the two problems
numbered 2i − 1 and 2i. The first two problems carry 11 points each and all other problems
carry 12 points each.

2. Although this exam is an open book exam, you are only allowed to consult the following
standard textbooks or course lecture notes. You should not consult the Web.

(a) Introduction to Algorithms (Cormen, Leiserson, Rivest, Stein)


(b) Algorithm Design by Kleinberg and Tardos
(c) Algorithms by Dasgupta, Papadimitriou and Vazirani

3. This test is designed to give you an opportunity to demonstrate your understanding of the
principles of algorithm design, analysis and application. Consequently, you are required to
work by yourself in answering the questions. Group work or consultation with others is not
allowed. You can check with the instructor or the TA for any clarification.

4. Each problem requires that you achieve an algorithm with certain complexity (for example,
polynomial time, linear time, etc.). To the extent the problem permits latitude in terms of
complexity (for example, polynomial time provides considerable latitude), obtain the most
efficient algorithm.

5. Guidelines for writing a solution:

(a) Write your solutions neatly. Proofread them before you submit.
(b) Write a high-level description of your algorithm. State the main ideas and strategies used
in developing your algorithm. Include all important details.
(c) Write your algorithm using a high-level pseudo language providing important imple-
mentation details. If you are using a modified version of a well-known algorithm, show
clearly what your modifications are. If you are using a well-known algorithm without
any modifications, it is enough to specify how you plan to apply the algorithm.

1
(d) Provide a detailed proof of correctness.
(e) Analyze the time complexity of your algorithm.
(f) Quality of the high-level description of your algorithm, its correctness and efficiency are
the prime determinants of your grade.

6. Well-written solutions will be rewarded. Characteristics of good solutions: correct solution,


logical coherence, an appropriate balance between completeness and succinctness, and an
orderly presentation of ideas. Excessively long solutions will be penalized.

Problem 1: Subset sum (KT 11.3)


Suppose you are given a set of positive integers A = {a1 , a2 , . . . , an } and a positive integer B. A
subset S ⊆ A is called feasible if the sum of the numbers in S does not exceed B:
X
ai ≤ B
ai ∈S

The sum of the numbers in S will be called the total sum of S.


You would like to select a feasible subset S of A whose total sum is as large as possible.
Example. If A = {8, 2, 4} and B = 11, then the optimal solution is the subset S = {8, 2}.

(a) Here is an algorithm for this problem.


Algorithm 1: A “Naive” greedy algorithm
Initially S = ∅
Define T = 0
for i = 1, 2, ..., n do
if T + ai ≤ B then
S ← S ∪ {ai }
T ← T + ai
end if
end for
Give an instance in which the total sum of the set S returned by this algorithm is less than half
the total sum of some other feasible subset of A.

(b) Give a polynomial-time approximation algorithm for this problem with the following guarantee:
It returns a feasible set S ⊆ A whose total sum is at least half as large as the maximum total
sum of any feasible set S 0 ⊆ A. Your algorithm should have a running time of at most O(n log n).
Less efficient algorithms will get partial credit.
Provide a clear description of your algorithm, analyze its time complexity, argue that it returns
a feasible set, and prove its performance guarantee.

Problem 2: Approximating the independent set


The independent set problem: given an undirected graph, find the largest independent set S of
vertices, i.e., a set so that no adjacent vertices u and v are both in S.

1. Give a linear programming relaxation for the independent set problem.

2
2. Give a polynomial time algorithm that, given a graph G with n vertices, either finds an
independent set of size at least n/3 or certifies that no independent set in G has size greater
than 2n/3. (It may involve using an algorithm for linear programming.)
Provide a clear description of your algorithm, analyze its time complexity, and argue that it
either returns an independent set of size at least n/3 or concludes that there is no independent
set of size greater than 2n/3.

3. Consider the special case of graphs of at most degree 3. Find α > 1/3 and a polynomial time
algorithm that either finds an independent set of size αn or certifies that no independent set
has size (1 − α)n. Obtain as good an α as you can.
Provide a clear description of your algorithm, analyze its time complexity, determine α, and
argue that your algorithm either returns an independent set of size at least αn or concludes
that there is no independent set of size greater than (1 − α)n.

Problem 3: Warehouse problem


There are two warehouses V and W from which widgets are to be shipped to destinations Di ,
1 ≤ i ≤ n. Let di ≥ 1 be the demand at Di , for
P 1 ≤ i ≤ n, and rV , rW be the number of widgets
available at V and W , respectively. Let d¯ = ni=1 di denote total demand of all the destinations.
Assume that there are enough widgets available to fill the demand, that is,

rV + rW = d¯
Let vi be the cost of shipping a widget from warehouse V to destination Di , and wi be the cost
of shipping a widget from warehouse W to destination Di , for 1 ≤ i ≤ n. The warehouse problem is
the problem of finding xi , yi ∈ N for 1 ≤ i ≤ n such that when xi widgets are sent from V to Di
and yi widgets are sent from W to Di :

• the demand at Di is satisfied, that is , xi + yi = di ,

• the inventory at V is sufficient, ni=1 xi = rV ,


P

• the inventory at W is sufficient, ni=1 yi = rW ,


P

and the total cost of shipping the widgets,


n
X
(vi xi + wi yi )
i=1
is minimized.
Use dynamic programming to design an O(d¯2 ) algorithm. Provide a clear description of your
dynamic programming definitions and recursive formulations. Make sure that your definitions and
recursive formulations deal with the determination of xi and yi for each destination as well as the
minimum total cost. Prove the correctness of your algorithm.
Present pseudocode to implement your algorithm and analyze its time complexity.
You will get partial credit if you present an algorithm whose complexity is worse than d¯2 .

Problem 4: Always Non-negative Path


Let G be an n-node directed graph whose edge weights are either -1 or 1. A path (not necessarily

3
simple) e1 , . . . , et in G is always non−negative if the sum of the weights of e1 up to ei is non-negative
for all 1 ≤ i ≤ t. A source s and a destination s0 are given as inputs. Give an algorithm to decide
whether there is an always non-negative path from s to s0 .
Use dynamic programming to design an O(nm) algorithm where m is number of edges in
the graph. Provide a clear description of your dynamic programming definitions and recursive
formulations. Make sure that your definitions and recursive formulations deal with the determination
of the desired path as well as its existence. Prove the correctness of your algorithm.
Present pseudocode to implement your algorithm and analyze its time complexity.
You will get partial credit if you present an algorithm whose complexity is worse than nm.
Note: A path in a graph is simple if it does not repeat vertices.

Problem 5: Electronic message transmission systems


Consider the problem of selecting sites for an electronic message transmission system. Any number
of sites can be chosen from a finite set of potential locations. We know the cost ci of establishing
site i and the revenue rij generated between sites i and j, if they are both selected. Both the costs
and revenues are non-negative. Find an efficient algorithm to determine the subset of vertices such
that the sum of the edge revenues less the vertex costs is as large as possible.
Design an efficient polynomial-time algorithm.
Provide a high-level description of your algorithm, prove its correctness, and analyze its time
complexity.

Problem 6: Driving Schedule


Some of your friends with jobs out West decide they really need some extra time each day to sit
in front of their laptops, and the morning commute from Woodside to Palo Alto seems likely the
only option. So they decided to carpool to work.
Unfortunately, they all hate to drive, so they want to make sure that any carpool management
they agree upon is fair and does not overload any individual with too much driving. Some sort of
simple round-robin scheme is out, because none of them goes to work every day, and so the subset
of them in the car varies from day to day.
Here is one way to define fairness. Let the people be labeled S = {p1 , . . . , pk }. We say that the
total driving obligation of pj over a set of days is the expected number of times that pj would have
driven, had a driver been chosen uniformly at random from among the people going to work each
day. More concretely, suppose the carpool plan lasts for d days, and on the i-th day a subset Si ⊆ S
of the people go to P work. Then the above definition of the total driving obligation ∆j for pj can
be written as ∆j = i:pj ∈Si |S1i | . Ideally, we would like to require that pj drives at most ∆j times.
However, ∆j may not be an integer.
So let us say that a driving schedule is a choice of a driver for each day, that is, a sequence
pi1 , . . . , pid with pit ∈ St and that a fair driving schedule is one in which each pj is chosen as the
driver on at most d∆j e days.

1. Prove that for any sequence of sets S1 , . . . , Sd , there exists a fair driving schedule.

2. Give an algorithm to compute a fair driving schedule with running time in polynomial in k
and d.

Design an efficient polynomial-time algorithm.

4
Provide a high-level description of your algorithm, prove its correctness, and analyze its time
complexity.

Problem 7: IPO
Consider the following problem. You are designing the business plan for a start-up company. You
have identified n possible projects for your company, and for each project, i, you have calculated
the minimum capital you need to start the project, Ri > 0, and the profit you will get after you
complete the project, Pi > 0. Profit is the net revenue obtained after subtracting the capital used
for carrying out the project. You also know your initial capital C0 > 0. You want to perform at
most k, 1 ≤ k ≤ n, projects before the IPO and want to maximize your total capital at the IPO.
Your company cannot perform the same project twice.
0
In other words, you want to pick a list of up to k distinct Ph=jprojects, i1 , · · · , ik with k ≤ k.
0

Your accumulated capital after project ij will be Cj = C0 + h=1 Pih . The sequence must satisfy
the constraint that you have sufficient capital to start ij+1 after completing the first j jobs, i.e.,
Cj ≥ Rij+1 for each j = 0, · · · , k 0 − 1. You want to maximize the final amount of capital, Ck0 .
Design an efficient algorithm. There is an O(n log n) algorithm for this problem. Less efficient
algorithms will get partial credit.
Provide a clear high-level description of your algorithm, write pseudo-code, argue correctness
and analyze time complexity.

Problem 8: Scheduling variations


Consider the following problem of scheduling unit-time tasks with deadlines and penalties on a
single processor. There are n jobs, each of which takes a unit time to complete. If job i is completed
before time di , then it incurs no penalty. Otherwise, it incurs a penalty pi . Design an efficient
algorithm to schedule all the jobs on a single processor so as to minimize the total penalty. Assume
that the processor is available at time 0. Also assume that all deadlines are non-negative.
Design an efficient algorithm. There is an O(n log n) algorithm for this problem. Less efficient
algorithms will get partial credit.
Provide a clear high-level description of your algorithm, write pseudo-code, argue correctness
and analyze time complexity.

You might also like