principleCritical
What is the definition of P, NP, NP-complete and NP-hard?
Viewed 0 times
definitionthewhathardcompleteand
Problem
I'm in a course about computing and complexity, and am unable to understand what these terms mean.
All I know is that NP is a subset of NP-complete, which is a subset of NP-hard, but I have no idea what they actually mean. Wikipedia isn't much help either, as the explanations are still a bit too high level.
All I know is that NP is a subset of NP-complete, which is a subset of NP-hard, but I have no idea what they actually mean. Wikipedia isn't much help either, as the explanations are still a bit too high level.
Solution
I think the Wikipedia articles
$\mathsf{P}$, $\mathsf{NP}$, and $\mathsf{P}$ vs. $\mathsf{NP}$ are quite good.
Still here is what I would say: Part I, Part II
[I will use remarks inside brackets to discuss some technical details which
you can skip if you want.]
Part I
Decision Problems
There are various kinds of computational problems.
However in an introduction to computational complexity theory course
it is easier to focus on decision problem,
i.e. problems where the answer is either YES or NO.
There are other kinds of computational problems but
most of the time questions about them can be reduced to
similar questions about decision problems.
Moreover decision problems are very simple.
Therefore in an introduction to computational complexity theory course
we focus our attention to the study of decision problems.
We can identify a decision problem with the subset of inputs that
have answer YES.
This simplifies notation and allows us to write
$x\in Q$ in place of $Q(x)=YES$ and
$x \notin Q$ in place of $Q(x)=NO$.
Another perspective is that
we are talking about membership queries in a set.
Here is an example:
Decision Problem:
Input: A natural number $x$,
Question: Is $x$ an even number?
Membership Problem:
Input: A natural number $x$,
Question: Is $x$ in $Even = \{0,2,4,6,\cdots\}$?
We refer to the YES answer on an input as accepting the input and
to the NO answer on an input as rejecting the input.
We will look at algorithms for decision problems and
discuss how efficient those algorithms are in their usage of computable resources.
I will rely on your intuition from programming in a language like C
in place of formally defining what we mean by an algorithm and computational resources.
[Remarks:
we would need to fix a model of computation like the standard Turing machine model
to precisely define what we mean by an algorithm and
its usage of computational resources.
the model cannot directly handle,
we would need to encode them as objects that the machine model can handle,
e.g. if we are using Turing machines
we need to encode objects like natural numbers and graphs
as binary strings.]
$\mathsf{P}$ = Problems with Efficient Algorithms for Finding Solutions
Assume that efficient algorithms means algorithms that
use at most polynomial amount of computational resources.
The main resource we care about is
the worst-case running time of algorithms with respect to the input size,
i.e. the number of basic steps an algorithm takes on an input of size $n$.
The size of an input $x$ is $n$ if it takes $n$-bits of computer memory to store $x$,
in which case we write $|x| = n$.
So by efficient algorithms we mean algorithms that
have polynomial worst-case running time.
The assumption that polynomial-time algorithms capture
the intuitive notion of efficient algorithms is known as Cobham's thesis.
I will not discuss at this point
whether $\mathsf{P}$ is the right model for efficiently solvable problems and
whether $\mathsf{P}$ does or does not capture
what can be computed efficiently in practice and related issues.
For now there are good reasons to make this assumption
so for our purpose we assume this is the case.
If you do not accept Cobham's thesis
it does not make what I write below incorrect,
the only thing we will lose is
the intuition about efficient computation in practice.
I think it is a helpful assumption for someone
who is starting to learn about complexity theory.
$\mathsf{P}$ is the class of decision problems that can be solved efficiently,
i.e. decision problems which have polynomial-time algorithms.
More formally, we say a decision problem $Q$ is in $\mathsf{P}$ iff
there is an efficient algorithm $A$ such that
for all inputs $x$,
I can simply write $A(x)=Q(x)$ but
I write it this way so we can compare it to the definition of $\mathsf{NP}$.
$\mathsf{NP}$ = Problems with Efficient Algorithms for Verifying Proofs/Certificates/Witnesses
Sometimes we do not know any efficient way of finding the answer to a decision problem,
however if someone tells us the answer and gives us a proof
we can efficiently verify that the answer is correct
by checking the proof to see if it is a valid proof.
This is the idea behind the complexity class $\mathsf{NP}$.
If the proof is too long it is not really useful,
it can take too long to just read the proof
let alone check if it is valid.
We want the time required for verification to be reasonable
in the size of the original input,
not the size of the given proof!
This means what we really want is not arbitrary long proofs but short proofs.
Note that if the verifier's running time is polynomial
in the size of the original input
then it can only read a polynomial part of the proof.
So by short we mean of polynomial size.
From this point on whenever I use the word "proof" I mean
$\mathsf{P}$, $\mathsf{NP}$, and $\mathsf{P}$ vs. $\mathsf{NP}$ are quite good.
Still here is what I would say: Part I, Part II
[I will use remarks inside brackets to discuss some technical details which
you can skip if you want.]
Part I
Decision Problems
There are various kinds of computational problems.
However in an introduction to computational complexity theory course
it is easier to focus on decision problem,
i.e. problems where the answer is either YES or NO.
There are other kinds of computational problems but
most of the time questions about them can be reduced to
similar questions about decision problems.
Moreover decision problems are very simple.
Therefore in an introduction to computational complexity theory course
we focus our attention to the study of decision problems.
We can identify a decision problem with the subset of inputs that
have answer YES.
This simplifies notation and allows us to write
$x\in Q$ in place of $Q(x)=YES$ and
$x \notin Q$ in place of $Q(x)=NO$.
Another perspective is that
we are talking about membership queries in a set.
Here is an example:
Decision Problem:
Input: A natural number $x$,
Question: Is $x$ an even number?
Membership Problem:
Input: A natural number $x$,
Question: Is $x$ in $Even = \{0,2,4,6,\cdots\}$?
We refer to the YES answer on an input as accepting the input and
to the NO answer on an input as rejecting the input.
We will look at algorithms for decision problems and
discuss how efficient those algorithms are in their usage of computable resources.
I will rely on your intuition from programming in a language like C
in place of formally defining what we mean by an algorithm and computational resources.
[Remarks:
- If we wanted to do everything formally and precisely
we would need to fix a model of computation like the standard Turing machine model
to precisely define what we mean by an algorithm and
its usage of computational resources.
- If we want to talk about computation over objects that
the model cannot directly handle,
we would need to encode them as objects that the machine model can handle,
e.g. if we are using Turing machines
we need to encode objects like natural numbers and graphs
as binary strings.]
$\mathsf{P}$ = Problems with Efficient Algorithms for Finding Solutions
Assume that efficient algorithms means algorithms that
use at most polynomial amount of computational resources.
The main resource we care about is
the worst-case running time of algorithms with respect to the input size,
i.e. the number of basic steps an algorithm takes on an input of size $n$.
The size of an input $x$ is $n$ if it takes $n$-bits of computer memory to store $x$,
in which case we write $|x| = n$.
So by efficient algorithms we mean algorithms that
have polynomial worst-case running time.
The assumption that polynomial-time algorithms capture
the intuitive notion of efficient algorithms is known as Cobham's thesis.
I will not discuss at this point
whether $\mathsf{P}$ is the right model for efficiently solvable problems and
whether $\mathsf{P}$ does or does not capture
what can be computed efficiently in practice and related issues.
For now there are good reasons to make this assumption
so for our purpose we assume this is the case.
If you do not accept Cobham's thesis
it does not make what I write below incorrect,
the only thing we will lose is
the intuition about efficient computation in practice.
I think it is a helpful assumption for someone
who is starting to learn about complexity theory.
$\mathsf{P}$ is the class of decision problems that can be solved efficiently,
i.e. decision problems which have polynomial-time algorithms.
More formally, we say a decision problem $Q$ is in $\mathsf{P}$ iff
there is an efficient algorithm $A$ such that
for all inputs $x$,
- if $Q(x)=YES$ then $A(x)=YES$,
- if $Q(x)=NO$ then $A(x)=NO$.
I can simply write $A(x)=Q(x)$ but
I write it this way so we can compare it to the definition of $\mathsf{NP}$.
$\mathsf{NP}$ = Problems with Efficient Algorithms for Verifying Proofs/Certificates/Witnesses
Sometimes we do not know any efficient way of finding the answer to a decision problem,
however if someone tells us the answer and gives us a proof
we can efficiently verify that the answer is correct
by checking the proof to see if it is a valid proof.
This is the idea behind the complexity class $\mathsf{NP}$.
If the proof is too long it is not really useful,
it can take too long to just read the proof
let alone check if it is valid.
We want the time required for verification to be reasonable
in the size of the original input,
not the size of the given proof!
This means what we really want is not arbitrary long proofs but short proofs.
Note that if the verifier's running time is polynomial
in the size of the original input
then it can only read a polynomial part of the proof.
So by short we mean of polynomial size.
From this point on whenever I use the word "proof" I mean
Context
StackExchange Computer Science Q#9556, answer score: 462
Revisions (0)
No revisions yet.