Questions tagged [np]

NP ("nondeterministic polynomial") is a complexity class of decision problems that can be solved by a nondeterministic Turing machine in polynomial time. Equivalently, it is the set of decision problems for which an answer can be verified in polynomial time by a deterministic Turing machine.

NP (nondeterministic polynomial-time) is a complexity class of decision problems that can be solved by a nondeterministic Turing machine in polynomial time. Equivalently, it is the set of decision problems for which an answer can be verified in polynomial time by a deterministic Turing machine.

For example:

  • 3-Colorability: Given a graph, can each vertex be colored red, green, or blue so that no two neighboring vertices have the same color?
  • Hamiltonian Cycle: Given a graph, is there a cycle that visits each vertex exactly once?
  • Traveling Salesperson: Given a set of n cities, and the distance between each pair of cities, is there a route that visits each city exactly once before returning to the starting city, and has length at most T?
  • Maximum Clique: Given a graph, are there k vertices all of which are neighbors of each other?
  • Subset Sum: Given a collection of integers, is there a subset of the integers that sums to exactly

References

466 questions
1203
votes
11 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
  • 46,241
  • 67
  • 190
  • 289
98
votes
16 answers

Algorithm for creating a school timetable

I've been wondering if there are known solutions for algorithm of creating a school timetable. Basically, it's about optimizing "hour-dispersion" (both in teachers and classes case) for given class-subject-teacher associations. We can assume that…
cand
  • 2,441
  • 2
  • 16
  • 13
32
votes
6 answers

Sum-subset with a fixed subset size

The sum-subset problem states: Given a set of integers, is there a non-empty subset whose sum is zero? This problem is NP-complete in general. I'm curious if the complexity of this slight variant is known: Given a set of integers, is there a…
PengOne
  • 47,332
  • 17
  • 126
  • 147
28
votes
1 answer

Proof that the halting problem is NP-hard?

In this answer to a question about the definitions of NP, NP-hard, and NP-complete, Jason makes the claim that The halting problem is the classic NP-hard problem. This is the problem that given a program P and input I, will it halt? This is a…
templatetypedef
  • 328,018
  • 92
  • 813
  • 992
27
votes
1 answer

I need to solve an NP-hard problem. Is there hope?

There are a lot of real-world problems that turn out to be NP-hard. If we assume that P ≠ NP, there aren't any polynomial-time algorithms for these problems. If you have to solve one of these problems, is there any hope that you'll be able to do so…
templatetypedef
  • 328,018
  • 92
  • 813
  • 992
25
votes
1 answer

What is fixed-parameter tractability? Why is it useful?

Some problems that are NP-hard are also fixed-parameter tractable, or FPT. Wikipedia describes a problem as fixed-parameter tractable if there's an algorithm that solves it in time f(k) · |x|O(1). What does this mean? Why is this concept useful?
templatetypedef
  • 328,018
  • 92
  • 813
  • 992
16
votes
8 answers

Generate equation with the result value closest to the requested one, have speed problems

I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available…
Saša Šijak
  • 7,295
  • 5
  • 41
  • 74
13
votes
3 answers

What are NP and NP-complete problems?

I am struggling to understand what are nondeterministic polynomial-time problems and NP-complete problems. I understand what polynomial-time solvable problems are, and saw in Wikipedia about NP problems. After reading about this I tried to think…
Mr.Anubis
  • 4,824
  • 5
  • 27
  • 43
13
votes
1 answer

Why is factoring in NP, but not in P?

Factoring: Gven an integer N, find integers 1 < a, b < N such that N = ab if they exist, otherwise say N is prime. I know that primality testing is in P, but why not factoring? Here is my algorithm: For each a = 1 ... sqrt(N) if(N % a == 0) …
Nayana
  • 1,321
  • 3
  • 18
  • 32
13
votes
2 answers

Why is P ⊆ co-NP?

I've seen several places that have simply stated that it's known that P is a subset of the intersection of NP and co-NP. Proofs that show that P is a subset of NP are not hard to find. So to show that it's a subset of the intersection, all that's…
golmschenk
  • 9,361
  • 17
  • 69
  • 117
12
votes
3 answers

Unit Testing Approximation Algorithms

I'm working on an open-source approximation algorithms library for graphs and networks using some popular python packages as a base. The main goal is to encompass up-to-date approximation algorithms for NP-Complete problems over graphs and networks.…
Nicholas Mancuso
  • 11,065
  • 6
  • 42
  • 46
11
votes
3 answers

The complexity of verifying solutions to NP-hard optimization problems?

There are many optimization problems that are known to be NP-hard, such as the traveling salesman problem, MAX-SAT, or finding the minimum chromatic number of a graph. Given a problem of this sort, I'm curious about the complexity of the following…
templatetypedef
  • 328,018
  • 92
  • 813
  • 992
10
votes
3 answers

Whats the difference between NP and co-NP

I know their complete counterparts mean that NP - complete is the hardest in the NP problems and co-NP-complete means the hardest in co-NP problems but whats the difference between the two? My textbook said "The yes and no are reversed" which…
thedoublejointedprince
  • 3,660
  • 11
  • 48
  • 66
10
votes
5 answers

Is this solvable in polynomial (or pseudo-polynomial) time?

I'm trying to come up with a reasonable algorithm for this problem: Let's say you have a bunch of balls. Each ball has at least one color, but can also be multicolored. Each ball has a weight and a value associated with it. There are also a bunch of…
8
votes
1 answer

Are there decision problems which are decidable but not in NP?

this is my first stackoverflow question, so be gentle. I apologize in advance if this has been beaten to death already... I read a few threads on NP but I haven't found a tantalizing answer to my question (if anything, I came up with some new ones).…
aegrisomnia
  • 1,306
  • 1
  • 9
  • 6
1
2 3
31 32