CS 301
Design and Analysis of Algorithms
Exercise Set 8
Due: 26/10/2007
Exercises
Marking scheme: First, an answer to each question is evaluated for raw 10 marks. Then it is converted to a
binary marks per question - 1 if raw marks is ≥ 5, 0 otherwise. Finally, the binary grades for all questions are
added. The sum is again converted to final 0/1 score (i.e. 1 if the sum is no less than the half of the number of
questions, 0 otherwise). The distribution of 10 raw marks per question is given with the answer.
1. Solve exercise 34.5-6. Showing that HP is in NP should be straightforward. To show that
HP is NP-hard there are 3 possibilities:
(a) Reduce from Hamiltonian cycle which we have already proved to be NP-complete.
(b) Modify the proof of HC being NP-hard so that it applies to HP.
(c) Use the generalized notion of reducibility described in the last homework, if you find
that more convenient.
Solution: Here we assume that the HP problem does not have start and end vertices as input. The
following can be easily adapted for these inputs.
We show all the three possibilities. However, any one would fetch marks.
(a) We show a direct mapping from an instance G = (V, E) of HC to an instance G0 = (V 0 , E 0 ) of HP.
V 0 contains all vertices of V except an arbitrary u which is replaced by u1 , u2 , u3 , u4 . E 0 contains
the edges (u1 , u2 ), (u3 , u4 ), for all v such that (u, v) ∈ E, (u2 , v) and (u3 , v) and the rest of the
edge of E. See figure 1a.
Figure 1: Construction of G0 from G
v1
v1
u2
v2
v2
u
v3
u1
v3
···
···
vk
vk
u3
u4
G0
G
Clearly this construction runs in polynomial time.
1
Suppose there is a HC in G. Let the circuit enter to u from vi and exit through vj and comes
back to vi . Then the path u1 , u2 , vj , ..., vi , u4 , u3 is an HP in G0 . Thus G0 has answer YES if G has
answer YES. On the other hand, if there is a HP u1 , u2 , vj , . . . , vi , u4 , u3 in G0 then vi , u, vj , . . . , vi
is a HC in G0 . This completes the reduction.
(b) The proof of VC ≤P HC done in class and HC ≤P HP above can be merged to give a direct
proof of VC ≤P HP. The same number of widgets and their interconnections are used. Only
difference is that instead of using k additional vertices, we use k + 3 additional vertices. The
vertices s1 , . . . , sk+1 are interconnected as done previously for s1 , . . . , sk . In addition, there are
two more edges (s1 , sk+2 ) and (sk+1 , sk+3 ). The rest can be proved following the previous two
proofs.
(c) We prove using the third method to show that HC polynomially reduces to HP. Suppose we are
given a polynomial time algorithm for HP. Then we construct the following algorithm for HC.
HC(G)
Let (V,E)=G
for every (u,v) in E
G’=(V U {u’,v’}, E U {(u,u’), (v,v’)})
if HP(G’) return true;
end
return false
It should not be difficult to show the correctness. If G0 has HP, it must have u0 , v 0 as end points.
Then G has HC obtained by replacing the end edges with (u, v). The algorithm HP(G0 ) is called
atmost O(|E|) times. Hence, by generalized notion of polynomial reducibility HC ≤P HP.
2. CLRS 34-4 (scheduling with profits and deadlines).
Solution:
(a) {2 marks} The decision problem DPDTJS is as follows:
Input:
•
•
•
•
p[1..n] : profits if meets deadline
d[1..n] : deadlines
t[1..n] : processing times
K : Integer
Output: Does there exist a scheduling of the tasks that completes all the tasks and returns profit
at least K such that no two tasks run simultaneously?
(b) {4 marks} Showing that DPDTJS is in NP is straightforward. For an instance x = (p[1..n], d[1..n], t[1..n]),
given a schedule y = (s[1..n]), where task i is scheduled at time s[i], one can easily verify if they
are non overlapping and the profit is at least K. This verifier F (x, y) runs in time O(n2 ).
We reduce SS to DPTDJS. Given an instance X = (x[1..n], t) we construct an instance Y =
(x[1..n], d[1..n], x[1..n], t), ∀i d[i] = t of DPTJS. This construction takes time O(n).
Suppose, there is a subset of elements of X such that the sum is exactly t, then there is a
corresponding schedule of Y . On thePother hand, if there is a schedule in Y then, the for the
subset
P S of tasks which met deadline, i∈SPxi ≤ t (condition of the last task in S meets deadline)
and i∈S xi ≥ t (profit constraint). Hence, i∈S xi = t. Thus X has answer YES.
(c) {2 marks} Use the solution to part 2d to compute the optimum profit Popt of scheduling and return
accordingly.
(d) {2 marks} This is very similar to the problem 3 of HW5. The same dynamic programming solution
can be used with the following recurrence.
M P (t + T [i], i + 1) + P [i] if (t + T [i] ≤ D[i]) ∧ (i < n)
M P (t, i) = max
M P (t, i + 1)
if (i < n)
with base cases M P (t, n) = 0 if t + T [n] ≤ D[n], D[n] otherwise. Since processing time is limited
to n. Dmax = O(n2 ) and hence time complexity is O(n3 ).
2
3. The input to the bin-packing problem is a sequence of object weights x[1..n], a bin capacity
C, and a target number k of bins. The question whether the objects can be placed in the
bins so that the capacity of no bin is exceeded, and at most k bins are used.
Show that this is NP-complete.
Solution:
BP is in NP
Let x = (x1 , . . . , xn , C, k) be an instance of BP. Given a k-partition y = (S1 , . . . , Sk ) of S = {x1 , . . . , xn },
one can easily verify if the sum of elements of Si does not exceed C for all i. This verifier F (x, y) runs
in polynomial in n.
BP is NP-Hard
We prove that SS ≤P BP. However, instead of giving a direct reduction, we prove that PP ≤P BP.
Combining this with the reduction SS ≤P PP proved in the tutorial on 16/10/2007 gives us the required
proof.
PP ≤P BP
Let x = (x1 , . . . , xn ) be an instance of PP. We construct the instance y = (x1 , . . . , xn , t =
of BP. Clearly this construction runs in polynomial in n.
1
2
Pn
i=1
xi , 2)
Suppose answer to x is YES. Then there exists a subset of elements of x such that the sum is exactly t.
Packing this subset to bin 1 and rest in bin 2 gives YES answer to y. Similarly if y has YES answer then
the set of elements packed in bin 1 (or bin 2) gives YES answer to x.
Thus we proved PP ≤P BP.
3
© Copyright 2026 Paperzz