It is written in a book that --"If a problem A is NP-Complete, there exists a non-deterministic polynomial time algorithm to solve A" . But as far I know 'yes' -answer for NP complete problems can be "verified" in polynomial time. I am really confused. Can a NP-complete problem be "solved" using non-deterministic polynomial time algorithm?
The two things are basically identical and are based on two different though equivalent definition of NP.
Every problem (language) in NP must be:
Verified in polynomial time by a deterministic turing machine. (given a problem and a 'verification', you can answer if the verification is correct for the problem in a polynomial time).
Example: Given a graph, and you want to check if there is a hamiltonian path in it - the verifier can be the path. You can easily check if the path is indeed hamiltonian once you have it.
Solved in polynomial time by a non deterministic turing machine. (there exists non deterministic Turing Machine M that can solve the problem polynomially)
Since by definition of NP-Complete - a problem is NP Complete if it is NP-Hard AND in NP, every NP-Complete problem is also NP - and both are correct.
Note that those two claims are basically based on the two equivalent definitions for NP:
A language L is in NP if for each x in L there is a word z such that |z| is polynomial in |x|, and there exists some deterministic turing machine that runs in polynomial time M - such that for each x and its matching z,: M(x,z) = true if and only if x is in L
A problem is in NP if there is a non deterministic turing machine that can solve the problem in polynomia time. Formally, a language L is in NP if there is a non deterministic turing machine such that M(x) = true if and only if x is in L
Finding the solution to an NP-complete problem can be done in polynomial time on a non-deterministic Turing machine. Given a candidate solution of an NP-complete problem, it can be verified whether it is indeed a solution or not, i.e. checked, in polynomial time on a deterministic Turing machine.
So the difference is in finding a solution and checking a solution. The former usually requires some kind of search for NP-complete problems while the latter is just verifying the assignments to your variables.
Related
Is this statement true or false : "If a problem A is polynomially reducible to a problem B, then problem B must also be polynomially reducible to A".
This is wrong, consider the reducible to relationship as its hardness is less than or equal. For example, if A is polynomially reducible to B, it means that A <= B in terms of hardness (amount of computation needed to solve it). If A is reducible to B it means that A is simpler than (or as hard as) B, which means if you can solve B you can solve A, as well.
Some supplementary information:
Any problem in P, which are problems that are simple and can be solved in polynomial time, is reducible to any problem in NP-complete (e.g. SAT). This means that problems in P are simpler than problems in NP-complete. Now, if your statement was true then problems in NP-complete would have been solved in polynomial time, which is seemingly impossible (no one has proved or disproved it). And if anybody solves it there will be chaos!!!
https://en.wikipedia.org/wiki/P_versus_NP_problem
SAT problem
A world with P=NP
Here is a (slightly edited) illustration from a very well-known graduate text on Complexity Theory (C.H. Papadimitriou, Computational Complexity). It shows what a reduction from A to B is.
A reduction from A to B is an algorithm for solving A that is composed of a translation R that maps every instance of A into an instance of B, and an algorithm for B. The translation must ensure that the answer for A(x) and for B(R(x)) is the same.
The existence of a such a translation does not guarantee that the inverse translation also exists. Intuitively the images of instances of A might form a subset of easy instances of B.
Anyone can easily suggest simple examples of problems where reduction in one direction does not guarantee a reduction in the other direction. For instance, 2-SAT is trivially reducible to SAT, yet 2-SAT is solvable in polynomial time, while SAT is NP-complete.
This is false. Consider the following problem:
Given a finite automaton, does it halt on a given input?
The answer to this problem happens always to be yes since all deterministic finite automata halt on all inputs. However, this problem is polynomial-time reducible to the following problem:
Given a Turing machine, does it halt on a given input?
The answer to this problem happens to be undecidable in the general case. This is the halting problem. However, if we had an oracle for this problem, we could certainly use it to answer the first question, albeit much less efficiently:
Produce a Turing machine equivalent to the DFA
Use the oracle to determine whether the Turing machine halts.
The halting problem for Turing machines, however, is not polynomial-time reducible to the halting problem for DFAs.
Assuming P != NP
The euler diagram shows a part not part of P and NP-complete. I read on wikipedia that this set is called NP-Intermediate.
Euler Diagram
I have some doubts as to how are NPI problems defined?
An NP-intermediate problem is a decision problem that
is in NP (that is, "yes" answers can be verified in polynomial time),
is not in P (that is, there is no polynomial-time algorithm for solving the problem), and
is not NP-complete.
That last criterion can be stated in a number of different ways. One way to say this is that there is no polynomial-time mapping reduction from SAT to that particular problem.
These problems are primarily of theoretical interest right now because we don't know if any NP-intermediate problems exist - if we could find one, we'd have a problem in NP that's not in P, meaning that P ≠ NP! However, they're interesting because if we can prove that P ≠ NP, then we know that there are some problems in NP that are too hard to be solved in polynomial time, but which aren't among the "hardest" of the hard problems in NP (the problems that are NP-complete).
In the event that P = NP, then there would not be any NP-intermediate problems because you couldn't have a problem in NP but not in P. If P ≠ NP, then Ladner's theorem guarantees at least one NP-intermediate problem exists, but does so by specifically constructing a problem that is highly artificial and designed solely to be NP-intermediate in that case. Right now, with a few exceptions (notably the graph isomorphism problem), all the problems we know of in NP are either squarely in P or known to be NP-complete.
I am actually looking for description what NP alogrithm actually means and what kind of algo/problem can be classified as NP problem
I have read many resources on net . I liked
https://www.quora.com/What-are-P-NP-NP-complete-and-NP-hard
What are the differences between NP, NP-Complete and NP-Hard?
Non deterministic Turing machine
What are NP problems?
What are NP and NP-complete problems?
Polynomial problem :-
If the running time is some polynomial function of the size of the input**, for instance if the algorithm runs in linear time or quadratic time or cubic time, then we say the algorithm runs in polynomial time . Example can be binary search
Now I do understand Polynomial problem . But not able to contrast it with NP.
NP(nondeterministic polynomial Problem):-
Now there are a lot of programs that don't (necessarily) run in polynomial time on a regular computer, but do run in polynomial time on a nondeterministic Turing machine. These programs solve problems in NP, which stands for nondeterministic polynomial time.
I am not able to to understand/think of example that does not run in polynomial time on a regular computer. Per mine current understanding, Every problem/algo can be solved
in some polynomial function of time which can or can't be proportional to time. I know i am missing something here but really could not grasp this concept. Could someone
give example of problem which can not be solved in polynomial time on regular computer but can be verified in polynomial time ?
One of the example given at second link mentioned above is Integer factorization is in NP. This is the problem that given integers n and m, is there an integer f with 1 < f < m, such that f divides n (f is a small factor of n)? why this can't be solved in some polynomial time on regular computer ? we can check for all number from 1 to n if they divide n or not. Right ?
Also where verification part come here(i mean if it can be solved in polynomial time but then how the problem solution can be verified in polynomial time)?
Your question touches several points.
First, in the sense relevant to your question, the size of a problem is defined to be the size of the representation of the problem. So, for example, when you write about the problem of a divisor of n. What is the representation of n? It is a series of characters of length q (I don't want to be more specific than that). In general, n is exponential in q. So when you talk about a simple loop from 1 to n, you're talking about something that is exponential in the size of the input. For example, the number "999999999999999" represents the number 999999999999999. That is quite a large number, but it is represented by 12 characters here.
Second, while there is more than a single way to define the class NP, perhaps the simplest one for decision problems (which is the type you raise in your question, namely is something true or not) is that if the answer is true, then there is an "certificate" that can be verified in polynomial time. For example, consider the Hamilton Path Problem. This is (probably) a hard problem to solve, but, if you are given a hamilton path as an answer, it is very easy to verify that it is so; specifically, it can be done in polynomial time. For the Hamilton Path Problem, the path is a polynomial-time verifiable certificate, and therefore this problem is NP.
It's probably worth noting how the idea of "checking a solution in polynomial time" relates to a nondeterministic Turing Machine solving a problem: in a normal (deterministic) Turing Machine, there is a well-defined set of instructions telling the machine exactly what to do in any situation ("if you're in state 3 and see an 'a', move left, if you're in state 7 and see a 'c', overwrite it with a 'b', etc.") whereas in a nondeterministic Turing Machine there is more than one option for what to do in some situations ("if you're in state 3 and see an 'a', either move right or overwrite it with a 'b'"). In terms of algorithms, this lets us "guess" solutions in the sense that if we can encode a problem into a language on an alphabet* then we can use a nondeterministic Turing Machine to generate strings on this alphabet, and then use a standard (deterministic) Turing Machine to ensure that it is correct. If we assume that we always make the right guess, then the runtime of our algorithm is simply the runtime of the deterministic checking part, which for NP problems runs in polynomial time. This is what it means for a problem to be 'decidable in polynomial time on a nondeterministic Turing Machine', and why it is often simply phrased as 'checking a solution/ certificate in polynomial time'.
*
Example: The Hamiltonian Path problem could be encoded as follows:
Label the vertices of the graph 1 through n, where n is the number of vertices. Our alphabet is then the numbers 1 through n, and our language consists of all words such that
a) every integer from 1 to n appears exactly once
and
b) for every consecutive pair of integers in a word, the vertices with those labels are connected
Polynomial Time :- Problem which can be solved in polynomial time of input size is called polynomial problem. In plain simple words :- Here Solution to problem is fast. For
example sorting, binary search
Non deterministic polynomial :- Theoretically the problems which can be verified in polynomial time irrespective of actual solution time complexity (which can be polynomial or not polynomial). So some problem which are P can also be NP.
But Informally people while conversation/posts use the NP term in below sense
Problem which can not be solved in polynomial time of input size is called polynomial problem. In plain simple words :- Here Solution to problem is not fast. You may have to try different permutation/combination or guessing work. But Verification part is fast and can be done in polynomial time. Like
input some numbers X and divide the numbers into two groups that difference in their sum is minimum
I really liked the Alex Flint answer at https://www.quora.com/What-are-P-NP-NP-complete-and-NP-hard .Above is just gist of that.
I have to check out whether my logic is on the right path.
NP-HARD: these are the hardest problems which may/may not be in NP class. If you have an efficient algorithm for these problems you have one for every problem in class NP.
NP COMPLETE: these are the hardest problems in class NP and also if you solve one of these you could solve any problem in class NP. So, NP COMPLETE problem is an NP-HARD problem.
COOK'S THEOREM: If SAT(NP-HARD) has a polynomial time algorithm then so does every problem in class NP.
Now, suppose we have to prove that CDP(clique decision problem) is NP COMPLETE.
->Step 1: Prove that CDP is in the class NP.
It is in class NP because the prover can generate a proof for yes inputs which would enable the verifier to check that it is a CDP (has a clique of size k).
->Step 2: Prove that CDP is NP HARD.
For that, we can convert the SAT to CDP by constructing a graph from clauses and supplying k.
We supply(G,k) to the clique subroutine which would verify is there a clique of size k or not. If it can figure this out in polynomial time then SAT has a polynomial time algorithm as CDP had a polynomial time algorithm and we converted SAT to CDP. So, now we proved that if there is a polynomial time algorithm for CDP then there is for the SAT. Now if we can find a polynomial time algorithm for CDP then it would imply that there is a polynomial time algorithm for SAT. This would imply that there is a polynomial time algorithm for every problem in NP by COOK'S THEOREM.
So we proved that CDP is NP COMPLETE. Once we have added CDP to NP COMPLETE class and now we come up with a new problem which we have again to prove that it is NP COMPLETE we can prove that problem to be in NP and then we could prove that if there is an efficient algorithm for given problem then that implies that there is an efficient algorithm for SAT/CDP(as we have added this to NP COMPLETE). Then as said above we can convert this problem to CDP/SAT and then prove that if there is an efficient algorithm for our problem then there is one for CDP/SAT and then by COOK'S THEOREM again we have that if there is a solution to NP-HARD problem (in this case CDP/SAT) then there is one for every problem in NP. So we again proved our problem as NP-HARD and as now it also belongs to NP as said above it is NP COMPLETE.
So we can add as many problems to the NP COMPLETE class as long as we can convert some problem which is already in NP-HARD class(in this case SAT/CDP) into our problem and we should find an efficient algorithm to our problem which would indirectly find an efficient algorithm to the NP-HARD problem and by COOK's theorem we can say that as some NP-HARD problem has an efficient algorithm we have an efficient algorithm to solve all problems in NP.
You're on the right path, but there your logic is a little incomplete.
The general structure of your proof is correct: First prove a problem is in NP, then prove the problem is NP-Hard. Those two bits of information together prove that a problem is NP-Complete.
Your proof for proving a problem is in NP is incomplete. Here are the key components to proving a problem is in NP:
Reword the problem as a decision problem that can be answered with a yes or a no.
Describe what a "certificate" would be. NOTE: a certificate is an output that can be checked to verify the answer to the decision problem. For CDP it could be a list of vertices and edges that make up the clique of size k.
Prove that this certificate can be verified in polynomial time.
Your proof for proving NP-Hard is incomplete. Here are the key components to proving a problem is NP-Hard:
Transform the input of the known NP-Hard problem into the input for the problem you are trying to prove.
Prove that this transformation can be done in polynomial time.
Transform the output of the problem your trying to prove into the output of the known NP-Hard problem.
Demonstrate how this can be done in polynomial time.
Prove that if you get an answer for the problem you are trying to prove, then you have an answer for the known problem.
Prove that if you get an answer for the known problem you have an answer for the problem you are trying to prove.
Only by meeting those 6 criterion can you say you have completely proven that a problem is NP-Hard.
Besides the specifics on that your logic is sound. Be careful when saying "efficient" if you really mean "can be solved in polynomial time".
I'm learning how to prove something is NP. In Thomas Cormen's intro to algorithm book, he states something is NP if given a solution to some problem, you can verify it is correct in polynomial time.
Say the problem is 2x + 9 = 55, and let's pretend I don't know how long it takes the find the correct x value, but an algorithm to solve the problem returned the solution 23. Then to show it is NP, do I only need to plug 23 in back in the equation, and see if that took a polynomial time and gave me 55? Thanks.
Yes; if you can check the correctness of every correct and every incorrect answer for every instance of this problem in polynomial time, then the problem is in NP.
Adding information to #Mehrdad answer:
Note that NP stands for Nondeterministic Polynomial time - it means that by definition - a problem is in NP if and only if it can be solved polynomially by a Non-deterministic Turing Machine.
It is equivalent to saying that in the standard computation model (RAM machine/ deterministic turing machine) - you can verify an answer in polynomial time (like #Mehrdad answered). The proof for the equivalence is described in the wikipedia page for equivalence of definitions
Bonus:
The question of "is everything that is verifiable (polynomially) on turing machine is also solveable polynomially" and the questions "is everything that is solveable on non-deterministic turing machine polynomially also solveable on deterministic turing machine polynomially" are also equivalent.
The answer is yet unknown and the problem is known as the P vs NP problem, which is the most important open question on computer science.
While the problems above cover the last, and perhaps, most identifiable step of NP-ness, there are 3 basic steps to showing that a problem is in NP.
Decision Problem: Can you turn your problem into a decision problem? In the case of the equation problem,the decision problem would be "is there an x such that 2x+9=55?" ?
Certificate: Can you identify an answer to your decision question? Again, in the case of the equation problem, an answer might be x = 23
Verification: Can you verify a certificate in polynomial time. By verifying in polynomial time, you know that the problem is not NP-Hard. Some verification steps might be: is x a number? is X equal to one half of 55-9?
That is how you know that your problem is completely in NP.