Questions tagged [np-complete]

NP-Complete refers to the hardest known problems within the complexity class NP. The "Traveling salesman problem" is one of the most widely known NP-Complete problems.

The classic method of attacking NP-complete problems is to try and prove that P = NP. Once a PTIME solution has been proven to exist for at least one NP-complete problem, that could be used to solve all of the others via reduction.

This is an active area of research. Communications of the ACM Volume 52, Number 9 (2009), Pages 78-86: The Status of the P vs NP Problem gives a good overview of the problem and current approaches to resolving it. (The article is freely available here.)

Apart from that, there are some approaches that can be used to get useful—although not optimal—solutions to NP-complete problems in practice:

  • Brute force
  • Heuristics that produce "reasonably good" results most of the time
  • Arbitrary approximation algorithms that can produce increasingly better solutions the longer they are allowed to run
  • Genetic algorithms, which try to find multiple "reasonably good" solutions and then "mutate" these solutions to get even better solutions.
340 questions
1409
votes
12 answers

What are the differences between NP, NP-Complete and NP-Hard?

What are the differences between NP, NP-Complete and 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 from what's out there, or there is something that I'm not…
DarthVader
  • 52,984
  • 76
  • 209
  • 300
505
votes
14 answers

What is an NP-complete in computer science?

What is an NP-complete problem? Why is it such an important topic in computer science?
Claudiu
  • 224,032
  • 165
  • 485
  • 680
270
votes
6 answers

What's "P=NP?", and why is it such a famous question?

The question of whether P=NP is perhaps the most famous in all of Computer Science. What does it mean? And why is it so interesting? Oh, and for extra credit, please post a proof of the statement's truth or falsehood. :)
raldi
  • 21,344
  • 33
  • 76
  • 86
45
votes
15 answers

Solving the NP-complete problem in XKCD

The problem/comic in question: http://xkcd.com/287/ I'm not sure this is the best way to do it, but here's what I've come up with so far. I'm using CFML, but it should be readable by anyone.
Adam Tuttle
  • 19,505
  • 17
  • 80
  • 113
32
votes
2 answers

how were the first NP-complete problems shown to be NP-complete?

From the wikipedia entry on NP-Complete: "The easiest way to prove that some new problem is NP-complete is first to prove that it is in NP, and then to reduce some known NP-complete problem to it" I'm pretty sure that I understand this: If I have a…
brad
  • 2,221
  • 3
  • 24
  • 26
26
votes
10 answers

Tricky programming problem that I'm having trouble getting my head around

First off, let me say that this is not homework (I am an A-Level student, this is nothing close to what we problem solve (this is way harder)), but more of a problem I'm trying to suss out to improve my programming logic. I thought of a scenario…
Phox
  • 499
  • 3
  • 9
  • 12
25
votes
14 answers

Algorithm to Divide a list of numbers into 2 equal sum lists

There is a list of numbers. The list is to be divided into 2 equal sized lists, with a minimal difference in sum. The sums have to be printed. #Example: >>>que = [2,3,10,5,8,9,7,3,5,2] >>>make_teams(que) 27 27 Is there an error in the following…
lprsd
  • 84,407
  • 47
  • 135
  • 168
23
votes
2 answers

Is this problem NP, and does it have a name?

This problem came up in the real world, but I've translated it into a more generic "textbook-like" formulation. I suspect it is NP, but I'm particularly interested in knowing if it has a name or is well known since I think I can't be the first one…
itub
  • 1,145
  • 1
  • 10
  • 11
21
votes
14 answers

Is it correct to ask to solve an NP-complete problem on a job interview?

Today there was a question on SO, where the author was given an NP-complete problem during an interview and he obviously hadn't been told that it was one. What is the purpose of asking such questions? What behavior does the interviewer expect when…
P Shved
  • 96,026
  • 17
  • 121
  • 165
20
votes
6 answers

Are all scheduling problems NP-Hard?

I know there are some scheduling problems out there that are NP-hard/NP-complete ... however, none of them are stated in such a way to show this situation is also NP. If you have a set of tasks constrained to a startAfter, startBy, and duration all…
17
votes
3 answers

Is the board game "Go" NP complete?

There are plenty of Chess AI's around, and evidently some are good enough to beat some of the world's greatest players. I've heard that many attempts have been made to write successful AI's for the board game Go, but so far nothing has been…
sharkin
  • 12,162
  • 24
  • 86
  • 122
14
votes
6 answers

Algorithm to find which numbers from a list of size n sum to another number

I have a decimal number (let's call it goal) and an array of other decimal numbers (let's call the array elements) and I need to find all the combinations of numbers from elements which sum to goal. I have a preference for a solution in C# (.Net…
Sam Meldrum
  • 13,835
  • 6
  • 33
  • 40
14
votes
5 answers

Non-exponential solution to finding all the values in a maze problem?

Given a n*n-sized multi-headed acyclic graph where each node has at most three children and three parents, is there an non-exponential algorithm to identify whether a n-length path exists where no two nodes share the same value, and every value of a…
Mike Douglas
  • 3,345
  • 2
  • 28
  • 30
12
votes
2 answers

Prove NP-Completeness clique + independent set graph

"Prove that it is NP-Complete to determine given input G and k whether G has both a clique of size k and an independent set of size k. Note that this is 1 problem, not 2; the answer is yes if and only if G has both of these subsets." We were given…
irtemed88
  • 333
  • 1
  • 3
  • 11
12
votes
5 answers

NP-Complete VS NP-Hard

I am trying to understand the difference between NP-Complete and NP-Hard. Below is my understanding An NP-Hard problem is one that is not solvable in polynomial time but can be verified in polynomial time. An NP-Complete problem is one that is…
ade19
  • 1,150
  • 4
  • 13
  • 28
1
2 3
22 23