1 / 22

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

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)?

carolos
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation 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 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 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 j 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.

  3. Backtracking if t(n, W) is not true then print “ no such partition” and stop; i=n; w=W; if ( t(n, W)== false) then stop; While (i> 0 ) do { if (t(i, w) == true) { if (t(i-1, W)== true) then i=i-1; else { W=W-s(ai); i=i-1; print “ai”} } }

  4. 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.)

  5. 0-1 version

  6. RNA Sequence: ACCGGUAGU

  7. Exercise: Let T be a rooted binary tree, where each internal node in the tree has two children and every node (except the root) in T has a parent. Each leaf in the tree is assigned a letter in ={A, C, G, T}. Figure 1 gives an example. Consider an edge e in T. Assume that every end of e is assigned a letter. The cost of e is 0 if the two letters are identical and the cost is 1 if the two letters are not identical. The problem here is to assign a letter in  to each internal node of T such that the cost of the tree is minimized, where the cost of the tree is the total cost of all edges in the tree. Design a polynomial-time dynamic programming algorithm to solve the problem.

  8. A A C Figure 1 A

  9. Assignment 4. (Due on May 2, 2007. Drop it in Mail Box 59) This time, Helena and I can explain the questions, but we will NOT tell you how to solve the problems. Question 1. Give a polynomial time algorithm to find the longest monotonically increasing subsequence of a sequence of n numbers. (Assume that each integer appears once in the input sequence of n numbers) Example: Consider sequence 1,8, 2,9, 3,10, 4, 5. Both subsequences 1, 2, 3, 4, 5 and 1, 8, 9, 10 are monotonically increasing subsequences. However, 1,2,3, 4, 5 is the longest.

  10. Assignment 4. (Due on May 2, 2007) • Question 2. Given an integer d and a sequence of integers s=s1s2…sn. Design a polynomial time algorithm to find the longest monotonically increasing subsequence of s such that the difference between any two consecutive numbers in the subsequence is at least d. • Example: Consider the input sequence 1,7,8, 2,9, 3,10, 4, 5. The subsequence 1, 2, 3, 4, 5 is a monotonically increasing subsequence such that the difference between any two consecutive numbers in the subsequence is at least 1. • 1, 3, 5 is a monotonically increasing subsequence such that the difference between any two consecutive numbers in the subsequence is at least 2.

  11. Assignment 4. (Due on May 2, 2007) Question 3. Suppose that there are n sequences s1, s2, …, snon alphabet ={a1, a2, …, am }. 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?

More Related