views:

1347

answers:

4

What are the differences between NP vs NP-Complete vs NP-Hard ?

I am aware of many resources all over the web. I d like to read your explanations, and the reason is they might be different then what s out there, or it s out there and i m not aware.

+2  A: 

http://en.wikipedia.org/wiki/NP%5F%28complexity%29
http://en.wikipedia.org/wiki/NP-complete
http://en.wikipedia.org/wiki/Np-hard

Mr. Brownstone
That wasnt very helpful. I m glad you didnt tell me to google it. My intention of asking this question is to learn some insights and ideas from other people in english.
The wikipedia explanations are actually pretty good. Is there something in particular you are having trouble with?
Suppressingfire
I m not having trouble with the definitions, i want to read others approach to describe this. CLRS and Sipser is right in front of me and i read it. I m curious about other's ideas and explanations about this. hope this is ok.
The edited part was kinda wrong. Thanks for removing.
These are all pretty well formally defined classes of problems so I gave you the defitions. Maybe you should update your question if you're looking for "ideas and insights".
Mr. Brownstone
ok i voted up. i certainly know how to look it up from google and wiki.
+3  A: 

NP-complete problems are those problems that are both NP-Hard and in the complexity class NP. Therefore, to show that any given problem is NP-complete, you need to show that the problem is both in NP and that it is NP-hard.

Problems that are in the NP complexity class can be solved non-deterministically in polynomial time and a possible solution (i.e., a certificate) for a problem in NP can be verified for correctness in polynomial time.

An example of a non-deterministic solution to the k-clique problem would be something like:

1) randomly select k nodes from a graph

2) verify that these k nodes form a clique.

The above strategy is polynomial in the size of the input graph and therefore the k-clique problem is in NP.

Note that all problems deterministically solvable in polynomial time are also in NP.

Showing that a problem is NP-hard typically involves a reduction from some other NP-hard problem to your problem using a polynomial time mapping: http://en.wikipedia.org/wiki/Reduction%5F%28complexity)

awesomo
Not that I see anything in this answer that is incorrect, but I don't know why it was accepted. It doesn't really offer much to what the OP was asking. It's not really even different than the standard explanations of these problems, and there aren't any clear explanations as to what makes these problems in these classes. Not worth a downvote, but certainly not worth answer acceptance.
San Jacinto
@San, i asked the question. not you. you can ask it again on your own. I prefer this answer better than wiki links.
@unknown okay, glad it helped you nonetheless :)
San Jacinto
+30  A: 

I assume that you are looking for intuitive definitions (the technical definitions are, well, technical and require quite some time to understand). Let's start by defining NP.

Decision problem: A question with a yes or no answer.

P: A decision problem that can be solved in polynomial time. That is, given an instance of the problem, the answer yes or no can be decided in polynomial time.

Example: Given a graph G, can its vertices be colored using two colors so that no edge is monochromatic. Algorithm: start with an arbitrary vertex, color it red and all of its neighbors blue and continue. Stop when you run our of vertices or you are forced to make an edge have both of its endpoints be the same color.

NP: A decision problem where instances of the problem for which the answer is yes have proofs that can be verified in polynomial time. This means that if someone gives us an instance of the problem and a certificate (sometimes called a witness) so the answer being yes, we can check that it is correct in polynomial time.

Example: Integer factorization is 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)? This is a decision problem because the answers are yes or no. If someone hands us an instance of the problem (so they hand us integers n and m) and an integer f with 1 < f < m and claim that f is a factor of n (the certificate) we can check the answer in polynomial time by performing the division n / f.

NP-complete: An NP problem X for which it is possible to reduce any other NP problem Y to X in polynomial time. Intuitively this means that we can solve Y quickly if we know how to solve X quickly. Precisely, Y is reducible to X if there is a polynomial time algorithm f to transform instances x of X to instances y=f(x) of Y in polynomial time with the property that the answer to x is yes if and only if the answer to f(x) is yes.

