Docsity

Practice Questions for Exam - Algorithm Design | ECS 122A, Study notes of Computer Science

Toggle sidebar
bg1
ECS122A Handout June 2, 2009
How to prove a problem is NP-complete?
Example 1. The directed Hamilton cycle (HC) problem is known to be NP-complete. In the following, we
show that the directed HC problem is reducible to the undirected Hamilton cycle problem.
Therefore, we conclude that the undirected HC problem is also NP-complete.
Proof: Let G= (V, E) be a directed graph with nvertices. Gis transformed into the undirected
graph G′= (V′, E′) by the transform function Tdefined as the following:
v∈V−→ v1, v2, v3∈V′and (v1, v 2),(v2, v3)∈E′.
and
(u, v)∈E−→ (u3, v1)∈E′.
Clearly, Tis polynomial-time computable.
We now show that
Ghas a HC ⇐⇒ G′has a HC.
•“=⇒”: Suppose that Ghas a directed HC, v1, v2,...,vn, v1. Then
v1
1, v2
1, v3
1, v1
2, v2
2, v3
2,...,v1
n, v2
n, v3
n, v1
1
is an undirected HC for G′.
•“⇐=”: Suppose that G′has an undirected HC, the three vertices, say v1, v2, v3that correspond
to one vertex from Gmust be traversed consecutively in the order v1, v 2, v3or v3, v2, v1, since v2
cannot be reached from any other vertex in G′. Since the other edges in G′connect vertices with
superscripts 1 or 3, if for any one triple the order of the superscripts is 1, 2, 3, then the order is
1, 2, 3 for all triples. Otherwise, it is 3, 2, 1 for all triples. Since G′is undirected, we may assume
that its Hamilton cycle is
v1
i1, v2
i1, v3
i1, v1
i2, v2
i2, v3
i2,...,v1
in, v2
in, v3
in, v1
i1, v2
i1, v3
i1.
Then vi1, vi2,...,vin, vi1is a directed Hamilton cycle for G.2
1
pf2

Partial preview of the text

Download Practice Questions for Exam - Algorithm Design | ECS 122A and more Study notes Computer Science in PDF only on Docsity!

ECS122A Handout June 2, 2009

How to prove a problem is NP-complete?

Example 1. The directed Hamilton cycle (HC) problem is known to be NP-complete. In the following, we show that the directed HC problem is reducible to the undirected Hamilton cycle problem. Therefore, we conclude that the undirected HC problem is also NP-complete.

Proof: Let G = (V, E) be a directed graph with n vertices. G is transformed into the undirected graph G′^ = (V ′, E′) by the transform function T defined as the following:

v ∈ V −→ v^1 , v^2 , v^3 ∈ V ′^ and (v^1 , v^2 ), (v^2 , v^3 ) ∈ E′.

and (u, v) ∈ E −→ (u^3 , v^1 ) ∈ E′.

Clearly, T is polynomial-time computable. We now show that G has a HC ⇐⇒ G′^ has a HC.

  • “=⇒”: Suppose that G has a directed HC, v 1 , v 2 ,... , vn, v 1. Then

v^11 , v 12 , v^31 , v^12 , v^22 , v 23 ,... , v^1 n, v^2 n, v n^3 , v 11

is an undirected HC for G′.

  • “⇐=”: Suppose that G′^ has an undirected HC, the three vertices, say v^1 , v^2 , v^3 that correspond to one vertex from G must be traversed consecutively in the order v^1 , v^2 , v^3 or v^3 , v^2 , v^1 , since v^2 cannot be reached from any other vertex in G′. Since the other edges in G′^ connect vertices with superscripts 1 or 3, if for any one triple the order of the superscripts is 1, 2, 3, then the order is 1, 2, 3 for all triples. Otherwise, it is 3, 2, 1 for all triples. Since G′^ is undirected, we may assume that its Hamilton cycle is

v^1 i 1 , v^2 i 1 , v i^31 , v i^12 , v^2 i 2 , v i^32 ,... , v^1 in , v i^2 n , v^3 in , v i^11 , v^2 i 1 , v^3 i 1.

Then vi 1 , vi 2 ,... , vin , vi 1 is a directed Hamilton cycle for G. 2

Example 2: The subset sum problem is known to be NP-complete, In the following, we show that the subset sum problem is reducible to the job scheduling (with penalties) problem. Therefore, we conclude that the problem of job scheduling with penalties is also NP-complete.

Proof ∑ : Let s 1 , s 2 ,... , sn and C be an input for the subset sum problem (we may assume that n i=1 si^ ≥^ C). Let the input be transformed into the following input for the job scheduling problem

ti = pi = si for 1 ≤ i ≤ n, di = C for 1 ≤ i ≤ n,

k =

∑^ n i=

si − C.

Clearly the transformation takes polynomial time. Now we shows that Yes-instance of the subset sum ⇐⇒ Yes-instance of the job scheduling.

  • “=⇒”: suppose that the subset sum input produces a YES answer; i.e., there is a subset J of N = { 1 , 2 ,... , n} such that

∑ i∈J si^ =^ C. Then let^ π^ be any permutation of^ N^ that causes all jobs with indices in J to be done before any job with indices in N − J. The first |J| jobs are completed by their deadline since ∑ i∈J ti^ =^

∑ i∈J si^ =^ C^ and^ C^ is the deadline for all jobs. Then the total penalty

Pπ =

∑^ |J|

j=

pπ(j) +

∑^ n

j=|J|+

pπ(j) = 0 +

∑^ n

j=|J|+

pπ(j) =

∑^ n

j=|J|+

sπ(j) =

∑^ n

j=

sj − C = k.

Thus the jobs can be done with total penalty ≤ k.

  • “⇐=” Let π be any schedule for the jobs with total penalty ≤ k. Let m be largest such that ∑^ m

i=

tπ(i) ≤ C; (1)

i.e., m is the number of jobs completed by the deadline C. The penalty, then, is

∑^ n

i=m+

pπ(i) ≤ k =

∑^ n

i=

si − C. (2)

Since ti = pi = si for all 1 ≤ i ≤ n, we must have

∑^ m

i=

tπ(i) +

∑^ n

i=m+

pπ(i) =

∑^ m

i=

sπ(i) +

∑^ n

i=m+

sπ(i) =

∑^ n

i=

si,

and this can happen only if the inequalities in (1) and (2) are equalities. Thus

∑^ m i=

tπ(i) = C,

so the objects with indices π(1), π(2),... , π(m) are a solution to the subset sum problem. 2