Is this a correct understanding of proving something is NP Complete? - algorithm

As I understand it there are two steps to proving that a problem is NP complete:
Give an algorithm that can verify a solution to the problem in polynomial time. That is, an algorithm whose input is a proposed solution to the problem and whose output is either "yes" or "no" based on whether the input is a valid solution to the problem.
Prove the problem is NP hard - eg, assume you have an oracle that can compute another known NP complete problem in one step. Using that, write an algorithm that solves this problem in polynomial time.
For example, suppose we want to prove that the following problem is NP Complete:
Given a set of integers, S, is it possible to isolate a subset of elements, S', such that the sum of the elements in S' is exactly equal to the sum of the remaining elements in S that are not included in S'?
Step 1: Verification algorithm
Verify_HalfSubset(Set S, Solution sol):
accum = 0
for each element i in sol:
accum+=i
linear search for an element with the same value as i in S.
if found, delete it from s, if not found, return false
end for
accum2 = 0
for each element i in S:
accum2+=i
end for
if accum==accum2 return true, else return false
Clearly this runs in polynomial time: The first for loop runs in O(nm) and the second runs in O(n).
Step 2: Reduction
Assume we have an oracle O(Set S, int I) that computes the subset sum problem in a single step (that is, is there a subset of elements in S that sum up to I)?
Then, we can write a polynomial time algorithm that computes our half-subset problem:
HalfSubset(Set S):
accum = 0
for each s in S:
accum+=S
end for
if(accum%2==1)
// this question forbids "splitting" values to non-integral parts
return NO_ANSWER
end if
half1 = O(S, accum/2)
if(half1 == NO_ANSWER)
return NO_ANSWER
end if
for each i in half1:
linear search for an element with the same value as half1[i] in S
delete it from S.
end for
half2 = S
return (half1 and half2)
Can someone please tell me if I've made any mistakes in this process? This is the one question on my final exam review that I'm not entirely sure I understand completely.

The second portion of your answer is a bit off. What you are saying in step two is that you can reduce this problem to a known NP-complete problem in polynomial time. That is, you are saying that this problem is at most as hard as the NP-complete problem.
What you want to say is that the NP-complete problem can be reduced to your example problem in polynomial time. This would show that, if you could solve this problem in polynomial time, then you could also solve the NP-complete problem in polynomial time, proving that your example problem is NP-complete.

No, this is incorrect. You could set up a situation where you use the NP-Complete oracle to solve the problem, yet still have the problem itself be in P.
What you have to do is show that you can reduce another NP-Complete problem to your problem. That is, provide a polynomial-time algorithm to transform any instance of a particular NP-Complete problem to an instance of your problem such that a solution of your (transformed) problem is also a solution to the given NP-Complete problem. This shows that if you can solve your problem, then you can also solve any NP-Complete problem, meaning your problem is at least as hard as any other NP-Complete problem.

Related

Subset sum decision problem -- how to verify "false" case in polynomial time?

I'm having a bit of trouble understanding how one would verify if there is no solution to a given instance of the subset sum problem in polynomial time.
Of course you could easily verify the positive case: simply provide the list of integers which add up to the target sum and check they are all in the original set. (O(N))
How do you verify that the answer "false" is the correct one in polynomial time?
It’s actually not known how to do this - and indeed it’s conjectured that it’s not possible to do so!
The class NP consists of problems where “yes” instances can be verified in polynomial time. The subset sum problem is a canonical example of a problem in NP. Importantly, notice that the definition of NP says nothing about what happens if the answer is “no” - maybe it’ll be easy to show this, or maybe there isn’t an efficient algorithm for doing so.
A counterpart to NP is the class co-NP, which consists of problems where “no” instances can be verified in polynomial time. A canonical example of such a problem is the tautology problem - given a propositional logic formula, is it always true regardless of what values the variables are given? If the formula isn’t a tautology, it’s easy to verify this by having someone tell you how to assign the values to the variables such that the formula is false. But if the formula is always true, it’s unclear how you’d show this efficiently.
Just as the P = NP problem hasn’t been solved, the NP = co-NP problem is also open. We don’t know whether problems where “yes” answers have fast verification are the same as problems where “no” answers have fast verification.
What we do know is that if any NP-complete problem is in co-NP, then NP = co-NP. And since subset sum is NP-complete, there’s no known polynomial time algorithm to verify if the answer to a subset sum instance is “no.”

