Http://blog.csdn.net/crfoxzl/article/details/2192957
NP is a type of problem in which the correctness of the solution can be checked in polynomial time. For example, if the array summation result is used to obtain a solution, is this solution correct? Obviously, it can be verified within the polynomial time. For example, if a solution is obtained for the SAT, the correctness can be verified within the polynomial time. Therefore, sat and summation are NP problems. Then, some NP problems can be found in polynomial time, such as array summation. This is a simple part of NP and is named P. The NP problem other than P is a problem that cannot be solved within polynomial time. Will one day, when Daniel invented the ox algorithm, all these problems will be solved within the polynomial time? That is to say, will all NP problems be P problems, but humans have not yet discovered them? NP = P?
It is conceivable that it is difficult to prove Np = P, because there are too many NP problems, and we need to find a polynomial algorithm one by one. At this time, Stephen A. Cook appeared, wrote the complexity of theorem proving procedures, and proposed the concept of NP-complete. NPC refers to the most difficult part of the NP problem. All NP problems can be reduced to NPC in polynomial time. The so-called reduction means that if A is reduced to B and B is easy to solve, A is easy to solve. Obviously, if any NPC problem is solved in polynomial time, all NP problems will become P problems, and Np = P will be proved, this greatly simplifies the process of proof. So how can we prove a problem C is an NP complete problem? First, it is necessary to prove that C is an NP problem, that is, the correctness of the C solution is easy to verify, and then it is necessary to prove that there is a NP complete Problem B, which can be reduced to C in polynomial time. This requires that at least one NPC problem exists first. At this time, cook daniu proved in 1971 that the ancestor of NP was sat. Sat is a logical formula that contains N Boolean variables. If a combination of values exists, the formula is satisfied. Cook proves that the SAT is an NPC problem. If the SAT is easy to solve, all NP will be easy to solve. How does cook do it?
He did it through an uncertain Turing machine. A non-deterministic Turing machine is a special type of Turing machine that can be guessed in polynomial time as long as there is a solution to the problem. Cook proves that the SAT summarizes all the constraints that must be met by the machine in the computing process. Any NP problem in the computing process on this machine can be described as an SAT problem. Therefore, if you have a good algorithm for solving the SAT, you can solve the computing problem of the non-deterministic Turing machine, because the NP problem is solved by Polynomials on the non-graphic machine, therefore, if you solve the SAT, you can solve all NP, so -- sat is a complete NP problem. Thanks to cook, we already have an issue with the NPC, and the rest is easy to handle. We can use the contract to prove it. At present, people have discovered thousands of NPC problems. To solve one problem, NP = P is the proof. You can win the Millennium Award (I think you can also get the Turing Award immediately ).
Someone must have asked, but there are still some problems beyond NP that cannot be solved by Polynomials even in verification solutions. These problems, even if Np = P, cannot be solved by Polynomials and are named NP-hard. NP-hard is too difficult. How to find a perfect girlfriend is the NP-hard problem. A np-hard problem can be reduced by an NP-complete problem. That is to say, if an NP-hard problem is solved, all NP-hard problems are solved.
NP-hardAndDifferences between NP-complete
PairNP-hardProblems andNP-completeAn intuitive understanding of the problem refers to the problems that are difficult (probably impossible) to find the polynomial time algorithm. Therefore, General beginners may ask the following question:NP-hardAndNP-completeWhat is the difference? The simple answer is as defined. If all NP problems can be reduced to question a by polynomial, question a isNP-hardIf question a is bothNP-hardIf it is NP, it isNP-complete. We can easily see from the definition,NP-hardThe question category includesNP-completeClass.NP-hardBut does not belongNP-completeQuestion? The answer is yes. for example, if a shutdown problem occurs, a program and input are provided to determine whether its operation will be terminated. the downtime problem cannot be determined, so it is certainly not an NP problem. but for SATNP-completeBut the polynomial can be reduced to the shutdown problem. because we can construct program A, which does not assign all values to the input formula. If a value is assigned to the input formula to make it true, it will be stopped; otherwise, it will enter an infinite loop. in this way, determining whether the formula can be met is converted to determining whether program a entered by the formula is out of service. so the downtime problem isNP-hardInsteadNP-complete.
Let me think about P/NP-complete/NP-hard at the risk of being attacked.
1. computing complexity
This is a metric describing the amount of time required by an algorithm. (There is also space complexity, but because they can be converted to each other, we usually talk about time complexity. For input whose size is N, we use a simplified formula containing N to express it. (The simplified formula is to ignore the coefficients and constants and retain only the largest part)
For example, to find the largest N number, it is very simple to compare the first number with the second one, the bigger one and the third one, and so on. In total, it is more than n-1, we record it as O (N) (-1 can be ignored if N can be very large ).
For example, we can find the number of N in the small to large rows that is equal to X. One method is to search from start to end in sequence. The best case is that the first one is X, and the worst case is to compare n
So the worst case computing complexity is O (n ). There is another way: first take the number in the middle and X
Comparison. If the value is too large, it is found in the first half. If the value is too small, it is found in the last half. Each time it is compared with the number in the middle, the worst case is
LG (N)/lg2. The algorithm complexity is O (lgn ).
2. Sort computing complexity:
Based on N
The expressions of can be sorted by 1 <lg (n) <n <NLG (n) <n ^ 2 <
... <N ^ K (K is a constant) <... <2 ^ n. N of the last 2
The power of power is the growth of the series. People who have read the story of wheat grains on the board know how fast this growth rate is. And those earlier are all N
The complexity of polynomial time. Why do we ignore all coefficients and constants here, for example, 2 * n ^ 3 + 9 * n ^ 2 can be simplified
N ^ 3? I forgot the exact statement when I explained everything in the set. If you still remember calculus, think about it (2 * n ^ 3 + 9 * n ^ 2)/(n ^ 3)
The result is 0, no difference, right?
2. P: For a problem, any algorithm that can find the computational complexity can be expressed as a polynomial is a problem of P (polynomial.
3. NP problems:
N in NP refers to a non-terministic algorithm. This is an algorithm: (1) Guess an answer. (2) Verify that the answer is correct. (3) If there is a verification and the answer is correct, the algorithm will obtain the solution.
NP (non-deterministic polynomial) is an algorithm that uses such an uncertain algorithm to verify the computational complexity of STEP (2) with polynomial time.
4. Problem reduction:
This ...... What terms should I use to explain it? Set? It's hard to say ...... If you still remember the function ing, it would be easier to imagine.
This is roughly the case: Find the correspondence between all inputs in question 1 and all inputs in question 2. If yes, all outputs in question 2 can correspond to all outputs in question 1, if we find the solution to problem 2, we can get the solution of Problem 1 through the correspondence between input and output. Therefore, we can contract Question 1 to question 2.
5, NP-hard:
There is such a problem that all NP problems can be reduced to this problem, which we call NP-hard.
6. NP-complete ):
If a problem is both an NP problem and an NP-hard problem, it is an NP-complete problem. The epsilience problem is an NP-complete problem. In addition, the famous graph dyeing, Hamilton ring, backpack, and orang problems are all NP-complete problems.
Intuitively, P <= NP-complete <= NP-hard increases the difficulty of the problem. However, it can only be proved that P belongs to NP. It is still unknown whether P = NP or P is actually included in NP.