Docsity

NP-Completeness and Undecidability: Subset Sum Problem and Halting Problem, Study notes of Algorithms and Programming

Partial preview of the text

Download NP-Completeness and Undecidability: Subset Sum Problem and Halting Problem and more Study notes Algorithms and Programming in PDF only on Docsity!

Design and analysis of algorithms

Lecture 36 & 37

Edyta Szyma ´

nska

[email protected]

CS3510 A, Fall 2005 – p. 1/

Subset sum - numerical problem

Given a sequence of integers

a

,... , a 1

and a parametern

k,

decide whether there is a subset of integers whose sum isexactly

k

CS3510 A, Fall 2005 – p. 2/

Subset sum - numerical problem

Given a sequence of integers

a

,... , a 1

and a parametern

k,

decide whether there is a subset of integers whose sum isexactly

k

Formally, does there exist a subset

I^

1 ,... , n

}^

such that

∑ i∈I

ai

k

CS3510 A, Fall 2005 – p. 2/

Subset sum - numerical problem

Given a sequence of integers

a

,... , a 1

and a parametern

k,

decide whether there is a subset of integers whose sum isexactly

k

Formally, does there exist a subset

I^

1 ,... , n

}^

such that

∑ i∈I

ai

k

Theorem

Subset Sum is

NP-complete.

CS3510 A, Fall 2005 – p. 2/

From Vertex Cover to Subset Sum

Idea of the reduction:

Start from a graph

G

and a parameter

k.

Create a set of integers and a parameter

k

Prove that

G

has vertex cover of size

k

if and only if

there is a subset of the integers that sum to

k

′.^ CS3510 A, Fall 2005 – p. 3/

From Vertex Cover to Subset Sum

Let

G

be given with

V

2 ,... , n

}^

and some

k.

CS3510 A, Fall 2005 – p. 4/

From Vertex Cover to Subset Sum

Defining the integers:

CS3510 A, Fall 2005 – p. 5/

From Vertex Cover to Subset Sum

Defining the integers:

create a matrix with

n

m

rows corresponding to all

ai

’s and

bij

’s and

m

columns, corresponding to

bij

’s

plus one extra column

X

in

X

put a 1 for all

a

’s and a 0 otherwisei

in column

(ij

)^ put a 1 for

a

, ai

andj

bij

and 0 elsewhere.

define

k

′^ :=

k

·^

m 4

m

−^1 ∑ i=

i 4

CS3510 A, Fall 2005 – p. 5/

From Vertex Cover to Subset Sum

CS3510 A, Fall 2005 – p. 6/

From Vertex Cover to Subset Sum

CS3510 A, Fall 2005 – p. 6/

From Vertex Cover to Subset Sum

1 ′^ k

·^4

∑ i=

i^4

X^

CS3510 A, Fall 2005 – p. 6/

From Vertex Cover to Subset Sum

1 ′^ k

·^4

∑ i=

i^4

X^

CS3510 A, Fall 2005 – p. 6/

Reduction - correctness

From Covers to Subsets:

Suppose

vertex cover

C,

|C

|^ =

k.

Choose

a

’s andi

′ b ij

s^

as described.

When we sum up these integers (in base 4), then wehave a 2 in all digits except for column

X.

Then we

have a 1 in

X k

times.

Thus the sum is

k

CS3510 A, Fall 2005 – p. 7/

Reduction - correctness

From Subsets to Covers:

CS3510 A, Fall 2005 – p. 8/