P vs. NP
An algorithm has polynomial running time if there is a constant such that for every input of length , the algorithm takes time.
An algorithm has exponential running time if there is a constant such that for every input of length , the algorithm takes time.
Complexity Class P
A decision problem is a problem for which the answer is "yes" or "no". The complexity class set of all decision problems that can be solved in polynomial time. For example a sorting problem is not in , since it does not output "yes" or "no".
Examples of problems in :
- is a given input graph connected
- is a given input graph bipartite
- is a given input sequence sorted
- does a given input graph contain an Euler tour? An Euler tour is a path that traverses each edge exactly once
Other Problems
Hamiltonian Cycle
- input: An undirected graph stored using adjacency lists
- question: Does contain a Hamiltonian cycle? A Hamiltonian cycle is a cycle that traverses each vertex exactly once.
Right now on this planet, nobody knows how to solve this problem in polynomial time. Not known if this problem is in !
Travelling Salesman Problem
- input:
- A complete directed graph , where each edge has a weigh
- An integer K
- question: Does contain a Hamiltonian cycle of total weight at most ?
Again we don't know if this problem is in !
Subset-Sum
- input: A set of integers together with an integer
- question: Is there a subset of such that the sum of the subset is equal to ?
Not known if this problem is in !
Clique
- input: An undirected graph together with an integer
- question: DOes contain a clique (complete subgraph) with vertices?
Not known if this problem is in !
Proving
For each of the 4 previous problems
- Not know if it can be solved in polynomial time
- If the answer to the question is YES, then
- there is a "short" proof for this
- "short" means the length of the proof is "polynomial in the length of the input"
- if someones gives us such a short proof, then we can "easily" verify this proof
- here "easily" means "in polynomial time"
- there is a "short" proof for this
How to check if proof is correct?
Hamiltonian cycle
proof/solution: sequence of vertices
verification:
- ?
- no duplicates in
- For each is an edge?
- ${v_k, v_1} is an edge?
TSP
proof/solution: sequence of vertices
verification:
- ?
- no duplicates in
- Do we have ?
Subset-sum
proof/solution: A set
verification:
- is a subset of S?
- Do we have sum of subset ?
Clique
proof/solution: A set
verification:
- is a subset of V?
- Do we have ?
- For each such that , is an edge in ?
Complexity Class NP
A decision problem is in if
- for a given input , the answer to the question is YES, then there exists a proof/solution/certificate such that
- is short (polynomial size in the length of )
- in polynomial time, we can verify that is a correct proof for the fact that = YES
stands for Nondeterministic Polynomial
Formal P vs. NP
Language of a Decision Problem
The language of a decision problem is the set of all inputs (encoded as finite strings) for which the answer is YES.
Examples:
- HAM-CYCLE = { | is a graph that contains a Hamiltonian cycle}
- TSP = {() | is a complete directed graph , where each edge has a weight , is an integer and contains a Hamiltonian cycle with total weight at most .}
- SUBSET-SUM = { is a set of integers, is an integer and such that }
Complexity Class P
The language (of a decision problem) is in if the following is true. There exists an algorithm and a constant such that for any input ,
- if returns YES.
- the running time of is , where is the length of .
Complexity Class NP
The language (of a decision problem) is in if the following is true. There exists an algorithm and a constant such that for any input ,
- there exists a certificate such that
- returns YES
- and the running time of is polynomial in the length of .
Observe that is a verification algorithm. It has 2 input parameters.
Example: Hamiltonian Cycle
{ is a graph that has a Hamiltonian cycle} is in NP
Verification algorithm V takes as input
- graph , where
- certificate
It does the following:
- check is
- check if are all different
- check if are edges in
- if steps 1-3 were successful, return YES, otherwise NO.
Theorem
Proof: Let be an arbitrary language (of a decision problem) in . By definition, there is an algorithm such that for any input ,
- returns YES.
- The running time of is polynomial in the length of x.
We have to show that is in . That is, we have to show that satisfies the definition of .
Therefore, we need a verification algorithm . We define it in the following way: takes as input.
- the input for
- and a certificate
does the following: it runs and that's it! (It ignores ).
We then have the following:
- returns YES
- empty string ) returns YES
- there exists a certificate such that
- is polynomial in the length of ,
- returns YES
- and the running time of is polynomial in the length of .
Therefore is in NP.
Big Question
Is or ? Most people believe the latter.
If we want to prove that , then we have to show that there exists a language (of a decision problem) such that
- .
Such an must be "difficult". So we should look at the "most difficult" problems.
But what does this mean? How can we measure how difficult a problem is?
Reductions
Polynomial-Time Reduction
Let and be two languages. We say that is a polynomial-time reducible to if the following is true: there exists a function which satisfies the following famous 3 properties:
- maps inputs for to inputs for
- for ever input for ,
- for every input for , can be computed in time that is polynomial in the length of .
Notation:
Theorem
If and , then .
Intuition:
- means " is easy"
- means " is easer than ".
- So is easy, .
Consider the following algorithm : on input ,
- Compute
- Run
We have
- by definition of reduction
- returns YES by definition of
- returns YES by definition of
The running time of is polynomial in the length of . So .
About 3SAT
Consider a Boolean formula with variables of the form , where each is of the form . Each is a variable or the negation of a variable. is called a clause and is called a literal.
We say that is satisfiable if there exists a truth value for each such that is true.
3SAT =
We want to show that 3SAT INDEP - SET
Let be an input for 3SAT, , each clause is the disjunction of 3 literals.
is obtained as follows:
- (number of clauses)
- has vertices, one vertex for each literal.
- For each clause, the literals in this clause form a triangle in .
- Additionally, there is an edge between any pair of opposite literals.
Theorem
The relation is transitive: and
NP-Hard and NP-Complete
The language is -Hard if
- for all ,
The language of a decision problem is -Complete if
- and for all ,
It is not clear if a -Complete problem exists.
Intuitively, this means that belongs to the most difficult problems in . This what we were looking for in Formal P vs. NP.
Theorem
Assume that is -Complete. Then .
Intuition:
- If is easy
- is -Complete, so belongs to the most difficult problems in .
- If the most difficult problem in turns out to be easy, then all problems in are easy!
Theorem
is -Complete, , is -Complete.
Intuition:
- is -Complete, so belongs to the most difficult problems in .
- is at least as difficult as
- Then also belongs to the most difficult problems in
Here is how to use this theorem; to show that is -Complete,
- Show that
- Look for a problem that is "similar" to and that is known to be -Complete
- Show that .
CIRCUIT-SAT
input: A Boolean circuit
- Directed acyclic graph, where vertices are gates
- AND-gates and OR-gates have indegree 2
- NOT-gates have indegree 1
- Known input gats have indegree 0 and are labeled TRUE or FALSE
- Unknown gates have indegree 0 and are labeled "?"
- There is one output gate (whose outdegree is 0)
question: is it possible to assign a truth-value to each unknown input gate, such that the output of the circuit is TRUE?
CIRCUIT-SAT = { | is a Boolean circuit for which there exist truth values for the unknown input gates such that the output of is TRUE}
To show that CIRCUIT-SAT is -Complete, we have to show two things:
- CIRCUIT-SAT is in
- Certificate: sequence of truth values for the unknown input gates
- Verification: evaluate the circuit (in topological order)
- Show that for all in , CIRCUIT-SAT
- Let . We need a function such that
- takes any input for and produces an input for CIRCUIT-SAT
- CIRCUIT-SAT
- The time to compute is polynomial in the length of
- Let . We need a function such that
We know that . So there is a verification algorithm such that
- the input to is , where is an input for and is a certificate
- For every input to ,
- there exists a certificate such that
- returns YES
- and the running time of is at most
- there exists a certificate such that
We now define the function . Let be an input for . Define a new algorithm :
- input is a string of length at most
- runs
- If terminates in at most most |x|^c' steps, then terminates and returns the output of
- If has not terminated after |x|^c' steps, then terminates and returns NO.
Observe:
- Running time of algorithm is at most |x|^c'