Week 10 - NP overview
Complexity classes
Nondeterministic Polynomial time (NP)
Nondeterministic Polynomial time (NP)
This definition can mean multiple things.
Nondeterministic Polynomial time (search)
The class of NP problems is the class of all search problems.
Otherwise it might mean.
Link to originalNondeterministic Polynomial time (decision)
The class of NP problems is the class of all decision problems.
In this class we use the search problem definition.
Search problems
Link to originalSearch problem
A problem is a search problem if we can verify a solution in polynomial time.
Formally:
The problem is of the form, for a given instance
of the problem you can either:
- find a solution
for if one exists, or - output no if
has no solutions. Then this problem is a search problem if given an instance
and a solution then we can verify that is a solution to in polynomial time in .
Note here we have.
Statement
Link to originalLemma
The class of Polynomial time problems is a subset of Nondeterministic Polynomial time (NP).
There is an open problem.
P equals NP or P not equals NP
This is the open problem whether the class of Polynomial time problems is equal to the class of Nondeterministic Polynomial time (NP) problems.
Link to original
Satisfiability
Statement
Link to originalSat Problem
Given a boolean function
in CNF with variables and clauses. Is there a true/false assignment to the variables that satisfies . If yes then output it, otherwise say no.
The Satisfiability problem is in NP
Statement
Lemma
The Satisfiability problem is in NP.
Proof
First note that it is in the form of a search problem as it either provides you with a satisfying assignment to the
variables or says one doesn’t exist. All that is left to show is that we can verify an answer in Polynomial time.
Given an assignment of values to the
-variables. To check one clause is satisfied takes time. There are clauses, so this in total takes time. This is polynomial so the Satisfiability problem is in NP.
Link to original
k-colourings problem
Statement
Link to original
-colourings problem (graphs) Given an undirected graph
and integer . Does have a proper vertex colouring using -colours, if it does output the colouring and if not say so.
The k-colourings problem is in NP
Statement
Lemma
The k-colourings problem (graphs) is in NP.
Proof
The problem is of the correct from for a search problem as you either have to provide a proper vertex k-colouring or you have to say no such colouring exists.
If you are given
Link to originaland a -colouring it takes time to check the colouring is proper by checking every edges vertices.
MST
Statement
Link to originalMinimum Spanning Tree problem
Given an undirected graph
with weights can you find a spanning tree with minimum weight
Minimum Spanning Tree problem is in NP
Statement
Lemma
Proof
The problem is in the correct form for a search problem. It outputs a MST always as one always exists from the definition.
To verify a solution as we can first check it is a spanning tree by running BFS to verify it is connected and checking the size of the edge set is
Link to originalto check it is a tree. To check it is minimal we can find a solution in polynomial time using Kruskal’s algorithm. We can just check it’s weight vs the weight of the proposed solution to check they match.
This proof was relatively easy as MST is a polynomial time problem. This is shown by what is above and Kruskal’s algorithm.
Knapsack problem
Statement
Link to originalThe knapsack problem
Given
objects with weight and value how do we maximise the value of a bag that can carry weight . The solution to this is a subset of objects such that:
, and - it maximises its value
.
Whilst the Knapsack problem is of the correct form to be a search problem we can’t currently check if a solution is correct in polynomial time. Therefore the Knapsack problem isn’t known to be in NP.
Similarly we say that the Knapsack problem isn’t known to be in polynomial time either.
We say it isn’t known to be as there might be a super clever algorithm that happens to solve the Knapsack problem in polynomial time.
However, there is a variant of the problem that is in NP.
Statement
Link to originalKnapsack-search (without replacement)
Given
objects with weight and value , and a goal is there a bag that has weight less than but value at least . The solution to this is a subset of objects such that:
, and . If there is such a bag what is it otherwise say there is no such solution.
Here instead of having to check if a solution is maximal we can instead just check if it has enough value.
Knapsack-search is NP
Statement
Lemma
Knapsack-search is in NP.
Proof
The problem statement is in the form of a search problem.
Given a proposed solution
to check if it solves the problem we just need to calculate and check the following. This takes
time, so is polynomial. This makes Knapsack-search run in polynomial time.
Link to original
Polynomial time and Nondeterministic Polynomial time
Note that NP isn’t Not Polynomial time. In fact we have the following result.
Polynomial time is a subset of NP-complete
Statement
Lemma
The class of Polynomial time problems is a subset of Nondeterministic Polynomial time (NP).
Proof
If the problem is in NP then we already know the problem is a search problem. Therefore it is in the class Nondeterministic Polynomial time.
Link to original
The question is, are there problems that are in NP but are not in P?
NP-complete
If P not equal to NP then we would have a problem in NP that didn’t lie in P. Therefore the green region above would be non-empty.
Therefore lets look at the hardest problems in NP.
NP-hard
NP-hard
A problem
is NP-hard if for all search problems there is a many-one reduction from to . In other terms, is as hard as any search problem. Link to original
We define a many-one reduction as bellow.
Many-one reduction (problem)
Link to originalMany-one reduction
There is a many-one reduction of problem
to ( or ) if a polynomial time algorithm to solve would also solve in polynomial time.
However, we want to look at the hardest problems in NP.
NP-Complete
NP-Complete
Link to original
A classic NP-Complete problem is the SAT problem.
Reductions functionally
To show a many-one reduction from
Transclude of reduction
Therefore to show
- Define
: Show how an instance of problem can be converted into an instance of problem in polynomial time. - Define
: Show how a solution to the problem can be converted into a solution to problem in polynomial time. - Proof: Show that a solution for
exists if and only if a solution to exists.
Showing NP-Complete
To show a problem
Generically showing
is NP, and - there is some NP-complete problem
that reduces to .
Practice problems
From Algorithms by S. Dasgupta, C. Papadimitriou, and U. Vazirani.
8.1 Optimisation vs Search problems
8.2 Search problems vs Decision problems