ISNP2月14日是什么日子意思

Is the resolution problem in OSGi NP-Complete? - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
The resolution problem is described in the modularity chapter of the OSGi R4 . It's a constraint satisfaction problem and certainly a challenging
problem to solve efficiently, i.e. not by brute force. The main complications are the uses constraint, which has non-local effects, and the freedom to drop optional imports to obtain a successful resolution.
NP-Completeness is dealt with
on StackOverflow.
There has already been plenty of speculation about the answer to this question, so please avoid speculation. Good answers will include a proof or, failing that, a compelling informal argument.
The answer to this question will be valuable to those projects building resolvers for OSGi, including the Eclipse Equinox and Apache Felix open source projects, as well as to the wider OSGi community.
The approach taken by the
Pascal quoted can be made to work with OSGi. Below I’ll show how to reduce any 3-SAT instance to an OSGi bundle resolution problem. This site doesn’t seem to support mathematical notation, so I’ll use the kind of notation that’s familiar to programmers instead.
Here’s a definition of the 3-SAT problem we’re trying to reduce:
First define A to be a set of propositional atoms and their negations A = {a(1), … ,a(k),na(1), … ,na(k)}. In simpler language, each a(i) is a boolean and we define na(i)=!a(i)
Then 3-SAT instances S have the form:
S = C(1) & … & C(n)
where C(i) = L(i,1) | L(i,2) | L(i,3) and each L(i,j) is a member of A
Solving a particular 3-SAT instance involves finding a set of values, true or false for each a(i) in A, such that S evaluates to true.
Now let’s define the bundles we’ll be use to construct an equivalent resolution problem. In the following all bundle and package versions are 0 and import version ranges unrestricted except where specified.
The whole expression S will be represented by Bundle BS
Each clause C(i) will be represented by a bundle BC(i)
Each atom a(j) will be represented by a bundle BA(j) version 1
Each negated atom na(j) will be represented by a bundle BA(j) version 2
Now for the constraints, starting with the atoms:
BA(j) version 1
-export package PA(j) version 1
-for each clause C(i) containing atom a(j) export PM(i) and add PA(j) to PM(i)’s uses directive
BA(j) version 2
-export package PA(j) version 2
-for each clause C(i) containing negated atom na(j) export PM(i) and add PA(j) to PM(i)’s uses directive
-export PC(i)
-import PM(i) and add it to the uses directive of PC(i)
-for each atom a(j) in clause C(i) optionally import PA(j) version [1,1] and add PA(j) to the uses directive of the PC(i) export
-for each atom na(j) in clause C(i) optionally import PA(j) version [2,2] and add PA(j) to the uses directive of the PC(i) export
-no exports
-for each clause C(i) import PC(i)
-for each atom a(j) in A import PA(j) [1,2]
A few words of explanation:
The AND relationships between the clauses is implemented by having BS import from each BC(i) a package PC(i) that is only exported by this bundle.
The OR relationship works because BC(i) imports package PM(i) which is only exported by the bundles representing its members, so at least one of them must be present, and because it optionally imports some PA(j) version x from each bundle representing a member, a package unique to that bundle.
The NOT relationship between BA(j) version 1 and BA(j) version 2 is enforced by uses constraints. BS imports each package PA(j) without version constraints, so it must import either PA(j) version 1 or PA(j) version 2 for each j. Also, the uses constraints ensure that any PA(j) imported by a clause bundle BC(i) acts as an implied constraint on the class space of BS, so BS cannot be resolved if both versions of PA(j) appear in its implied constraints. So only one version of BA(j) can be in the solution.
Incidentally, there is a much easier way to implement the NOT relationship - just add the singleton:=true directive to each BA(j). I haven’t done it this way because the singleton directive is rarely used, so this seems like cheating. I’m only mentioning it because in practice, no OSGi framework I know of implements uses based package constraints properly in the face of optional imports, so if you were to actually create bundles using this method then testing them could be a frustrating experience.
Other remarks:
A reduction of 3-SAT that doesn't use optional imports in also possible, although this is longer. It basically involves an extra layer of bundles to simulate the optionality using versions. A reduction of 1-in-3 SAT is equivalent to a reduction to 3-SAT and looks simpler, although I haven't stepped through it.
Apart from proofs that use singleton:=true, all of the proofs I know about depend on the transitivity of uses constraints. Note that both singleton:=true and transitive uses are non-local constraints.
The proof above actually shows that the OSGi resolution problem is NP-Complete or worse. To demonstrate that it’s not worse we need to show that any solution to the problem can be verified in polynomial time. Most of the things that need to be checked are local, e.g. looking at each non-optional import and checking that it is wired to a compatible export. Verifying these is O(num-local-constraints). Constraints based on singleton:=true need to look at all singleton bundles and check that no two have the same bundle symbolic name. The number of checks is less than num-bundles*num-bundles. The most complicated part is checking that the uses constraints are satisfied. For each bundle this involves walking the uses graph to gather all of the constraints and then checking that none of these conflict with the bundle’s imports. Any reasonable walking algorithm would turn back whenever it encountered a wire or uses relationship it had seen before, so the maximum number of steps in the walk is (num-wires-in-framework + num-uses-in framework). The maximum cost of checking that a wire or uses relationship hasn't been walked before is less than the log of this. Once the constrained packages have been gathered the cost of the consistency check for each bundle is less than num-imports-in-bundle*num-exports-in-framework. Everything here is a polynomial or better.
This paper provides a demonstration:
From memory I thought this paper contained the demonstration, sorry for not checking that out before. Here is other link that I meant to copy that I'm sure provides a demonstration on page 48:
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledNPIS的海词问答与网友补充:
NPIS的相关资料:
相关词典网站:complexity theory - What is the definition of P, NP, NP-complete and NP-hard? - Computer Science Stack Exchange
to customize your list.
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. J it only takes a minute:
Here's how it works:
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
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.
isn't much help either, as the explanations are still a bit too high level.
12.4k53176
I think the Wikipedia articles
are quite good.
Still here is what I would say: ,
[I will use remarks inside brackets to discuss some technical details which
you can skip if you want.]
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.
1. If we wanted to do everything formally and precisely
we would need to fix a model of computation like the standard
to precisely define what we mean by an algorithm and
its usage of computational resources.
2. 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 .
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.
Form this point on whenever I use the word "proof" I mean "short proof".
Here is an example of a problem which
we do not know how to solve efficiently but
we can efficiently verify proofs:
Input: a finite set of natural numbers $S$,
Question: is it possible to partition $S$ into two sets $A$ and $B$
($A \cup B = S$ and $A \cap B = \emptyset$)
such that the sum of the numbers in $A$ is equal to the sum of number in $B$ ($\sum_{x\in A}x=\sum_{x\in B}x$)?
If I give you $S$ and
ask you if we can partition it into two sets such that
their sums are equal,
you do not know any efficient algorithm to solve it.
You will probably try all possible ways of
partitioning the numbers into two sets
until you find a partition where the sums are equal or
until you have tried all possible partitions and none has worked.
If any of them worked you would say YES, otherwise you would say NO.
But there are exponentially many possible partitions so
it will take a lot of time.
However if I give you two sets $A$ and $B$,
you can easily check if the sums are equal and
if $A$ and $B$ is a partition of $S$.
Note that we can compute sums efficiently.
Here the pair of $A$ and $B$ that I give you is a proof for a YES answer.
You can efficiently verify my claim by looking at my proof and
checking if it is a valid proof.
If the answer is YES then there is a valid proof, and
I can give it to you and you can verify it efficiently.
If the answer is NO then there is no valid proof.
So whatever I give you you can check and see it is not a valid proof.
I cannot trick you by an invalid proof that the answer is YES.
Recall that if the answer is too big
it will take a lot of time to verify it,
we do not want this to happen,
so we only care about efficient proofs,
i.e. proofs which have polynomial size.
Sometimes people use "certificate" or "witness" in place of "proof".
Note I am giving you enough information about the answer for a given input $x$
so that you can find and verify the answer efficiently.
For example, in our partition example
I do not tell you the answer,
I just give you a partition,
and you can check if it is valid or not.
Note that you have to verify the answer yourself,
you cannot trust me about what I say.
Moreover you can only check the correctness of my proof.
If my proof is valid it means the answer is YES.
But if my proof is invalid it does not mean the answer is NO.
You have seen that one proof was invalid,
not that there are no valid proofs.
We are talking about proofs for YES.
We are not talking about proofs for NO.
Let us look at an example:
$A=\{2,4\}$ and $B=\{1,5\}$ is a proof that
$S=\{1,2,4,5\}$ can be partitioned into two sets with equal sums.
We just need to sum up the numbers in $A$ and the numbers in $B$ and
see if the results are equal, and check if $A$, $B$ is partition of $S$.
If I gave you $A=\{2,5\}$ and $B=\{1,4\}$,
you will check and see that my proof is invalid.
It does not mean the answer is NO,
it just means that this particular proof was invalid.
Your task here is not to find the answer,
but only to check if the proof you are given is valid.
It is like a student solving a question in an exam and
a professor checking if the answer is correct. :)
(unfortunately often students do not give enough information
to verify the correctness of their answer and
the professors have to guess the rest of their partial answer and
decide how much mark they should give to the students for their partial answers,
indeed a quite difficult task).
The amazing thing is that
the same situation applies to many other natural problems that we want to solve:
we can efficiently verify if a given short proof is valid,
but we do not know any efficient way of finding the answer.
This is the motivation why
the complexity class $\mathsf{NP}$ is extremely interesting
(though this was not the original motivation for defining it).
Whatever you do
(not just in CS, but also in
math, biology, physics, chemistry, economics, management, sociology, business,
you will face computational problems that fall in this class.
To get an idea of how many problems turn out to be in $\mathsf{NP}$ check out
Indeed you will have hard time finding natural problems
which are not in $\mathsf{NP}$.
It is simply amazing.
$\mathsf{NP}$ is the class of problems which have efficient verifiers,
there is a polynomial time algorithm that can verify
if a given solution is correct.
More formally, we say a decision problem $Q$ is in $\mathsf{NP}$ iff
there is an efficient algorithm $V$ called verifier such that
for all inputs $x$,
if $Q(x)=YES$ then there is a proof $y$ such that $V(x,y)=YES$,
if $Q(x)=NO$ then for all proofs $y$, $V(x,y)=NO$.
We say a verifier is sound
if it does not accept any proof when the answer is NO.
In other words, a sound verifier cannot be tricked
to accept a proof if the answer is really NO.
No false positives.
Similarly, we say a verifier is complete
if it accepts at least one proof when the answer is YES.
In other words, a complete verifier can be convinced of the answer being YES.
The terminology comes from logic and proof systems.
We cannot use a sound proof system to prove any false statements.
We can use a complete proof system to prove all true statements.
The verifier $V$ gets two inputs,
$x$ : the original input for $Q$, and
$y$ : a suggested proof for $Q(x)=YES$.
Note that we want $V$ to be efficient in the size of $x$.
If $y$ is a big proof
the verifier will be able to read only a polynomial part of $y$.
That is why we require the proofs to be short.
If $y$ is short saying that $V$ is efficient in $x$
is the same as saying that $V$ is efficient in $x$ and $y$
(because the size of $y$ is bounded by a fixed polynomial in the size of $x$).
In summery, to show that a decision problem $Q$ is in $\mathsf{NP}$
we have to give an efficient verifier algorithm
which is sound and complete.
Historical Note:
historically this is not the original definition of $\mathsf{NP}$.
The original definition uses what is called non-deterministic Turing machines.
These machines do not correspond to any actual machine model and
are difficult to get used to
(at least when you are starting to learn about complexity theory).
I have read that many experts think that
they would have used the verifier definition as the main definition and
even would have named the class $\mathsf{VP}$
(for verifiable in polynomial-time) in place of $\mathsf{NP}$
if they go back to the dawn of the computational complexity theory.
The verifier definition is more natural,
easier to understand conceptually, and
easier to use to show problems are in $\mathsf{NP}$.
$\mathsf{P}\subseteq \mathsf{NP}$
Therefore we have
$\mathsf{P}$=efficient solvable and $\mathsf{NP}$=efficiently verifiable.
So $\mathsf{P}=\mathsf{NP}$ iff
the problems that can be efficiently verified are
the same as the problems that can be efficiently solved.
Note that any problem in $\mathsf{P}$ is also in $\mathsf{NP}$,
i.e. if you can solve the problem
you can also verify if a given proof is correct:
the verifier will just ignore the proof!
That is because we do not need it,
the verifier can compute the answer by itself,
it can decide if the answer is YES or NO without any help.
If the answer is NO we know there should be no proofs and
our verifier will just reject every suggested proof.
If the answer is YES, there should be a proof, and
in fact we will just accept anything as a proof.
[We could have made our verifier accept only some of them,
that is also fine,
as long as our verifier accept at lest one proof
the verifier works correctly for the problem.]
Here is an example:
Input: a list of $n+1$ natural numbers $a_1,\cdots,a_n$, and $s$,
Question: is $\Sigma_{i=1}^n a_i = s$?
The problem is in $\mathsf{P}$ because
we can sum up the numbers and then compare it with $s$,
we return YES if they are equal, and NO if they are not.
The problem is also in $\mathsf{NP}$.
Consider a verifier $V$ that gets a proof plus the input for Sum.
It acts the same way as the algorithm in $\mathsf{P}$ that we described above.
This is an efficient verifier for Sum.
Note that there are other efficient verifiers for Sum, and
some of them might use the proof given to them.
However the one we designed does not and that is also fine.
Since we gave an efficient verifier for Sum the problem is in $\mathsf{NP}$.
The same trick works for all other problems in $\mathsf{P}$ so
$\mathsf{P} \subseteq \mathsf{NP}$.
Brute-Force/Exhaustive-Search Algorithms for $\mathsf{NP}$ and $\mathsf{NP}\subseteq \mathsf{ExpTime}$
The best algorithms we know of for solving an arbitrary problem in $\mathsf{NP}$ are
brute-force/exhaustive-search algorithms.
Pick an efficient verifier for the problem
(it has an efficient verifier by our assumption that it is in $\mathsf{NP}$) and
check all possible proofs once by one.
If the verifier accepts one of them then the answer is YES.
Otherwise the answer is NO.
In our partition example,
we try all possible partitions and
check if the sums are equal in any of them.
Note that the brute-force algorithm runes in worst-case exponential time.
The size of the proofs is polynomial in the size of input.
If the size of the proofs is $m$ then there are $2^m$ possible proofs.
Checking each of them will take polynomial time by the verifier.
So in total the brute-force algorithm takes exponential time.
This shows that any $\mathsf{NP}$ problem
can be solved in exponential time, i.e.
$\mathsf{NP}\subseteq \mathsf{ExpTime}$.
(Moreover the brute-force algorithm will use
only a polynomial amount of space, i.e.
$\mathsf{NP}\subseteq \mathsf{PSpace}$
but that is a story for another day).
A problem in $\mathsf{NP}$ can have much faster algorithms,
for example any problem in $\mathsf{P}$ has a polynomial-time algorithm.
However for an arbitrary problem in $\mathsf{NP}$
we do not know algorithms that can do much better.
In other words, if you just tell me that
your problem is in $\mathsf{NP}$
(and nothing else about the problem)
then the fastest algorithm that
we know of for solving it takes exponential time.
However it does not mean that there are not any better algorithms,
we do not know that.
As far as we know it is still possible
(though thought to be very unlikely by almost all complexity theorists) that
$\mathsf{NP}=\mathsf{P}$ and
all $\mathsf{NP}$ problems can be solved in polynomial time.
Furthermore, some experts conjecture that
we cannot do much better, i.e.
there are problems in $\mathsf{NP}$ that
cannot be solved much more efficiently than brute-force search algorithms
which take exponential amount of time.
for more information.
But this is not proven, it is only a conjecture.
It just shows how far we are from
finding polynomial time algorithms for arbitrary $\mathsf{NP}$ problems.
This association with exponential time confuses some people:
they think incorrectly that
$\mathsf{NP}$ problems require exponential-time to solve
(or even worse there are no algorithm for them at all).
Stating that a problem is in $\mathsf{NP}$
does not mean a problem is difficult to solve,
it just means that it is easy to verify,
it is an upper bound on the difficulty of solving the problem, and
many $\mathsf{NP}$ problems are easy to solve since $\mathsf{P}\subseteq\mathsf{NP}$.
Never the less,
there are $\mathsf{NP}$ problems which seem to be hard to solve.
I will return to this in when we discuss $\mathsf{NP}$-hardness.
Lower Bounds Seem Difficult to Prove
OK, so we now know that there are
that are in $\mathsf{NP}$ and
we do not know any efficient way of solving them and
we suspect that they really require exponential time to solve.
Can we prove this?
Unfortunately the task of proving lower bounds is very difficult.
We cannot even prove that these problems require more than linear time!
let alone requiring exponential time.
Proving linear-time lower bounds is rather easy:
the algorithm needs to read the input after all.
Proving super-linear lower bounds is a completely different story.
We can prove super-linear lower bounds
with more restrictions about the kind of algorithms we are considering,
e.g. sorting algorithms using comparison,
but we do not know lower-bounds without those restrictions.
To prove an upper bound for a problem
we just need to design a good enough algorithm.
It often needs knowledge, creative thinking, and
even ingenuity to come up with such an algorithm.
However the task is considerably simpler compared to proving a lower bound.
We have to show that there are no good algorithms.
Not that we do not know of any good enough algorithms right now, but
that there does not exist any good algorithms,
that no one will ever come up with a good algorithm.
Think about it for a minute if you have not before,
how can we show such an impossibility result?
This is another place where people get confused.
Here "impossibility" is a mathematical impossibility, i.e.
it is not a short coming on our part that
some genius can fix in future.
When we say impossible
we mean it is absolutely impossible,
as impossible as $1=0$.
No scientific advance can make it possible.
That is what we are doing when we are proving lower bounds.
To prove a lower bound, i.e.
to show that a problem requires some amount of time to solve,
means that we have to prove that any algorithm,
even very ingenuous ones that do not know yet,
cannot solve the problem faster.
There are many intelligent ideas that we know of
(greedy, matching, dynamic programming, linear programming, semidefinite programming, sum-of-squares programming, and
many other intelligent ideas) and
there are many many more that we do not know of yet.
Ruling out one algorithm or one particular idea of designing algorithms
is not sufficient,
we need to rule out all of them,
even those we do not know about yet,
even those may not ever know about!
And one can combine all of these in an algorithm,
so we need to rule out their combinations also.
There has been some progress towards showing that
some ideas cannot solve difficult $\mathsf{NP}$ problems,
e.g. greedy and its extensions cannot work,
and there are some work related to dynamic programming algorithms,
and there are some work on particular ways of using linear programming.
But these are not even close to ruling out the intelligent ideas that
we know of
(search for lower-bounds in restricted models of computation
if you are interested).
Barriers: Lower Bounds Are Difficult to Prove
On the other hand we have mathematical results called
that say that a lower-bound proof cannot be such and such,
and such and such almost covers all techniques that
we have used to prove lower bounds!
In fact many researchers gave up working on proving lower bounds after
Alexander Razbarov and Steven Rudich's
barrier result.
It turns out that the existence of particular kind of lower-bound proofs
would imply the insecurity of cryptographic pseudorandom number generators and
many other cryptographic tools.
I say almost because
in recent years there has been some progress mainly by
that has been able to intelligently circumvent the barrier results,
still the results so far are for very weak models of computation and
quite far from ruling out general polynomial-time algorithms.
But I am diverging.
The main point I wanted to make was that
proving lower bounds is difficult and
we do not have strong lower bounds for general algorithms
solving $\mathsf{NP}$ problems.
[On the other hand,
Ryan Williams' work shows that
there are close connections between proving lower bounds and proving upper bounds.
if you are interested.]
Reductions: Solving a Problem Using Another Problem as a Subroutine/Oracle/Black Box
The idea of a reduction is very simple:
to solve a problem, use an algorithm for another problem.
Here is simple example:
assume we want to compute the sum of a list of $n$ natural numbers and
we have an algorithm $Sum$ that returns the sum of two given numbers.
Can we use $Sum$ to add up the numbers in the list?
Of course!
Input: a list of $n$ natural numbers $x_1,\ldots,x_n$,
Output: return $\sum_{i=1}^{n} x_i$.
Reduction Algorithm:
for $i$ from $1$ to $n$
$s = Sum(s,x_i)$
return $s$
Here we are using $Sum$ in our algorithm as a subroutine.
Note that we do not care about how $Sum$ works,
it acts like black box for us,
we do not care what is going on inside $Sum$.
We often refer to the subroutine $Sum$ as oracle.
It is like
in Greek mythology,
we ask questions and the oracle answers them and
we use the answers.
This is essentially what a reduction is:
assume that we have algorithm for a problem and
use it as an oracle to solve another problem.
Here efficient means efficient assuming that
the oracle answers in a unit of time, i.e.
we count each execution of the oracle a single step.
If the oracle returns a large answer
we need to read it and
that can take some time,
so we should count the time it takes us to read the answer that
oracle has given to us.
Similarly for writing/asking the question from the oracle.
But oracle works instantly, i.e.
as soon as we ask the question from the oracle
the oracle writes the answer for us in a single unit of time.
All the work that oracle does is counted a single step,
but this excludes the time it takes us to
write the question and read the answer.
Because we do not care how oracle works but only about the answers it returns
we can make a simplification and consider the oracle to be
the problem itself in place of an algorithm for it.
In other words,
we do not care if the oracle is not an algorithm,
we do not care how oracles comes up with its replies.
For example,
$Sum$ in the question above is the addition function itself
(not an algorithm for computing addition).
We can ask multiple questions from an oracle, and
the questions does not need to be predetermined:
we can ask a question and
based on the answer that oracle returns
we perform some computations by ourselves and then
ask another question based on the answer we got for the previous question.
Another way of looking at this is
thinking about it as an interactive computation.
Interactive computation in itself is large topic so
I will not get into it here, but
I think mentioning this perspective of reductions can be helpful.
An algorithm $A$ that uses a oracle/black box $O$ is usually denoted as $A^O$.
The reduction we discussed above is the most general form of a reduction and
is known as black-box reduction
(a.k.a. oracle reduction, Turing reduction).
More formally:
We say that problem $Q$ is black-box reducible to problem $O$ and
write $Q \leq_T O$ iff
there is an algorithm $A$ such that for all inputs $x$,
$Q(x) = A^O(x)$.
In other words if there is an algorithm $A$ which
uses the oracle $O$ as a subroutine and solves problem $Q$.
If our reduction algorithm $A$ runs in polynomial time
we call it a polynomial-time black-box reduction or
simply a Cook reduction
(in honor of
write $Q\leq^\mathsf{P}_T O$.
(The subscript $T$ stands for "Turing" in the honor of
However we may want to put some restrictions
on the way the reduction algorithm interacts with the oracle.
There are several restrictions that are studied but
the most useful restriction is the one called many-one reductions
(a.k.a. mapping reductions).
The idea here is that on a given input $x$,
we perform some polynomial-time computation and generate a $y$
that is an instance of the problem the oracle solves.
We then ask the oracle and return the answer it returns to us.
We are allowed to ask a single question from the oracle and
the oracle's answers is what will be returned.
More formally,
We say that problem $Q$ is many-one reducible to problem $O$ and
write $Q \leq_m O$ iff
there is an algorithm $A$ such that for all inputs $x$,
$Q(x) = O(A(x))$.
When the reduction algorithm is polynomial time we call it
polynomial-time many-one reduction or
simply Karp reduction (in honor of
denote it by $Q \leq_m^\mathsf{P} O$.
The main reason for the interest in
this particular non-interactive reduction is that
it preserves $\mathsf{NP}$ problems:
if there is a polynomial-time many-one reduction from
a problem $A$ to an $\mathsf{NP}$ problem $B$,
then $A$ is also in $\mathsf{NP}$.
The simple notion of reduction is
one of the most fundamental notions in complexity theory
along with $\mathsf{P}$, $\mathsf{NP}$, and $\mathsf{NP}$-complete
(which we will discuss below).
The post has become too long and exceeds the limit of an answer (30000 characters).
I will continue the answer in .
Continued from .
The previous one exceeded the maximum number of letters allowed in an answer (30000)
so I am breaking it in two.
$\mathsf{NP}$-completeness: Universal $\mathsf{NP}$ Problems
OK, so far we have discussed the class of efficiently solvable problems
($\mathsf{P}$) and
the class of problems efficiently verifiable problems ($\mathsf{NP}$).
As we discussed above,
both of these are upper-bounds.
Let's focus our attention for now on problems inside $\mathsf{NP}$
as amazingly many natural problems turn out to be inside $\mathsf{NP}$.
Now sometimes we want to say that a problem is difficult to solve.
But as we mentioned above we cannot use lower-bounds for this purpose:
theoretically they are exactly what we would like to prove,
however in practice we have not been very successful in proving lower bounds and
in general they are hard to prove as we mentioned above.
Is there still a way to say that a problem is difficult to solve?
Here comes the notion of $\mathsf{NP}$-completeness.
But before defining $\mathsf{NP}$-completeness
let us have another look at reductions.
Reductions as Relative Difficulty
We can think of lower-bounds as absolute difficulty of problems.
Then we can think of reductions as relative difficulty of problems.
We can take a reductions from $A$ to $B$ as saying $A$ is easier than $B$.
This is implicit in the $\leq$ notion we used for reductions.
Formally, reductions give partial orders on problems.
If we can efficiently reduce a problem $A$ to another problem $B$
then $A$ should not be more difficult than $B$ to solve.
The intuition is as follows:
Let $M^B$ be an efficient reduction from $A$ to $B$, i.e.
$M$ is an efficient algorithm that uses $B$ and solves $A$.
Let $N$ be an efficient algorithm that solves $B$.
We can combine the efficient reduction $M^B$ and the efficient algorithm $N$
to obtain $M^N$ which is an efficient algorithm that solves $A$.
This is because we can use an efficient subroutine in an efficient algorithm
(where each subroutine call costs one unit of time) and
the result is an efficient algorithm.
This is a very nice closure property of polynomial-time algorithms and
$\mathsf{P}$,
it does not hold for many other complexity classes.
$\mathsf{NP}$-complete means most difficult $\mathsf{NP}$ problems
Now that we have a relative way of comparing difficulty of problems
we can ask which problems are most difficult among problems in $\mathsf{NP}$?
We call such problems $\mathsf{NP}$-complete.
$\mathsf{NP}$-complete problems are
the most difficult $\mathsf{NP}$ problems,
if we can solve an $\mathsf{NP}$-complete problem efficiently,
we can solve all $\mathsf{NP}$ problems efficiently.
More formally, we say a decision problem $A$ is $\mathsf{NP}$-complete iff
$A$ is in $\mathsf{NP}$, and
for all $\mathsf{NP}$ problems $B$,
$B$ is polynomial-time many-one reducible to $A$
($B\leq_m^\mathsf{P} A$).
Another way to think about $\mathsf{NP}$-complete problems is
to think about them as the complexity version of .
An $\mathsf{NP}$-complete problem is
among $\mathsf{NP}$ problems in a similar sense:
you can use them to solve any $\mathsf{NP}$ problem.
This is one of the reasons that good
are important, particularly in the industry.
SAT is $\mathsf{NP}$-complete (more on this later),
so we can focus on designing very good algorithms (as much as we can)
for solving SAT.
To solve any other problem in $\mathsf{NP}$
we can convert the problem instance to a SAT instance and
then use an industrial-quality highly-optimized SAT-solver.
(Two other problems that lots of people work on
optimizing their algorithms for them for practical usage in industry
Depending on your problem and the instances you care about
the optimized algorithms for one of these
might perform better than the others.)
If a problem satisfies
the second condition in the definition of $\mathsf{NP}$-completeness
(i.e. the universality condition)
we call the problem $\mathsf{NP}$-hard.
$\mathsf{NP}$-hardness is a way of saying that a problem is
difficult.
I personally prefer to think about $\mathsf{NP}$-hardness as universality,
so probably $\mathsf{NP}$-universal could have been a more correct name,
since we do not know at the moment if they are really hard or
it is just because
we have not been able to find a polynomial-time algorithm for them).
The name $\mathsf{NP}$-hard also confuses people to incorrectly think that
$\mathsf{NP}$-hard problems are problems which are absolutely hard to solve.
We do not know that yet,
we only know that they are as difficult as any $\mathsf{NP}$ problem to solve.
Though experts think it is unlikely
it is still possible that
all $\mathsf{NP}$ problems are easy and efficiently solvable.
In other words,
being as difficult as any other $\mathsf{NP}$ problem
does not mean really difficult.
That is only true if there is an $\mathsf{NP}$ problem
which is absolutely hard
(i.e. does not have any polynomial time algorithm).
Now the questions are:
Are there any $\mathsf{NP}$-complete problems?
Do we know any of them?
I have already given away the answer
when we discussed SAT-solvers.
The surprising thing is that
many natural $\mathsf{NP}$ problems turn out to be
$\mathsf{NP}$-complete
(more on this later).
So if we pick a randomly pick a natural problems in $\mathsf{NP}$,
with very high probability
it is either that we know a polynomial-time algorithm for it or
that we know it is $\mathsf{NP}$-complete.
The number of natural problems which are not known to be either is quite small
(an important example is factoring integers,
for a list of similar problems).
Before moving to examples of $\mathsf{NP}$-complete problems,
note that we can give similar definitions for
other complexity classes and
define complexity classes like $\mathsf{ExpTime}$-complete.
But as I said,
$\mathsf{NP}$ has a very special place:
unlike $\mathsf{NP}$
other complexity classes have few natural complete problems.
(By a natural problem
I mean a problem that people really care about solving,
not problems that are defined artificially by people to demonstrate some point.
We can modify any problem in a way that
it remains essentially the same problem,
e.g. we can change the answer for the input $p \lor \lnot p$ in SAT to be NO.
We can define infinitely many distinct problems in a similar way
without essentially changing the problem.
But who would really care about these artificial problem by themselves?)
$\mathsf{NP}$-complete Problems: There are Universal Problems in $\mathsf{NP}$
First, note that if $A$ is $\mathsf{NP}$-hard and
$A$ polynomial-time many-one reduces to $B$ then
$B$ is also $\mathsf{NP}$-hard.
We can solve any $\mathsf{NP}$ problem using $A$
and we can solve $A$ itself using $B$,
so we can solve any $\mathsf{NP}$ problem using $B$!
This is a very useful lemma.
If we want to show that a problem is $\mathsf{NP}$-hard
we have to show that we can reduce all $\mathsf{NP}$ problems to it,
that is not easy because
we know nothing about these problems other than
that they are in $\mathsf{NP}$.
Think about it for a second.
It is quite amazing the first time we see this.
We can prove all $\mathsf{NP}$ problems are reducible to SAT and
without knowing anything about those problems other than the fact that
they are in $\mathsf{NP}$!
Fortunately we do not need to carry out this more than once.
Once we show a problem like $SAT$ is $\mathsf{NP}$-hard
for other problems we only need to reduce $SAT$ to them.
For example,
to show that $SubsetSum$ is $\mathsf{NP}$-hard
we only need to give a reduction from $SAT$ to $SubsetSum$.
OK, let's show there is an $\mathsf{NP}$-complete problem.
Universal Verifier is $\mathsf{NP}$-complete
Note: the following part might be a bit technical on the first reading.
The first example is a bit artificial but
I think it is simpler and useful for intuition.
Recall the verifier definition of $\mathsf{NP}$.
We want to define a problem that can be used to solve all of them.
So why not just define the problem to be that?
Time-Bounded Universal Verifier
the code of an algorithm $V$ which gets an input and a proof,
an input $x$, and
two numbers $t$ and $k$.
$YES$ if there is a proof of size at most $k$ s.t.
it is accepted by $V$ for input $x$ in $t$-steps,
$NO$ if there are no such proofs.
It is not difficult to show this problem
which I will call $UniVer$ is $\mathsf{NP}$-hard:
Take a verifier $V$ for a problem in $\mathsf{NP}$.
To check if there is proof for given input $x$,
we pass the code of $V$ and $x$ to $UniVer$.
($t$ and $k$ are upper-bounds on the running time of $V$ and
the size of proofs we are looking for $x$.
we need them to limit the running-time of $V$ and
the size of proofs by polynomials in the size of $x$.)
(Technical detail:
the running time will be polynomial in $t$ and
we would like to have the size of input be at least $t$ so
we give $t$ in unary notation not binary.
Similar $k$ is given in unary.)
We still need to show that the problem itself is in $\mathsf{NP}$.
To show the $UniVer$ is in $\mathsf{NP}$
we consider the following problem:
Time-Bounded Interpreter
the code of an algorithm $M$,
an input $x$ for $M$, and
a number $t$.
Output: $YES$ if the algorithm $M$ given input $x$
returns $YES$ in $t$ steps,
$NO$ if it does not return $YES$ in $t$ steps.
You can think of an algorithm roughly as the code of a $C$ program.
It is not difficult to see this problem is in $\mathsf{P}$.
It is essentially writing an interpreter, counting the number of steps, and stopping after $t$ steps.
I will use the abbreviation $Interpreter$ for this problem.
Now it is not difficult to see that $UniVer$ is in $\mathsf{NP}$:
given input $M$, $x$, $t$, and $k$; and a suggested proof $c$;
check if $c$ has size at most $k$ and
then use $Interpreter$ to see if $M$ returns $YES$ on $x$ and $c$ in $t$ steps.
$SAT$ is $\mathsf{NP}$-complete
The universal verifier $UniVer$ is a bit artificial.
It is not very useful to show other problems are $\mathsf{NP}$-hard.
Giving a reducing from $UniVer$ is not much easier than
giving a reduction from an arbitrary $\mathsf{NP}$ problem.
We need problems which are simpler.
Historically the first natural problem that
was shown to be $\mathsf{NP}$-complete was .
Recall that $SAT$ is the problem where we are given a propositional formula and
we want to see if it is satisfiable,
i.e. if we can assign true/false to the propositional variables
to make it evaluate to true.
Input: a propositional formula $\varphi$.
Output: $YES$ if $\varphi$ is satisfiable, $NO$ if it is not.
It is not difficult to see that $SAT$ is in $\mathsf{NP}$.
We can evaluate a given propositional formula on a given truth assignment
in polynomial time.
The verifier will get a truth assignment and
will evaluate the formula on that truth assignment.
To be written...
SAT is $\mathsf{NP}$-hard
What does $\mathsf{NP}$-completeness mean for practice?
What to do if you have to solve an $\mathsf{NP}$-complete problem?
$\mathsf{P}$ vs. $\mathsf{NP}$
What's Next? Where To Go From Here?
More than useful mentioned answers, I recommend you highly to watch "" by . I think this video should be archived as one of the leading teaching video in computer science.!
Copying my answer to a similar question on Stack Overflow:
The easiest way to explain P v. NP and such without getting into technicalities is to compare "word problems" with "multiple choice problems".
When you are trying to solve a "word problem" you have to find the solution from scratch. When you are trying to solve a "multiple choice problems" you have a choice: either solve it as you would a "word problem", or try to plug in each of the answers given to you, and pick the candidate answer that fits.
It often happens that a "multiple choice problem" is much easier than the corresponding "word problem": substituting the candidate answers and checking whether they fit may require significantly less effort than finding the right answer from scratch.
Now, if we would agree the effort that takes polynomial time "easy" then the class P would consist of "easy word problems", and the class NP would consist of "easy multiple choice problems".
The essence of P v. NP is the question: "Are there any easy multiple choice problems that are not easy as word problems"? That is, are there problems for which it's easy to verify the validity of a given answer but finding that answer from scratch is difficult?
Now that we understand intuitively what NP is, we have to challenge our intuition. It turns out that there are "multiple choice problems" that, in some sense, are hardest of them all: if one would find a solution to one of those "hardest of them all" problems one would be able to find a solution to ALL NP problems! When Cook discovered this 40 years ago it came as a complete surprise. These "hardest of them all" problems are known as NP-hard. If you find a "word problem solution" to one of them you would automatically find a "word problem solution" to each and every "easy multiple choice problem"!
Finally, NP-complete problems are those that are simultaneously NP and NP-hard. Following our analogy, they are simultaneously "easy as multiple choice problems" and "the hardest of them all as word problems".
Simplest of them is P, problems solvable in polynomial time belongs here.
Then comes NP.
Problems solvable in polynomial time on a non-deterministic Turing machine belongs here.
The hardness and completeness has to with reductions.
A problem A is hard for a class C if every problem in C reduces to A.
If problem A is hard for NP, or NP-hard, if every problem in NP reduces to A.
Finally, a problem is complete for a class C if it is in C and hard for C.
In your case, problem A is complete for NP, or NP-complete, if every problem in NP reduces to A, and A is in NP.
To add to explanation of NP, a problem is in NP if and only if a solution can be verified in (deterministic) polynomial time.
Consider any NP-complete problem you know, SAT, CLIQUE, SUBSET SUM, VERTEX COVER, etc.
If you "get the solution", you can verify its correctness in polynomial time.
They are, resp., truth assignments for variables, complete subgraph, subset of numbers and set of vertices that dominates all edges.
For the basics, the
video seems a whole lot simpler to understand.
For a computer with a really big version of a problem:
P problems
easy to solve (rubix cube)
NP problems
hard - but checking answers is easy (sudoku)
Perhaps these are all really P problems but we don't know it... P vs. NP.
NP-complete
Lots of NP problems boil down to the same one (sudoku is a newcomer to the list).
EXP problems
really hard (best next move in chess)
NP-hard problems
Edit: NP-hard isn't well explained in the video (it's all the pink bits), Wikipedia's
Euler diagram is clearer on this.
Video summary
Euler diagram
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Computer Science Stack Exchange works best with JavaScript enabled

我要回帖

更多关于 2月14日是什么日子 的文章

 

随机推荐