Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 a  A. 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 i  n 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: T(i,j)=true if and only if t(i-1, j)=true or t(i-1, j-s(a i ))=true.

2 2 Example i012345678910111213 1TTFFFFFFFFFFFF 2TTFFFFFFFTTFFF 3TTFFFTTFFTTFFF 4TTFTTTTFTTTFTT 5TTFTTTTFTTTTTT Figure 4.8 Table of t(i,j) for the instance of PARTITION for which A={a 1,a 2,a 3,a 4,a 5 }, s(a 1 )=1, s(a 2 )=9, s(a 3 )=5, s(a 4 )=3, and s(a 5 )=8. The answer for this instance is "yes", since t(5,13)=T, reflecting the fact that s(a 1 )+s(a 2 )+s(a 4 )=13=26/2. j

3 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(a i )=2 n =10000…0. (binary number of n+1 bits, n 0’s). So B is at least O(2 n ). The input size is O(n) if there some a i with S(a i )=2 n. 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 4 0-1 version

5 5

6 6

7 7

8 8

9 9

10 10

11 11

12 12

13 13

14 14

15 15 Exercise: Suppose that there are n sequences s 1, s 2, …, s n on alphabet  ={1, 2, …, m }. Every sequence s i is of length m and every letter in  appears exactly once in each s i. Design a polynomial time algorithm to compute the LCS of the n sequences. What is the time complexity of your algorithm?


Download ppt "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."

Similar presentations


Ads by Google