11 - NP Ribiero
11 - NP Ribiero
Pedro Ribeiro
DCC/FCUP
2018/2019
Good news: Almost all the algorithms we’ve studied thus far can be
solved ”quickly”, i.e., they are polynomial-time algorithms: on
inputs of size n, their worst-case running time is O(nk ), for some
(typically small) constant k.
This lecture will focus on this last set of problems. We want evidence
that some problems are intrinsically hard. We will be particularly
interested in NP-complete problems.
coNP is essentially the opposite of NP. if the answer is NO, then there
is a proof of this fact that can be checked in polynomial time.
P = NP?
I Checking if a solution is correct, is easier than solving the problem
from scratch, no? But nobody knows how to prove it!
I This is one of the most important unanswered questions in Computer
Science (if not from all sciences!)
I P = NP is one of the (7) Millenium Prize problems. The Clay
Mathematics Institute offers an US 1, 000, 000 for anyone solving it.
This reward was posted in 2000 and in fact nobody solved it (yet?)
Pedro Ribeiro (DCC/FCUP) NP-completeness 2018/2019 10 / 32
Classes of Problems
What I (we?) think about it
1) SAT is in NP
2) SAT is NP-hard
We end up with a circuit C that is satisfiable if and only if the input to our
problem has an YES answer!
Pedro Ribeiro (DCC/FCUP) NP-completeness 2018/2019 21 / 32
3SAT is NP-complete
We now know that CIRCUIT-SAT and SAT are NP-complete. We can use
it as the basis for proving any other problem is also NP-complete.
1) 3SAT is in NP
2) 3SAT is NP-hard
Now we have two choices for problem we can reduce to 3SAT: SAT and its
”circuit equivalent”: CIRCUIT-SAT. Let’s choose this last one.
1) Make sure every gate has only two inputs at most. If any gate has
k > 2 inputs, replace it with a binary tree of k − 1 input gates.
3) Now transform every clause with one or two literals into a clause with
three literals, introducing new variables:
Let’s continue our ”journey”, but now going to the graphs realm.
Now, suppose that the initial formula had k clauses. Then the formula is
satisfiable if and only if the graph has an independent set of size k
IndSet → Satisfying: if the graph has an independent set of k vertices, then
each vertex comes from a different clause. To obtain a satisfying assignment, we
assign TRUE to each literal in the independent set. Since contradictory literals
are connected by edges, this is consistent. There may be variables that have no
literal in the independent set; we can set these to any value we like. The resulting
assignment satisfies the original 3CNF formula.
MaxIndSet is NP-complete.
VERTEX-COVER is NP-complete.
Pedro Ribeiro (DCC/FCUP) NP-completeness 2018/2019 30 / 32
CLIQUE is NP-complete (from IndSet)
CLIQUE is NP-complete.
Pedro Ribeiro (DCC/FCUP) NP-completeness 2018/2019 32 / 32