Example: 3-SAT. This is the problem wherein we are given a conjunction of 3-clause disjunctions (i.e., statements of the form

(x_v11 or x_v21 or x_v31) and (x_v12 or x_v22 or x_v32) and ... and (x_v1n or x_v2n or x_v3n)

where each x_vij is a variable or the negation of a variable from a finite predefined list (x_1, x_2, ... x_n). It can be shown that every NP problem can be reduced to 3-SAT. The proof of this is technical and requires use of the technical definition of NP (based on non-deterministic Turing machines and the like). This is known as Karp's theorem.

What makes NP-complete problems important is that if a deterministic polynomial time algorithm can be found to solve one of them, every NP problem is solvable in polynomial time (one problem to rule them all).

NP-hard: Intuitively these are the problems that are even harder than the NP-complete problems. Note that NP-hard problems do not have to be in NP (they do not have to be decision problems). The precise definition here is that a problem X is NP-hard if there is an NP-complete problem Y such that Y is reducible to X in polynomial time. But since any NP-complete problem can be reduced to any other NP-complete problem in polynomial time, all NP-complete problems can be reduced to any NP-hard problem in polynomial time. Then if there is a solution to one NP-hard problem in polynomial time, there is a solution to all NP problems in polynomial time.

The halting problem is the classic NP-hard problem. This is the problem that given a program P and input I, will it halt? This is a decision problem but it is not in NP. It is clear that any NP-complete problem can be reduced to this one.

P = NP: This the most famous problem in computer science, and one of the most important outstanding questions in the mathematical sciences. In fact, the Clay Institute is offering one million dollars for a solution to the problem (Stephen Cook's writeup on the Clay website is quite good). It's clear that P is a subset of NP. The open question is whether or not NP problems have deterministic polynomial time solutions. It is largely believed that they do not. Here is an outstanding recent article on the latest (and the importance) of the P = NP problem: The Status of the P versus NP problem.

The best book on the subject is Computers and Intractability by Garey and Johnson. My favorite NP-complete problem is the Minesweeper problem.

Jason
Nice work! Def. gets my upvote.
San Jacinto
upvote for San. to appreciate an answer. this is what i was looking a short summary of what someone thinks. there are much more interesting approaches i read. such as Non-deterministic turing machine and the way it works to explain the problem. i just wanted to see an answer without going too deep into details. such as a magic machine that works non deterministically in paralel and solves problems in polinomial time which these problems are NP problems.
Yet another example is dove tailing, a paradigm in parallel programming which describes NP problems.
decision trees are another tool to use to explain NP problems.
@Jason, thanks. this is great.
@unknown (google): The explanations involving non-deterministic Turing machines are the technically correct explanations. Turing machines are how we formalize the notions of computers, algorithms, problems etc.
Jason
NP-hard problems need not be decision problems
Managu
"The halting problem is the classic NP-hard problem."No, it's not. The halting problem is *undecidable*. If you're looking for the classic NP-hard problem, you're probably looking for Travelling Salesman.
Paul Fisher
@Managu: Yes, that is what I meant when I said that "NP-hard problems do not have to be in NP." I will make this meaning more explicit.
Jason
@Paul Fisher: I'll show that SAT is reducible to the halting problem in polynomial time. Consider the following algorithm: given as input a proposition `I` over `n` variables, try all `2^n` possible assignments to the variables and halt if one satisfies the proposition and otherwise enter an infinite loop. We see that this algorithm halts if and only if `I` is satisfiable. Thus, if we had a polynomial time algorithm for solving the halting problem then we could solve SAT in polynomial time. Therefore, the halting problem is NP-hard.
Jason
@Jason - You can't reduce a decidable problem to an undecidable problem in that manner. Decidable problems have to result in a definitive yes or no answer in order to be considered to be decidable. The Halting Problem does not have a definitive yes or now answer since an arbitrary answer might throw any solution into a loop.
Rob
@Rob: Yes, I can. The definition of reducible does not require that the problem being reduced to be solvable. This is true for either many-one reductions or Turing reductions.
Jason
@Jason - Sorry, that's wrong even though I must admit that I was incorrect in stating that the Halting problem doesn't have a definitive yes or no solution. It is indeed a decision problem; however, it is an undecidable one. The reason that you can't reduce SAT to the Halting problem in that way is because the Halting problem requires that a Turing Machine *M* and a input string *w* be provided, it should then accept if *M* accepts *w*, otherwise reject. However, simulation of *M* on a Universal Turing Machine might cause a loop which is why the Halting Problem is undecidable.
Rob
[continued] Likewise, you fail to provide a mapping from SAT to the Halting problem since you are, in essence, saying that any Boolean formula can be used to determine if *M* accepts *w* however, this is not possible unless you have a means of simulating *M* which you fail to provide.
Rob
@Rob: Well, okay, if you want to continue this. First, "Decidable" is not synonomous with "decision problem" as you've used it. "Decidable" means, roughly, that there is an "effective method" for determining the answer. "Effective method", of course, has a technical definition. Moreover, "decidable" can also be defined in terms of "computable functions." So, the halting problem is a decision problem ("Does this program halt?" is a yes/no question) but it is undecidable; there is no effective method for determining whether or not an instance of the halting problem will halt.
Jason
@Rob: Second, I maintain that the definition of reducibility does not require that the problem being reduced to be decidable. Precisely, we say that `A` is Turing reducible to `B` if there is an Oracle algorithm for `A` given an `Oracle` algorithm for `B`. See, for example, Sipser, Introduction to the Theory of Computation.
Jason
@Rob: Finally, regarding the statement that started all of this ("the halting problem is NP-hard"), I note that Google (http://www.google.com/search?hl=en some even provide proofs similar to the one that I outlined.
Jason
@Jason - Just so you know, I'm not "continuing this" to be a jerk or anything, these are subjects that I enjoy talking about. Now, back to the subject at hand, I did some reading around and it seems that the problem is we are both slightly in disagreement in regards to how we are defining reducibility. I've been exposed to in such a way that you should be able to reciprocate the reduction such that if you go from A to B then you should be able to go from B to A, likewise this is the definition that is been used in the formal class I took on the subject.
Rob
[continued] However, there is another type of reduction ("many-one reduction") that is a simple A to B with no guarantee of going the other direction and it seems that is what you are using in your proof sketch.
Rob
@Rob: I never took you to be a jerk. I'm here to learn too and discussing this stuff is fun. And yes, I was only using one-direction reducibility.
Jason
+3  A: 

This is a very informal answer to the question asked.

Can 3233 be written as the product of two other numbers bigger than 1? Is there any way to walk a path around all of the Seven Bridges of Königsberg without taking any bridge twice? These are examples of questions that share a common trait. It may not be obvious how to efficiently determine the answer, but if the answer is 'yes', then there's a short and quick to check proof. In the first case a non-trivial factorization of 51; in the second, a route for walking the bridges (fitting the constraints).

A decision problem is a collection of questions with yes or no answers that vary only in one parameter. Say the problem COMPOSITE={"Is n composite": n is an integer} or EULERPATH={"Does the graph G have an Euler path?": G is a finite graph}.

Now, some decision problems lend themselves to efficient, if not obvious algorithms. Euler discovered an efficient algorithm for problems like the "Seven Bridges of Königsberg" over 250 years ago.

On the other hand, for many decision problems, it's not obvious how to get the answer -- but if you know some additional piece of information, it's obvious how to go about proving you've got the answer right. COMPOSITE is like this: Trial division is the obvious algorithm, and it's slow: to factor a 10 digit number, you have to try something like 100,000 possible divisors. But if, for example, somebody told you that 61 is a divisor of 3233, simple long division is a efficient way to see that they're correct.

The complexity class NP is the class of decision problems where the 'yes' answers have short to state, quick to check proofs. Like COMPOSITE. One important point is that this definition doesn't say anything about how hard the problem is. If you have a correct, efficient way to solve a decision problem, just writing down the steps in the solution is proof enough.

Algorithms research continues, and new clever algorithms are created all the time. A problem you might not know how to solve efficiently today may turn out to have an efficient (if not obvious) solution tomorrow. In fact, it took researchers until 2002 to find an efficient solution to COMPOSITE! With all these advances, one really has to wonder: Is this bit about having short proofs just an illusion? Maybe every decision problem that lends itself to efficient proofs has an efficient solution? Nobody knows.

Perhaps the biggest contribution to this field came with the discovery a peculiar class of NP problems. By playing around with circuit models for computation, Stephen Cook found a decision problem of the NP variety that was provably as hard or harder than every other NP problem. An efficient solution for the boolean satisfiability problem could be used to create an efficient solution to any other problem in NP. Soon after, Richard Karp showed that a number of other decision problems could serve the same purpose. These problems, in a sense the "hardest" problems in NP, became known as NP-complete problems.

Of course, NP is only a class of decision problems. Many problems aren't naturally stated in this manner: "find the factors of N", "find the shortest path in the graph G that visits every vertex", "give a set of variable assignments that makes the following boolean expression true". Though one may informally talk about some such problems being "in NP", technically that doesn't make much sense -- they're not decision problems. Some of these problems might even have the same sort of power as an NP-complete problem: an efficient solution to these (non-decision) problems would lead directly to an efficient solution to any NP problem. A problem like this is called NP-hard.

Managu
Thank you for your answer.