What is P problem, NP problem and NPC problem

What is P problem, NP problem and NPC problem

    This may be one of the biggest misunderstandings of many OIers.
    You will often see words such as "how to do this, isn't this an NP problem", "this is only a search, and this has been proven to be an NP problem" on the Internet. You need to know that what most people are talking about at this time is the NP problem actually refers to the NPC problem. They didn't figure out the concept of NP problem and NPC problem. The NP problem is not the kind of "search only" problem, the NPC problem is. OK, okay, basically this misunderstanding has been cleared up. The following content is about what is the P problem, what is the NP problem, and what is the NPC problem. If you are not very interested, you can skip it. Next you can see how wrong it is to think of an NP problem as an NPC problem.

    Let's briefly explain the time complexity in a few sentences. Time complexity does not represent how long a program takes to solve a problem, but how quickly the length of time the program takes grows as the problem scales. That is to say, for a computer that processes data at high speed, the efficiency of processing a specific data cannot be a measure of the quality of a program, but should see whether the program running time remains the same when the size of the data increases to hundreds of times. , or it is also hundreds of times slower, or tens of thousands of times slower. No matter how big the data is, the processing time of the program is always so much, we say that this program is very good and has O(1) time complexity, also known as constant-level complexity; how big the data scale becomes, the more time it takes How long the time also becomes, the time complexity of this program is O(n), such as finding the maximum value of n numbers; and like bubble sort, insertion sort, etc., the data is expanded by 2 times, and the time is slowed down by 4 times, which belongs to the complexity of O(n^2). There are also some exhaustive algorithms, and the time required increases in geometric order, which is the exponential complexity of O(a^n), or even the factorial complexity of O(n!). There will be no O(2*n^2) complexity, because the previous "2" is a coefficient, which will not affect the time growth of the entire program at all. Similarly, the complexity of O(n^3+n^2) is also the complexity of O(n^3). Therefore, we would say that a program of O(0.01*n^3) is less efficient than O(100*n^2), although the former is better than the latter when n is small, but the latter time As the data size grows slowly, eventually the complexity of O(n^3) will be much more than O(n^2). We also say that the complexity of O(n^100) is less than the complexity of O(1.01^n).
    It is easy to see that the previous types of complexity are divided into two levels, where the complexity of the latter is far greater than the former in any case: one is O(1), O(log(n)), O(n ^a), etc., we call it polynomial-level complexity because its scale n appears in the base; the other is O(a^n) and O(n!) type complexity, which is non-polynomial level , the complexity of which computers often cannot afford. When we are solving a problem, the algorithm we choose usually requires polynomial complexity, and non-polynomial complexity takes too much time and often times out, unless the data size is very small.

    Naturally, one would think of a question: will all problems be able to find an algorithm with a complexity of the polynomial level? Unfortunately, the answer is no. Some problems are not even possible to find a correct algorithm, this is called "unsolvable problem" (Undecidable Decision Problem). The Halting Problem is a famous unsolvable problem, which has been specially introduced and proved on my Blog. For another example, output the full permutation of n numbers from 1 to n. No matter what method you use, your complexity is factorial, because you have to print out the result in factorial time. Some people say that such a "problem" is not a "regular" problem, that a regular problem is to have a program solve a problem and output a "YES" or "NO" (this is called a decision problem), or something optimal value (this is called an optimization problem). Then, with this definition, I can also cite a problem that is unlikely to have polynomial-level algorithms: Hamiltonian circuits. The problem is this: given a graph, ask if you can find a path that goes through each vertex exactly once (no omissions and no repetitions) and comes back (a path that satisfies this condition is called a Hamiltonian circuit). No polynomial-level algorithm has yet been found for this problem. In fact, this problem is the NPC problem we will talk about later.

    The concept of class P problems is introduced below: if a problem can find an algorithm that can solve it in polynomial time, then the problem is a P problem. P is the first letter of the English word polynomial. Which problems are P-type problems? Usually NOIs and NOIPs do not have questions that are not P-type questions. Some of the topics we often see in the Information Olympiad are P questions. The reason is simple, a timeout program that trades exhaustive for non-polynomial time will not cover any worthwhile algorithm.
    Next, the concept of NP problem is introduced. This is a bit difficult to understand, or easy to understand wrong. To emphasize here (back to the misunderstanding I'm trying to clear up), NP problems are not non-P problems. An NP problem is one for which a solution can be verified in polynomial time. Another definition of an NP problem is one for which a solution can be guessed in polynomial time. For example, my RP is very good, and when enumeration is required in the program, I can make a guess. Now someone has a shortest path problem, asking if there is a route that is less than 100 units long from the start point to the end point. It drew a picture based on the data, but it couldn't figure it out, so it came to me and asked me: How do you think you can choose the path that takes the least amount of time? I said, my RP is very good, I can definitely give you a short way out. Then I just randomly drew a few lines and said this is it. The man added up the weights according to the one I pointed to, hey, God, the path length is 98, which is less than 100. So the answer came out, there is a path smaller than 100. Others will ask him how he came up with this problem, and he can say, because I found a solution smaller than 100. In this problem, finding a solution is difficult, but verifying a solution is easy. Verifying a solution only takes O(n) time complexity, which means I can add up the length of the path I guessed in O(n) time. Well, as long as my RP is good and I guess right, I can definitely solve this problem in polynomial time. The solution I guess is always the best, and the solution that does not satisfy the meaning of the question will not trick me into choosing it. This is the NP problem. Of course there are problems that are not NP problems, i.e. you guessed to understand but useless because you can't verify it in polynomial time. The example I'm going to give below is a classic example of a problem for which there is currently no way to verify a solution in polynomial time. Obviously, the Hamilton circuit described above is an NP problem, because it is very easy to verify that a path passes exactly every vertex. But I'm going to change the question to this: ask if there are no Hamiltonian circuits in a graph. This way the problem cannot be verified in polynomial time, because unless you've tried all the ways, you can't say it "has no Hamilton circuit".
    The NP problem is defined because it is usually only possible to find an algorithm for a polynomial with an NP problem. We wouldn't expect a polynomial-level algorithm to solve a problem that doesn't even polynomially verify a solution. I believe readers will soon understand that the so-called most difficult problem in informatics - "NP problem" is actually discussing the relationship between NP problems and P-type problems.

    Obviously, all P-type problems are NP problems. That is to say, if a problem can be solved polynomially, the solution of a problem must be verified polynomially—since all the positive solutions have come out, the verification of any given solution only needs to be compared. The point is, one wonders if all NP problems are P problems. We can again use the point of view of sets to illustrate. If all P-type problems are classified into a set P, and all NP problems are classified into another set NP, then obviously there are P belonging to NP. Now, all research on NP problems is focused on the question, is there any P=NP at all? The so-called "NP problem" is actually just one sentence: to prove or disprove P=NP.
    NP problems have always been the pinnacle of informatics. Pinnacle, which means compelling but intractable. In informatics research, this is an ultimate
problem , such as the grand unification in physics and the Goldbach conjecture in mathematics.
    So far this issue has not been "bitten". However, there is a general trend and a general direction. It is widely believed that P = NP does not hold, that is, most people believe that there is an NP problem for which at least one algorithm with polynomial complexity is not possible. There is a reason why people believe that P≠NP, that is, in the process of studying NP problems, a very special kind of NP problem is found called NP-complete problem, also known as NPC problem. C is the first letter of the English word "completely". It is the existence of the NPC problem that makes people believe that P≠NP. The following section will spend a lot of time on the NPC problem, from which you can appreciate how incredible the NPC problem makes P=NP.

    In order to explain the NPC problem, we first introduce a concept - reduction (Reduction, some materials are called "reduction").
    Simply put, the meaning that a problem A can be reduced to problem B is that problem A can be solved by the solution of problem B, or that problem A can "become" problem B. An example of this is given in Introduction to Algorithms. For example, there are now two problems: solving a linear equation in one variable and solving a quadratic equation in one variable. Then we say that the former can be reduced to the latter, which means that if you know how to solve a quadratic equation in one variable, you must be able to solve a quadratic equation in one variable. We can write two programs corresponding to two problems respectively, then we can find a "rule", according to this rule, change the input data of the program for solving one-dimensional linear equation and use it in the program for solving one-dimensional quadratic equation, two The program always gives the same result. This rule is: the coefficients of the corresponding terms of the two equations are unchanged, and the coefficient of the quadratic term of the quadratic equation of one variable is 0. According to this rule, the former question is transformed into the latter question, and the two questions are equivalent. Similarly, we can say that the Hamilton circuit can be reduced to the TSP problem (Travelling Salesman Problem): In the Hamilton circuit problem, two points are connected, that is, the distance between the two points is 0, and if the two points are not directly connected, let it be The distance is 1, so the problem turns into whether there is a path of length 0 in the TSP problem. Hamiltonian cycles exist if and only if there is a cycle of length 0 in the TSP problem.
    "Problem A can be reduced to problem B" has an important intuitive meaning: the time complexity of B is higher than or equal to that of A. That is, problem A is no harder than problem B. It's easy to understand. Since problem A can be solved by problem B, if the time complexity of B is lower than that of A, then the algorithm of A can be improved to the algorithm of B, and the time complexity of the two is still the same. Just as solving quadratic equations in one variable is harder than solving linear equations in one variable, the same method used to solve the former can be used to solve the latter.
    Obviously, reduction has an important property: reduction is transitive. If problem A can be reduced to problem B, and problem B can be reduced to problem C, then problem A must be reduced to problem C. This principle is so simple that it does not need to be explained.
    Now let's talk about the standard concept of reduction, it is not difficult to understand: if we can find such a change rule, the input of any program A can be transformed into the input of program B according to this rule, 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, when we say "reducible", we mean "polynomially" reducible (Polynomial-time Reducible), that is, the method of transforming the input can be completed in polynomial time. The reduction process only makes sense if it is done in polynomial time.

    Well, from the definition of reduction, we can see that one problem is reduced to another problem, the time complexity increases, and the application scope of the problem also increases. Through the continuous reduction of certain problems, we can continue to find algorithms with higher complexity but wider application range to replace algorithms with low complexity but only for a small class of problems. Recalling the P and NP problems mentioned earlier, and thinking of the transitivity of reduction, naturally, we would like to ask, if we continue to reduce, we can continue to find a slightly more complex big problem that can "take all" several small NP problems. NP problem, then is it possible to find such a super NP problem with the highest time complexity and can "take all" all NP problems? The answer is actually yes. That is, there is an NP problem to which all NP problems can be reduced. In other words, as long as this problem is solved, then all NP problems are solved. The existence of this kind of problem is incredible, and even more incredible is that there is not only one such problem, there are many, it is a kind of problem. This type of problem is the so-called NPC problem, or NP-complete problem. The emergence of the NPC problem has made the research of the whole NP problem develop by leaps and bounds. We have reason to believe that the NPC problem is the most complex problem. Going back to the beginning of the text again, we can see that when people want to express an efficient algorithm for a problem that does not exist polynomials, they should say that it "belongs to the NPC problem". At this point, my purpose has finally been achieved, and I have distinguished the NP problem from the NPC problem. So far, this article has written nearly 5,000 words. I admire that you can still see it here, and I also admire that you can write it here.

    The definition of the NPC problem is very simple. The problem that satisfies the following two conditions at the same time is the NPC problem. First, it has to be an NP problem; then, all NP problems can be reduced to it. Proving that a problem is an NPC problem is also simple. First prove that it is at least one NP problem, and then prove that one of the known NPC problems can be reduced to it (by the transitivity of the reduction, the second clause of the definition of the NPC problem is also satisfied; as for the first NPC problem is How come, will be introduced below), so it can be said that it is an NPC problem.
    Since all NP problems can be reduced to NPC problems, as long as any NPC problem finds a polynomial algorithm, then all NP problems can be solved by this algorithm, and NP is equal to P. So, finding a polynomial algorithm for an NPC is inconceivable. Therefore, the previous article said, "It is the existence of the NPC problem that makes people believe that P≠NP". We can intuitively understand that there is currently no effective polynomial algorithm for the NPC problem, and we can only search with exponential or even factorial complexity.

    By the way, let's talk about the NP-Hard problem. An NP-Hard problem is a problem that satisfies the second but not necessarily the first of the NPC problem definition (that is, NP-Hard problems are broader in scope than NPC problems). The NP-Hard problem is equally difficult to find an algorithm for polynomials, but it is not included in our scope because it is not necessarily an NP problem. Even if a polynomial-level algorithm is found for the NPC problem, the NP-Hard problem may still fail to obtain a polynomial-level algorithm. In fact, since NP-Hard relaxes the constraints, it will likely be more time-complex and more difficult to solve than all NPC problems.

    Don't think that the NPC issue is a piece of paper. NPC problems exist. There is indeed such a very specific problem that belongs to the NPC problem. It will be introduced below.
    Logic circuit problems are discussed below. This is the first NPC question. All other NPC problems are reduced from this problem. Therefore, the logic circuit problem is the "ancestor" of the NPC-type problem.
    A logic circuit problem refers to a problem: given a logic circuit, ask if there is an input that makes the output True.
    What is a logic circuit? A logic circuit consists of several inputs, one output, several "logic gates" and densely packed wires. Take a look at the following example, you will understand immediately without explanation.
  ┌───┐
  │ Enter 1├─→┐ ┌──┐
  └───┘ └─→┤ │
                      │ or ├→─┐
  ┌───┐ ┌─→┤ │ │ ┌──┐
  │ Enter 2 ├─→┤ └──┘ └─→┤ │
 &
nbsp;└───┘ │ ┌─→┤AND ├──→output
                └────────┘┌→┤ │
  ┌─── ┐ ┌──┐ │ └──┘
  │ Input 3├─→┤ NOT├─→────┘
  └───┘ └──┘

    This is a relatively simple logic circuit, when input 1, input 2, When input 3 is True, True, False or False, True, False, respectively, the output is True.
    Is there a logic circuit whose output can't possibly be True anyway? have. Below is a simple example.
  ┌───┐ │Enter
  1 ├→─┐ ┌──┐ └───┘
  └─→┤ │
                      │AND ├─→┐
                ┌─→┤ │ │
                │ └──┘ │ ┌──┐
                │ └ →┤ │
  ┌───┐ │ │AND ├─
  →output│input2 ├→─┤ ┌──┐ ┌→┤ │
  └───┘ └→┤NOT ├→──┘ └──┘
                    └─ ─┘ In

    the above logic circuit, no matter what the input is, the output is False. Let's just say that this logic circuit does not have a set of inputs that make the output True.
    Back to the above, given a logic circuit, ask whether there is an input that makes the output True, this is the logic circuit problem.
    Logic circuit problems are NPC problems. This is strictly proved. It is clearly an NP problem, and it is straightforward to prove that all NP problems can be reduced to it (don't think that an infinite number of NP problems will make the proof insurmountable). The proof process is quite complicated, which roughly means that the input and output of any NP problem can be converted into the input and output of a logic circuit (think that the computer is just some operations of 0 and 1), so for an NP problem to Say, the problem turns into finding an input (ie, a feasible solution) that satisfies the result of True.

    With the first NPC problem, a whole bunch of NPC problems arise, because proving a new NPC problem only requires reducing a known NPC problem to it. Later, the Hamilton circuit became an NPC problem, and the TSP problem became an NPC problem. There are many NPC problems that have been proved to be NPC problems. If any one finds a polynomial algorithm, all NP problems can be solved perfectly. Therefore, it is precisely because of the existence of the NPC problem that P=NP becomes implausible. There are still many interesting things about the P=NP problem, which need to be further explored by everyone. Climbing the pinnacle of this informatics is the ultimate goal of our generation. Now what we need to do, at least not confuse the concepts.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324495748&siteId=291194637