P,NP,NPC, this may be one of the biggest pitfalls of many oier.
This article is for everyone to explain in detail as above three questions.
Pre-order:
You will often see the online "How do you do this, this is not NP problem", "This only search, this has been proved to be NP problem" and so on. As you know, the NP problem that most people are talking about at this point actually refers to NPC. They did not understand the concept of NP problems and NPC problems. NP problem is not the kind of "only search" problem, NPC problem is. OK, okay, basically this misunderstanding has been clarified. The following is about what is P, what is NP, what is NPC, and if you are not very interested, you can not read it. Next you can see how big a mistake it is to think of NP as NPC.
Let's start with a few words to explain the complexity of the time. Time complexity does not mean how much time it takes for a program to solve a problem, but how quickly the program needs to grow when the scale of the problem expands. That is, for a computer with high-speed processing data, the efficiency of processing a particular data does not measure the quality of a program, but should be seen when the scale of the data is larger to hundreds of times times, whether the program runs the same time, or hundreds of times times slower, or tens of thousands of times times slower.
Regardless of the size of the data, the process of processing the time is always so many, we say that the program is very good, with O (1) time complexity, also known as the constant degree of complexity, the size of the data has become how much, the time has become how long, the complexity of the program is O (n). For example, to find the maximum number of n, but like bubble sort, insert sort, the data expands twice times, the time slows 4 times times, belongs to O (n^2) complexity. There are some algorithms for the exhaustive class, the time required to increase the length of the geometric order, which is O (a^n) exponential complexity, or even O (n!) The factorial level of complexity. The complexity of O (2*n^2) is not saved, because the previous "2" is a factor that does not affect the overall program's time growth at all.
In the same way, the complexity of O (n^3+n^2) is the complexity of O (n^3). Therefore, we would say that an O (0.01*n^3) program is less efficient than O (100*n^2), although the former is better than the latter when n is very small, but the latter time increases slowly with the scale of the data, and the complexity of O (n^3) will far exceed O (n^2). We also say that the complexity of O (n^100) is less than the complexity of O (1.01^n).
Easy to see, the complexity of the preceding categories is divided into two levels, the latter of which is far more complex than the former: O (1), O (log (n)), O (n^a), etc., we call it the complexity of the polynomial level, because its size n appears in the base position, the other is O (a^n) and O (n!) Type of complexity, it is non-polynomial level, its complexity of the computer is often unable to bear. When we solve a problem, the algorithm we choose usually needs to be polynomial-level complexity, non-polynomial-level complexity takes too much time, and often times out, unless the size of the data is very small.
Naturally, people will think of a problem: will all the problems can be found in the complexity of the polynomial-level algorithm? Unfortunately, the answer is no. Some problems are even impossible to find a correct algorithm, which is called "undecidable decision Problem". The Haltingproblem is a famous non-solvable problem.
For example, the output from 1 to N of the full array of n number. No matter what method you use, your complexity is factorial, because you have to use factorial time to print out the results. Some people say that such a "problem" is not a "normal" problem, the formal problem is to let the program solve a problem, output a "YES" or "NO" (this is called a decision-making problem), or what is the optimal value (this is called the optimization problem).
So, according to this definition, I can also cite a problem that is unlikely to have a polynomial-level algorithm: Hamilton Loop. The question is this: give you a diagram asking if you can find a path that passes through each vertex once and then once (no omission or repetition) and finally comes back (the route that satisfies this condition is called the Hamilton Loop). This problem has not yet found a polynomial-level algorithm. In fact, this question is the NPC question we are going to talk about later.
P Problem:
The following introduces the concept of P-class problem: If a problem can find an algorithm that can solve it in polynomial time, then this problem is P problem. P is the first letter of the English word polynomial. What questions are P-type problems? Usually Noi and Noip do not issue topics that do not belong to the P class. Some of the information we often see is the question of P. The simple truth is that a non-polynomial-level time-out program with a poor lift does not cover any valuable algorithms.
NP problem:
Then the concept of NP problem is introduced. This is a bit difficult to understand, or easy to understand mistakes. In this emphasis (back to the misunderstanding I tried to clarify), NP is not a non-P-class problem. NP problem refers to the problem of validating a solution in polynomial time. Another definition of NP problem is that you can guess the problem of a solution in polynomial time. Let's say that my RP is good, and I can guess when I need an enumeration in my program. Now someone has a problem asking for the shortest path, whether there is a route less than 100 units in length from the start to the end. It is based on the data to draw a good picture, but how can not be counted out, so asked me: You see how to choose the least way to go? I said, I rp very good, certainly can give you casually point a very short way out. Then I just scribble a few lines and say this one. The man added up the weights as I pointed out, hey, God, the path length is 98, smaller than 100. So the answer comes out, there is a path smaller than 100.
People will ask him how to do this, he can say, because I found a smaller than 100 solution. In this problem, finding a solution is difficult, but validating a solution is easy. Verify that a solution requires only O (n) time complexity, that is, I can spend O (n) time to add up the length of the path I guess. So, as long as my RP good, guess, I will be able to solve this problem in polynomial time. I guess the solution is always the best, not to meet the test instructions plan will not come to deceive me to choose it. This is the NP problem.
Of course there is not the problem of NP, that you guessed to understand but useless, because you can not in polynomial time to verify it. The example I want to cite below is a classic example of a problem that has not yet been able to validate a solution in polynomial time. It is clear that the Hamilton Circuit mentioned earlier is NP-hard because it is very easy to verify that a path is passing through each vertex exactly. But I'm going to replace the question with this: Is there no Hamilton circuit in a diagram? This problem cannot be verified in polynomial time, because unless you have tried all the way, you dare not conclude that it "has no Hamilton circuit".
The NP problem is defined because it is usually only NP problems that can find the polynomial algorithm. We do not expect a polynomial-level algorithm to solve a problem in which a solution is not available. It is believed that the reader will soon understand that the most difficult problem in informatics-the "NP problem"-is actually exploring the relationship between NP and P-type problems.
Obviously, all P-Class problems are NP -related. That is, to solve a problem polynomial, it is necessary to be able to polynomial to verify the solution of a problem-since the positive solution has come out, verify that any given solution can only be compared. The point is that people want to know if all NP problems are P-type. We can use the view of the collection again to illustrate. If all P-class problems are classified as a set P, and all NP problems are classified into another set NP, then it is obvious that p belongs to NP. Now, all the research on NP is focused on one question: Is there a P=NP? Usually the so-called "NP problem" is actually a word: proving or overthrowing P=NP.
NP problem has always been the pinnacle of information science. The peak, meaning is very compelling but difficult to solve. In the study of information science, this is an ultimate problem that takes a lot of time and energy and is not solved, like the great unification in physics and the Goldbach conjecture in mathematics.
So far the problem has been "gnawing". However, a general trend, a broad direction is there. It is generally believed that P=NP is not tenable, that is to say, most people believe that there is at least one NP problem with an algorithm that cannot have polynomial-level complexity. People are so convinced that there is a reason for P≠NP, that is, in the process of studying NP problem, we find a kind of very special NP problem called np-complete problem, also called NPC problem. C is the first letter of the English word "complete". It is the presence of NPC that makes people believe in P≠NP. The following will take a lot of time to introduce NPC issues, and you can see how the NPC problem makes P=NP so incredible.
To the date of:
To illustrate NPC issues, we first introduce a concept--the reducibility, which is called "attribution" in some of the data.
To put it simply, a question a can be reduced to the meaning of question B, that is, you can solve problem a with the solution of question B, or question A can be "turned into" question B.
An example of this is given in the introduction to algorithms. For example, there are two problems: solving a unary-once equation and solving a unary two-second equation. Then we say that the former can be reduced to the latter, meaning to know how to solve a one-yuan two-time equation then it is possible to solve the unary-once equation. We can write two programs corresponding to two questions, then we can find a "rule", according to this rule to solve the one-dimensional equation of the input data of the program, used in the solution of a two-time equation of the program, two programs always get the same results.
The rule is that the corresponding coefficients of the two equations are constant, and the two-time term coefficients of the two-order equation are 0. By following this rule the previous question is converted to the latter one, and the two questions are equivalent. Similarly, we can say that Hamilton circuit can be reduced to TSP (travellingsalesman problem, travel salesman problem): In Hamilton Circuit problem, two point is connected to the two point distance is 0, two point is not directly connected to the distance is 1, The problem then turns into whether there is a 0-length path in the TSP problem. Hamilton Circuit exists when and only if there is a 0-length loop in the TSP problem.
"Problem a can be reduced to question B" has an important visual meaning: B's time complexity is higher or equal to the time complexity of a. In other words, problem A is not more difficult than problem B. It's easy to understand. Since problem a can be solved with problem B, if the time complexity of B is lower than the time complexity of a, then A's algorithm can be improved to B's algorithm, the time complexity is the same. Just as solving a two-time equation is harder than solving a unary one, because the method of solving the former can be used to solve the latter.
It is clear that the Covenant has an important nature: the reduction is transitive. If problem a can be reduced to question B, question B can be reduced to question C, then problem a must be reduced to question C. This is a very simple truth and it is not necessary to elaborate.
Now again, the standard concept of the Covenant is not difficult to understand: if you can find such a law of change, the input of any program a can be converted to the input of program B according to this law, so that the output of the two programs is the same, then we say that problem a can be reduced to problem B.
Of course, what we call "Polynomial-time" refers to "polynomial" (reducible), that is, the method of transforming input can be done in polynomial time. The process of the reduction is meaningful only when it is done in polynomial time.
NP and NPC questions:
Well, from the definition of the Covenant we see that one problem is reduced to another, the complexity of time increases, and the scope of application of the problem increases. Through constant reduction of some problems, we are able to search for algorithms that are more complex, but have a wider range of applications, instead of low complexity, but only for a small class of problems. Recalling the aforementioned P and NP problems, associating with the transfer of the Covenant, naturally, we would like to ask, if constantly to go up, and constantly find to "take all" a number of small NP problems of a slightly more complex NP problem, then finally whether it is possible to find a time of the highest complexity, and can "all" all NP problem of such a super NP problem? The answer is sure.
In other words, there is such a NP problem that all NP problems can be reduced to it. In other words, as long as the problem is solved, all NP problems are solved. The existence of this problem is incredibly, and even more incredible, this problem is more than one, it has many, it is a kind of problem. This kind of question is the legendary NPC question, namely np-complete question. The emergence of NPC problem has made the research of NP problem get a leap-forward development. We have reason to believe that NPC is the most complex problem.
Back to the beginning of the full text, we can see that people want to express a problem without a polynomial efficient algorithm should say that it "belongs to NPC problem." At this point, my goal has finally reached, I have the NP problem and NPC issues have been differentiated. So far, this article has written nearly 5000 words, I admire you can still see here, at the same time also admire oneself can write here.
The definition of NPC question is very simple. The problem of meeting the following two conditions is NPC. First, it has to be a NP problem, and then all NP problems can be reduced to it. Proving that one problem is NPC is also very simple. Proving that it is at least a NP problem and proving that one of the known NPC problems can be reduced to it (by the transitive nature of the Covenant, the second of the NPC's problem definitions is also met; As for the first NPC question, which follows), it can be said that it is a NPC problem.
Since all NP problems can be reduced to NPC problem, so long as any one NPC problem found a polynomial algorithm, then all the NP problem can be solved with this algorithm, NP is equal to P. So it's amazing to find a polynomial algorithm for NPC. Therefore, former Wencai said, "It is the NPC problem that makes people believe in P≠NP." We can intuitively understand that NPC problem currently does not have a polynomial effective algorithm, can only use the number of points or even factorial level of complexity of the search.
By the way, np-hard problem. Np-hard problem is a problem, it satisfies the NPC question definition of the second article but not necessarily to meet the first (that is, the np-hard problem is wider than the NPC problem). The Np-hard problem is also difficult to find the polynomial algorithm, but it does not include in our research scope, because it is not necessarily NP problem. Even if the NPC problem finds a polynomial-level algorithm, the Np-hard problem may still not get the polynomial-level algorithm. In fact, because Np-hard relaxes the constraints, it is likely to be more difficult to solve than the time complexity of all NPC problems.
Don't think NPC questions are a piece of paper. NPC problem is there. It is true that a very specific problem belongs to NPC. It will be introduced later.
The following is an introduction to the logic circuit problem. This is the first NPC question. The question of other NPCs is the problem. Therefore, the problem of logic circuit is the "originator" of NPC class problem.
A logic circuit problem is a problem: given a logic circuit, ask if there is an input to make the output true.
What is a logic circuit? A logic circuit consists of several inputs, an output, several "logic gates" and a dense line. Take a look at the following example, and you'll understand without explaining it.
┌───┐
│ Input 1├─→┐┌──┐
└───┘└─→┤│
│or├→─┐
┌───┐┌─→┤││┌──┐
│ Input 2├─→┤└──┘└─→┤│
&
nbsp;└───┘│┌─→┤and├──→ Output
└────────┘┌→┤│
┌───┐┌──┐│└──┘
│ Input 3├─→┤not├─→────┘
└───┘└──┘
This is a simpler logic circuit, when input 1, input 2, input 3 is True, True, False or False, True, FALSE, the output is true.
Is there a logic circuit in which output cannot be true anyway? Yes. Here is a simple example.
┌───┐
│ Input 1├→─┐┌──┐
└───┘└─→┤│
│and├─→┐
┌─→┤││
│└──┘│┌──┐
│└→┤│
┌───┐││and├─→ Output
│ Input 2├→─┤┌──┐┌→┤│
└───┘└→┤not├→──┘└──┘
└──┘
In the above logic circuit, the output is false regardless of the input. We say that this logic circuit does not exist a set of inputs that make the output true.
Back to the above, given a logic circuit, ask if there is an input to make the output true, which is the logic circuit problem.
Logic circuit problem belongs to NPC problem. There is a strict proof of this. It obviously belongs to the NP problem, and can directly prove that all NP problems can be reduced to it (do not think that the NP problem has an infinite number of problems will prove insurmountable difficulties). Proving that the process is quite complex, it probably means that the input and output of any NP problem can be converted into the input and output of the logic circuit (think of the internal computer is just some 0 and 1 operations), so for a NP problem, The problem is converted in order to find an input that satisfies the result as true (that is, a workable solution).
With the first NPC problem, a whole bunch of NPC questions came up, because proving a new NPC problem only requires a known NPC problem to be reduced to it. Later, Hamilton Loop became NPC problem, TSP problem also became NPC problem. It is now proved that there are many problems with NPC, and any NP problem can be solved perfectly if any one finds a polynomial algorithm. So it is because of the NPC problem that P=NP becomes unbelievable. There are a lot of interesting things to P=NP and we need to dig further. Climbing the pinnacle of this information science is the ultimate goal of our generation. What we need to do now, at least, is not to confuse the concept.
Transferred from Dalao article http://www.matrix67.com/blog/archives/105
A detailed explanation of P and NP problems