The problem complexity of the Maximum Coverage problem with set size constraint (P or NP)

The classic Maximum Coverage (MC) problem is an NP-hard optimization problem. Consider d elements U = {e1, e2, ... ed} and c sets T1, T2 ... Tc. Each set contains some elements in U. The problem aims to find at most b sets, such that the cardinality of the union of these sets is maximized.
For example, T1={e1, e3}, T2={e1, e2, e3} and T3={e3, e4}. When b=2, the optimal solution picks T2 and T3.
I am considering a variation of the classic MC problem, which imposes a set size constraint. Consider 1 < k <= d, if the size of all sets is bounded by k. Call this problem k-MC. Is the problem still NP-hard?
My conjecture is that k-MC is still NP-hard, but I am struggling to come up with a polynomial reduction from a proven NP-hard problem, like MC.
For an arbitrary instance of Maximum coverage, if I could find a polynomial reduction to my problem for all k>1, I can conclude that my problem is also NP-hard.
Here is what I got so far:
When k=d, the problem is trivially equivalent to the classic Maximum Coverage.
When k=d-1, we look at the given MC instance and see if there exist a set with size d. If there is, simply pick that. Otherwise, it reduces to the k-MC problem with k=d-1.
When k is less than d-1, I resort to dynamic programming to complete the reduction. However, this yields a non-polynomial time reduction, which defeat the purpose of reduction from a NP-hard problem.
If anyone could give me some pointers on how I should tackle this problem, or even just make an educated guess on the problem complexity of k-MC (P or NP), I'd really appreciate it.
2-MC is easy -- interpret the sets of size 2 as a graph and run your favorite matching algorithm for non-bipartite graphs. Once you exceed the matching cardinality, you're stuck picking singletons.
3-MC is hard. You can encode an instance of 3-partition as 3-MC by taking the sets to be the triples that sum to the target, then decide if it's solvable by checking coverage for b = n/3.

Is finding a subset with exact cut with other given subsets NP-hard?

I am trying to figure out whether the following problem is NP-hard:
Given G_1,..,G_n subsets of {1..m}
c_1,..,c_n non-negative integers in {0..m}
Find T subset of {1..m}
S.T. for all i=1..n, T intersects G_i in exactly c_i elements
I tried to find reductions to NP problems such as coloring, or P problems such as matching, but on both cases could think of exponential conversion algorithm (i.e. one that takes into account all subsets of G_i of size c_i), which doesn't help me much :(
A side note: would any restrictions on the parameters make this problem much easier?
For instance, would m<< n make a computational difference (we would still be looking for an algorithm that is polynomial in m)?
What if we knew that some of the constants c_i were zero?
Would appreciate any insight :)
This is NP-Complete problem, and is a generalization of Hitting Set Problem. Proof of NP-Completeness follows.
The problem is in NP (trivial - given a solution T, it is easy to check the intersection with each of Gi, and verify if its size is Ci).
It is also NP-Complete, assuming you are looking for minimal such T, with reduction from Exact Hitting Set Problem:
Where the decision problem of exact hitting set is:
Given a universe of elements U, subsets S1,...,Sk, and a number
m - is there a subset S of U of size at most m that contains
exactly one element from each Si?
Given instance of hitting-set problem (S1,S2,...Sk,d) - reduce it to this problem with Gi=Si, ci = 1, if the minimal solution of this problem is of size d, there is also a solution to exact hitting set of size d (and vise versa).

