简体   繁体   中英

If these problems are NP-Complete, how are there polynomial time algorithms for solving them?

I'm studying P, NP, and NP-Complete problems and I've encountered some questions.

I understand that a problem is P if you can solve it in polynomial time, and a problem is NP if it is verifiable in polynomial time. I also understand that a problem is NP-Complete if it is NP and can be reduced from an existing NP-Complete problem.

I know that SAT, 3-SAT, Independent Set, Vertex Cover, Hamiltonian Cycle, Subset Sum, and Traveling Salesman are all NPC. But I encountered a problem where I was told that deciding whether an independent set of 5 vertices exists in a graph is actually polynomial time solvable instead of NPC. This then confused me because I thought independent set problems were NPC.

So then it made me wonder, in what scenarios are these "NPC" problems not NPC and are in fact P? When given a problem, how do I determine whether a problem is P or NPC? What if the problem does have a poly time solvable solution I just wasn't able to come up with it and therefore went down the NPC path. How do I know that I've made a mistake?

The problem of finding a maximal independent set of a graph is NP-hard, just like the travelling salesman problem. They are both optimisation problems, and they both involve enumerating a number of cases which is greater than polynomial in the input size.

Given a number k , and a graph of n vertices, the problem of finding an independent set of k vertices is a separate problem, for which there is a polynomial-time solution. This is not an optimisation problem.

The solution is bounded by the fact that there are at most C(n, k) subsets of five vertices, and for each subset, you need to check at most C(k, 2) edges. Each of these is polynomial in n for constant k .

deciding whether an independent set of 5 vertices exists in a graph is actually polynomial time solvable

Yes, deciding/finding independent sets of fixed size (or complementary, finding cliques of fixed size ) has a brute-force algorithm that is polynomial-time, usually something like n k with k being the fixed size - in your case n 5 .

However, the decision problem that is NP-complete is for arbitrary sizes, where k belongs to the input of the algorithm. Then it becomes exponential time. The parameterised complexity field analyses this further.

There is an analogy that might help you think about it, although it's not the same thing. There is a mathematical proof that you can't sort arbitrary length array in less than O(n*log(n)). However, if the input is "small" or if you know something about the input, for example, that it contains only k chars, then you can use other methods to solve it quicker, using O(n) algorithms (for example, Redix sort).

When we try to generalize the problem, as we don't have any previous knowledge about the input, things are harder (and sometimes, NP-Complete harder).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM