1 pseudo-polynomial time algorithm (the concept and the terminology are important) partition...

15
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1 , a 2 , …, a n } and a size s(a) (integer) for each aA. Question: Is there a subset A’A such that a A’ s(a) = a A –A’ s(a)? Theorem: Partition problem is NP-complete (Karp, 1972). An dynamic algorithm: For in and j 0.5 a A s(a) , define t(i, j) to be true if and only if there is a subset A i of {a 1 , a 2 , …, a i } such that a Ai s(a)=j. Formula:

Post on 19-Dec-2015

216 views

Category:

Documents


3 download

TRANSCRIPT

1

Pseudo-polynomial time algorithm(The concept and the terminology are important)

Partition Problem:

Input: Finite set A=(a1, a2, …, an} and a size s(a) (integer) for each aA.

Question: Is there a subset A’A such that

a A’ s(a) = a A –A’ s(a)?

Theorem: Partition problem is NP-complete (Karp, 1972).

An dynamic algorithm:

For in and j 0.5 a A s(a) , define t(i, j) to be true

if and only if there is a subset Ai of {a1, a2, …, ai} such that

a Ai s(a)=j.

Formula:

T(i,j)=true if and only if t(i-1, j)=true or t(i-1, j-s(ai))=true.

2

Example

i 0 1 2 3 4 5 6 7 8 9 10 11 12 13

1 T T F F F F F F F F F F F F

2 T T F F F F F F F T T F F F

3 T T F F F T T F F T T F F F

4 T T F T T T T F T T T F T T

5 T T F T T T T F T T T T T T

Figure 4.8 Table of t(i,j) for the instance of PARTITION for which A={a1,a2,a3,a4,a5}, s(a1)=1, s(a2)=9, s(a3)=5, s(a4)=3, and s(a5)=8. The answer for this instance is "yes", since t(5,13)=T, reflecting the fact that s(a1)+s(a2)+s(a4)=13=26/2.

j

3

Time complexity

• The algorithm takes at most O(nB) time to fill in the table. (Each cell needs constant time to compute).•Do we have a polynomial time algorithm to solve the Partition Problem and thus all NP-complete problems?

–No.–O(nb) is not polynomial in terms of the input size.

S(ai)=2n=10000…0 . (binary number of n+1 bits , n 0’s).

So B is at least O(2n). The input size is O(n) if there some ai with S(ai)=2n. B is not polynomial in terms of n (input size) in general.However, if any upper bound is imposed on B, (e.g., B is Polynomial), the problem can be solved in polynomial time for this special case.(This is called pseudo-polynomial.)

4

0-1 version

5

6

7

8

9

10

11

12

13

14

15

• Exercise: Suppose that there are n sequences s1, s2, …, sn on alphabet ={1, 2, …, m }. Every sequence si is of length m and every letter in appears exactly once in each si.

• Design a polynomial time algorithm to compute the LCS of the n sequences. What is the time complexity of your algorithm?