Polynomial-time reduction between languages(of problems) in NP and languages(of problems) in P

hello I am having difficulties to understand the topic of P,NP and Polynomial-time reduction.
I have tried to search it on web and ask some of my friends , but i havent got any good answer .
I wish to ask a general question about this topic :
let A,B be languages ( or set of problems ) in P
let C,D be languages in NP
which of the next are Necessarily true ( may be more than 1)
there is a Polynomial-time reduction from A to B
there is a Polynomial-time reduction from A to C
there is a Polynomial-time reduction from C to A
there is a Polynomial-time reduction from C to D
thanks in advance for your answer.
(1) is true (with the exception of B={} and B={all words}), with the following polynomial reduction:
Let w_t be some word such that B(w_t)=true, and w_f be some word such that B(w_f)=false.
Given a word w: Run A(w). If A(w)=true, return w_t - otherwise, return w_f
The above is polynomial reduction, because all operartions are polynomial and the output of the reduction yields B(f(w))=true if and only if A(w)=true.
(2) is true again, with the same reduction (again, if you can assume there is one w_t and one w_f such as described).
(3) This is wrong, assuming P!=NP.
Assume such a reduction exist, and let it be f:Sigma*->Sigma*.
Examine the problems C=SAT and A is some problem P, and let M_A be a polynomial time algorithm that solves A.
We will show we can solve SAT in polynomial time (but since we assumed P!=NP, it is impossible - contradiction, so f does not exist).
Given an instance of SAT w, run w'=f(w). Run M_A(w'), and answer the same.
The above is clearly polynomial, and it returns always the correct answer - from the definition of polynomial reduction - f(w) is in A if and only if w is in C.
Thus - the above algorithm solves SAT in polynomial time - contradiction.
(4) Is also wrong, since case (3) is covered in it.

solving the Longest-Path-Length. Is my solution correct?

This is the question [From CLRS]:
Define the optimization problem LONGEST-PATH-LENGTH as the relation that
associates each instance of an undirected graph and two vertices with the number
of edges in a longest simple path between the two vertices. Define the decision
problem LONGEST-PATH = {: G=(V,E) is an undirected
graph, u,v contained in V, k >= 0 is an integer, and there exists a simple path
from u to v in G consisting of at least k edges}. Show that the optimization problem
LONGEST-PATH-LENGTH can be solved in polynomial time if and only if
LONGEST-PATH is contained in P.
My solution:
Given an algorith A, that can solve G(u,v) in polytime, so we run the A on G(u,v) if it returns 'YES" and k' such that k' is the longest path in G(u,v), now all we have to do it compare if
k =< k'
if then the longest path length is solved. If we recieve "NO" or k>=k', then there exists no solution.
so polytime to run A + constant for comparsion, then to find the longest path length it takes poly time. Also this is only possible since G(u,v) runs in Polytime (in P), thus G(u,v,k) runs also in polytime (in P), therefore since longest path can be reduced to longest-path-length, then longest-path-length is in P.
we can solve it the oposite way, what we do is, run G(u,v,k') for k'=0 to n, every time check if the k==k', is so we solved it.
run time analysis for this:
n*polytime+ n*(constant comparsion)=polytime
Can someone tell me if my answer is reasonable? if not please tell me where i've gone wrong
Also can you give me some advice to how to study algorithms ,and what approch i should take to solve a algorith question (or a graph question)
please and thankyou
Your answer is reasonable but I would try to shore it up a little bit formally (format the cases separately in a clear manner, be more precise about what polynomial time means, that kind of stuff...)
The only thing that I would like to point out is that in your second reduction (showing the decision problem solves the optimization problem) the for k=0 to N solution is not general. Polynomial time is determined in relation to the length of input so in problems where N is a general number (such as weight or something) instead of a number of a count of items from the input (as in this case) you need to use a more advanced binary search to be sure.

Resources