i have NP hard problem. Let imagine I have found some polynomial algorithm that find ONLY one of many existing solutions of that problem, but at least one solution (if present in the probem). Is that algorithm considered as solution of NP=P question (if that algorithm transformed to mathematical proof)?
Thanks for answers
NP is a class of decision problems. Your algorithm should answer "yes" or "no" correctly to all possible instances (questions).
For example, the problem: "given graph G and number k, does G contain a clique of size >= k" is NP-hard. If you have a polynomial time algorithm that answers "yes" or "no" correctly each time, then it is a valid proof of P=NP. The algorithm doesn't need to explicitly show the clique - only answer if it exists for all possible G and k.
If you find a NP-hard problem and you can detect some cases that you can solve in polynomial time (leaving others for exponential time), then only if the fraction of cases remaining is on the order of log(N)/N will you change the order of the entire problem, and even then only if you can restrict your exponential case to examining only log(N) not all N possibilities.
Also, if you find a NP-hard problem where you think you can solve every case in polynomial time, you have probably made a mistake, either in posing a NP-hard problem correctly, or in finding the more troublesome examples. Try a larger test set before believing yourself!
Related
knapsack problem is NP means that there is polynomial algorithm that can verify solution. Can you tell me what means "verify". what is that algorithm? How we can verify given solution?
You seem to be a victim of sloppy language.
The classes P and NP apply to decision problems only. Those are questions with a yes/no answer.
NP does not mean that we verify an answer in polynomial time, because that answer is just 'yes' or 'no'.
NP means that every 'yes' answer has a proof that we can verify in polynomial time.
For knapsack, the NP decision problem is "is there a subset of weights that exactly fills the knapsack"? When the answer is 'yes', a list of those weights would be the proof, and you can verify it just by adding them up.
Verify means checking if an answer is correct.
To verify a solution to the knapsack problem (e.g. a set of items to pack) we can sum their sizes (linear to the number of items packed) and compare the total to the space in the knapsack.
Verifying that it is an optimal answer is as difficult (np) as solving the knapsack problem. However, given a set of solutions we can choose (or verify) the best of those solutions again in polynominal time to the number of solutions.
The algorithm needs to generate all possible combinations from a given list (empty set excluded).
list => [1, 2, 3]
combinations => [{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}]
This algorithm would take O(2n) time complexity to generate all combinations. However, I'm not sure if an improved algorithm can bring this time complexity down. If an improved algorithm exists, please do share your knowledge!
In the case that it takes O(2n) which is exponential, I would like some insight regarding which class this algorithm belongs to P, NP, NP-Complete, or NP-Hard. Thanks in advance :)
P, NP, NP-complete, and NP-hard are all classes of decision problems, none of which contain problems that involve non-binary output (such as this enumeration problem).
Often people refer colloquially to problems in FNP as being in NP. This problem is not in FNP either because the length of the output string for the relation must be bounded by some polynomial function of the input length. It might be FNP-hard, but we're getting into the weeds that even a graduate CS education doesn't cover. Worth asking on the CS Stack Exchange if you care enough.
This problem is in none of them except, arguably, NP-hard.
It is not in P because there is no polynomial time algorithm to do it. You cannot generate an exponential number of things in polynomial time.
It is not in NP because there is no polynomial time algorithm to validate the answer. You cannot process an exponential number of things in polynomial time.
It is not in NP-complete because everything in NP-complete must be in NP and it is not.
The argument for it being in NP-hard goes like this. You can say anything that you want about the members of the empty set. Including that they make monkeys fly out of your nose and can solve any problem in NP in polynomial time. So if we could find a polynomial solution, we can solve any NP problem fast, and therefore it meets the definition of NP-hard. But uselessly so - we know that no polynomial solution exists.
So I was reading this Wikipedia article https://en.wikipedia.org/wiki/Sharp-P-complete
and stumbled on this line:
How many different variable assignments will satisfy a given 2SAT formula?
Can someone link me a proof or write one that points out solving a 2SAT #P algorithm can solve any NP problem since it stated there that 2SAT#P solves PvsNP?
If I understand you correctly now, you are referring to this line:
A polynomial-time algorithm for solving a #P-complete problem, if it existed, would imply P = NP
in the wikipedia page you linked.
An important distinction from the title of your question is the "polynomial-time" part. A polynomail-time solution to a #p-complete problem (as #2SAT) would prove P=NP. Solutions that are not polynomial in time (in regard to their input) exist already.
(I'm assuming you know that, but I feel obliged to include this clarification so people who don't know the distinction and read the question won't get misinformed).
And to answer your question - remember that #P is the class of all the counting problems corresponding to the decision problems in NP. Now from the #P Wikipedia page:
Clearly, a #P problem must be at least as hard as the corresponding NP problem. If it's easy to count answers, then it must be easy to tell whether there are any answers—just count them and see whether the count is greater than zero.
And the described reduction is of-course done in polynomial time (we are actually using the exact same input and solving the counting-problem for it, then performing one check for the output - whether it is greater than zero).
For completion of answer (again - for those who don't know it yet) here's why this shows the first quoted line is true: If there is a polynomial-time algorithm that solves a #P-complete problem, then it can be used to solve all #P problems in polynomial time by using a polynomial-time reduction from them to it (which exist as it is a #P-complete problem) and solving it with said algorithm. Showing a polynomial-time reduction for any NP problem from its corresponding #P-problem (as the second quote did) means that if such an algorithm exists, for any NP-problem we can look at its counting problem (which is in #P by definition), reduce it into #2SAT, solve it and get the result for the NP problem - all in polynomial time. Which means - if such an algorithm exists, all NP problems can be solved in polynomial-time using a deterministic Turing machine, which means they are all in P (and P=NP).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Subset problem is defined in Wikipedia as follows:
Given a set of integers, is there a non-empty
subset whose sum is zero? For example, given the set { −7, −3, −2, 5,
8}, the answer is yes because the subset { −3, −2, 5} sums to zero.
or
given a set of integers and an integer s, does any non-empty subset sum to s?
Brute force solution for this problem is exponential (cycle through all subsets of N numbers and, for every one of them, check if the subset sums to the right number), there some optimized version for brute force running in exponential time as well.
Let suppose there is an algorithm that can compute a brute force solution (exact solution to above questions) in between quadratic and polynomial time complexity
How it would be considered related to P=NP question, time complexity and so on?
Supposing algorithm exists, would be an improvement to state of the art for the subset sum problem?
(I'm not an expert on this area so if something does not make sense or is not clear I'll provide additional input to this question to the extent I'm able to :) )
Since the subset problem is NP-complete, if you can find a polynomial time solution to the problem, then you can solve all problems in NP in polynomial time, and P = NP.
Now, of course the above statement wouldn't make sense without understanding what NP and NP-completeness are. There are many ways to define NP problems, but the simplest way is that a problem is in NP if and only if there exists a verifier that can check the correctness of its solution in polynomial time. In the case of the subset sum problem, clearly you can verify its solution in polynomial time. Therefore, it's an NP problem.
The class NP-complete is a special set of problems in NP such that all problems in NP can be reduced to any problem in NP-complete in polynomial time. As an example, the first proven NP-complete problem by Cook is the SAT problem, where you try to decide if there exists a possible assignment to a set of boolean variables such that a boolean formula would evaluate to true. With the correct procedure, you can transform all decision problems in NP to SAT in polynomial time, and this makes SAT NP-complete. You can find more details about the original proof here, but it requires some understanding of the Turing machine.
To prove the NP-completeness of a new problem, you can try to reduce an existing NP-complete problem to the new one. As an example, we know that the SAT problem can be easily reduced to a 3-SAT problem. This means given a SAT problem, we can transform it into a 3-SAT version such that solving the equivalent 3-SAT problem would give us the result of the original SAT problem. Since all problems in NP can be reduced to SAT, and SAT can be reduced to 3-SAT, this makes the 3-SAT problem NP-complete.
Here is a nice proof of how you can reduce 3-SAT to the subset sum problem. As a consequence of the proof, the subset sum problem is NP-complete. Hence, if you can find a polynomial time solution to the subset sum problem, you can then solve all NP problems (yes, including problems such as the traveling salesman, graph coloring, knapsack, etc.) in polynomial time (since all reductions are done in polynomial time).
Professor Tim Roughgarden from Stanford University while teaching a MOOC said that solutions to problems in the class NP must be polynomial in length. But the wikipedia article says that NP problems are decision problems. So what type of problems are basically in the class NP ? And is it unnecessary to say that solutions to such problems have a polynomial length output(as decision problems necessarily output either 0 or 1) ?
He was probably talking about witnesses and verifiers.
For every problem in NP, there is a verifier—read algorithm/turing machine—that can verify "yes"-claims in polynomial time.
The idea is, that you have some kind of information—the witness—to help you do this given the time constraints.
For instance, in the travelling salesman problem:
TSP = {(G, k) if G has a hamiltonian cycle of cost <= k}
For a given input (G, k), you only need to determine whether or not the problem instance is in TSP. That's a yes/no answer.
Now, if someone comes along and says: This problem instance is in TSP, you will demand a proof. The other person will then probably give you a sequence of cities. You can then simply check whether the cities in that order form a Hamiltonian cycle and whether the total cost of the cycle is ≤ k.
You can perform this procedure in polynomial time—given that the witness is polynomial in length.
Using this sequence of cities, you were thus able to correctly determine that the problem instance was indeed in TSP.
That's the idea of verifiers: They take a proof object/witness that is polynomial in length to check in polynomial time, that a certain problem instance is in the language.
The standard definition of NP is that it is a class of decision problems only. Decision problems always produce a yes/no answer and thus have constant-sized output.
sDidn't watch the video/course, but I am guessing he was talking about certificates/verification and not solutions. Big difference.