0% found this document useful (0 votes)
2 views

Small26

The document discusses NP-completeness, introducing key concepts such as polynomial-time reductions, NP-hardness, and specific NP-complete problems like 3SAT and the Independent Set Problem. It outlines methods for proving NP-completeness, including gadget-based reductions and constructing graphs for problem transformations. The document also includes course logistics and final exam details for a related course.

Uploaded by

saeb2saeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Small26

The document discusses NP-completeness, introducing key concepts such as polynomial-time reductions, NP-hardness, and specific NP-complete problems like 3SAT and the Independent Set Problem. It outlines methods for proving NP-completeness, including gadget-based reductions and constructing graphs for problem transformations. The document also includes course logistics and final exam details for a related course.

Uploaded by

saeb2saeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

NP-Completeness

Part II
Outline for Today
● Recap from Last Time
● What is NP-completeness again, anyway?
● 3SAT
● A simple, canonical NP-complete problem.
● Independent Sets
● Discovering a new NP-complete problem.
● Gadget-Based Reductions
● A common technique in NP reductions.
● 3-Colorability
● A more elaborate NP-completeness reduction.
Recap from Last Time
Polynomial-Time Reductions
● If L1 ≤P L2 and L2 ∈ P, then L1 ∈ P.
● If L1 ≤P L2 and L2 ∈ NP, then L1 ∈ NP.

P NP
NP-Hardness
● A language L is called NP-hard if for every L' ∈ NP, we
have L' ≤P L.
● A language in L is called NP-complete if L is NP-hard and
L ∈ NP.
● The class NPC is the set of NP-complete problems.

NP NP-Hard
NPC
P
The Tantalizing Truth
Theorem: If any NP-complete language is in P, then
P = NP.

P = NP
The Tantalizing Truth
Theorem: If any NP-complete language is not in P,
then P ≠ NP.

NP
NPC
P
How do we even know NP-complete
problems exist in the first place?
Satisfiability
● A propositional logic formula φ is called
satisfiable if there is some assignment to
its variables that makes it evaluate to true.
● p ∧ q is satisfiable.
● p ∧ ¬p is unsatisfiable.
● p → (q ∧ ¬q) is satisfiable.
● An assignment of true and false to the
variables of φ that makes it evaluate to
true is called a satisfying assignment.
SAT
● The boolean satisfiability problem
(SAT) is the following:
Given a propositional logic
formula φ, is φ satisfiable?
● Formally:
SAT = { ⟨φ⟩ | φ is a satisfiable PL
formula }
Theorem (Cook-Levin): SAT is NP-complete.

Proof: Take CS154!


New Stuff!
A Simpler NP-Complete Problem
Literals and Clauses
● A literal in propositional logic is a
variable or its negation:
● x
● ¬y
● But not x ∧ y.
● A clause is a many-way OR (disjunction)
of literals.
● (¬x ∨ y ∨ ¬z)
● (x)
● But not x ∨ ¬(y ∨ z)
Conjunctive Normal Form
● A propositional logic formula φ is in
conjunctive normal form (CNF) if it is
the many-way AND (conjunction) of
clauses.
● (x ∨ y ∨ z) ∧ (¬x ∨ ¬y) ∧ (x ∨ y ∨ z ∨ ¬w)
● (x ∨ z)
● But not (x ∨ (y ∧ z)) ∨ (x ∨ y)
● Only legal operators are ¬, ∨, ∧.
● No nesting allowed.
The Structure of CNF

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

We
We should
should pick
pick at
at least
least
one
one true
true literal
literal from
from
each
each clause.
clause.
The Structure of CNF

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

.. but
but never
never choose
choose aa literal
literal
and
and its
its negation
negation
3-CNF
● A propositional formula is in 3-CNF if
● it is in CNF, and
● every clause has exactly three literals.
● For example:
● (x ∨ y ∨ z) ∧ (¬x ∨ ¬y ∨ z)
● (x ∨ x ∨ x) ∧ (y ∨ ¬y ∨ ¬x) ∧ (x ∨ y ∨ ¬y)
● but not (x ∨ y ∨ z ∨ w) ∧ (x ∨ y)

The language 3SAT is defined as follows:
3SAT = { ⟨φ⟩ | φ is a satisfiable 3-CNF
formula }
Theorem: 3SAT is NP-Complete
Finding Additional NP-Complete Problems
NP-Completeness
Theorem: Let L₁ and L₂ be languages. If
L₁ ≤P L₂ and L₁ is NP-hard, then L₂ is NP-hard.
Theorem: Let L₁ and L₂ be languages where
L₁ ∈ NPC and L₂ ∈ NP. If L₁ ≤P L₂, then
L₂ ∈ NPC.

NP
P
NPC
Be Careful!
● To prove that some language L is NP-complete, show
that L ∈ NP, then reduce some known NP-complete
problem to L.
● Do not reduce L to a known NP-complete problem.
● We already knew you could do this; every NP problem is
reducible to any NP-complete problem!

NP
P
NPC
So what other problems are NP-complete?
An independent set in an undirected graph
is a set of nodes that have no edges between them.
The Independent Set Problem
● Given an undirected graph G and a
natural number n, the independent set
problem is
Does G contain an independent set
of size at least n?
● As a formal language:
INDSET = { ⟨G, n⟩ | G is an
undirected graph with an
independent set of size at least n }
INDSET ∈ NP

The independent set problem is in NP.
● Here is a polynomial-time verifier that
checks whether S is an n-element
independent set:
V = “On input ⟨G, n, S⟩, where G is a graph,
n ∈ ℕ, and S is a set of nodes in G:
If |S| < n, reject.
For each edge in G, if both
endpoints are in S, reject.
Otherwise, accept.”
INDSET ∈ NPC
● The INDSET problem is NP-complete.
● To prove this, we will find a polynomial-
time reduction from 3SAT to INDSET.
● Goal: Given a 3CNF formula φ, build a
graph G and number n such that φ is
satisfiable iff G has an independent set of
size n.
● How can we accomplish this?
From 3SAT to INDSET
● To convert a 3SAT instance φ to an INDSET
instance, we need to create a graph G and
number n such that an independent set of size
at least n in G
● gives us a way to choose which literal in each
clause of φ should be true,
● doesn't simultaneously choose a literal and its
negation, and
● has size polynomially large in the length of the
formula φ.
From 3SAT to INDSET

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

Any independent set in this graph


chooses exactly one literal from
each clause to be true.
From 3SAT to INDSET

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

We need a way to ensure we never


pick a literal and its negation.
From 3SAT to INDSET

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

If this graph has an independent set of


size three, the original formula is satisfiable.
From 3SAT to INDSET
x = false, y = false, z = false.

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

If this graph has an independent set of


size three, the original formula is satisfiable.
From 3SAT to INDSET
x = false, y = true, z = false.

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

If the original formula is satisfiable,


this graph has an independent set of size three.
From 3SAT to INDSET
● Let φ = C1 ∧ C2 ∧ … ∧ Cn be a 3-CNF formula.
● Construct the graph G as follows:
● For each clause Ci = x1 ∨ x2 ∨ x3, where x1, x2, and x3
are literals, add three new nodes into G with edges
connecting them.
● For each pair of nodes vi and ¬vi, where vi is some
variable, add an edge connecting vi and ¬vi. (Note
that there are multiple copies of these nodes)
● Claim One: This reduction can be computed in
polynomial time.
● Claim Two: G has an independent set of size n
iff φ is satisfiable.
INDSET ∈ NPC
● Theorem: INDSET is NP-complete.
● Proof sketch: We just showed that
INDSET ∈ NP and that 3SAT ≤p INDSET.
Therefore, INDSET is NP-complete. ■
Time-Out For Announcements!
Please evaluate this course in Axess.
Your feedback really makes a difference.
Final Exam Logistics
● The final exam is next Monday, June 8 from
8:30AM – 11:30AM.
● Sorry about the time – that was the registrar's decision.
Please put down the pitchforks and torches. ☺
● Same format as midterms: three hours, closed-
book, closed-computer, open one page of notes.
● Topic coverage, roughly:
● About 1/3 on discrete mathematics.
● About 1/3 on regular and context-free languages.
● About 1/3 on R, RE, P, and NP.
Practice Final Exam
● We will be holding a practice final exam on
Thursday, June 4 from 1:00PM – 4:00PM,
location TBA.
● Same format as the practice midterms:
show up, give it your best shot, and we'll
answer questions afterwards.
● Practice exam will be posted online later
that day; solutions will be in the normal
filing cabinet.
Extra Practice Problems
● We will release three extra sets of practice
problems this week:
● EPP7: Out today, solutions out Wednesday.
● EPP8: Out Wednesday, solutions out Friday.
● EPP9: Out with solutions on Friday.
● These will be cumulative review from across
the quarter.
● Have any topics you'd like extra practice with?
Let us know!
Your Questions
“Do you think math is hardwired into the
universe? Or is it merely a human invention or
construct that provides useful tools for problem
solving in a myriad of fields?”

“Are languages (regular, context-free, etc.) real?


Are they some kind of abstraction stemming from
the human mind? Or do they actually exist,
whether we ever knew about them or not?”

“All
“All models
models are
are wrong;
wrong; some
some are
are useful”
useful”

Personally,
Personally, II think
think it's
it's all
all made
made up
up and
and has
has little
little to
to no
no
bearing
bearing on
on how
how the
the universe
universe actually
actually works.
works. ItIt would
would bebe
astounding
astounding ifif we
we could
could somehow
somehow figure
figure out
out something
something deep
deep
and
and fundamental
fundamental about
about the
the universe
universe given
given all
all of
of our
our
biological
biological limitations.
limitations. That's
That's just
just me,
me, though.
though. ☺

“Any recommendations for the summer?
Good books to read, things to do, movies to
watch, etc...”
Try
Try to
to travel
travel ifif you
you can.
can. The
The weather's
weather's nice.
nice. ☺

Watch
Watch “Jiro
“Jiro Dreams
Dreams of
of Sushi”
Sushi” with
with aa group
group and
and talk
talk about
about it.
it.
It's
It's aa great
great conversation
conversation starter,
starter, especially
especially ifif you're
you're talking
talking
to
to other
other Stanford
Stanford students.
students. Other
Other good
good movies:
movies: “Seven
“Seven
Samurai,”
Samurai,” “Yojimbo,”
“Yojimbo,” “Nightcrawler,”
“Nightcrawler,” “Brazil,”
“Brazil,” and
and “The
“The
Babadook.”
Babadook.”
“Are we sure that P ≟ NP is solvable?”

Actually,
Actually, no,
no, we're
we're not!
not!

The class RE
The class RE corresponds
corresponds toto problems
problems where
where “yes”
“yes” answers
answers can
can be
be
proven,
proven, and
and the class NP
the class NP corresponds
corresponds to
to problems
problems where
where “yes”
“yes” answers
answers
can
can be
be proven
proven with
with aa short
short proof.
proof. Therefore,
Therefore, there's
there's aa risk
risk that
that
PP ≟≟ NP
NP actually
actually might
might not
not be
be solvable
solvable by
by any
any reasonably-sized
reasonably-sized proof
proof
because
because reasoning about NP
reasoning about NP requires
requires reasoning
reasoning about
about short
short proofs.
proofs.

There
There isis also
also aa nontrivial
nontrivial camp
camp of
of people
people that
that believe
believe that
that the
the answer
answer
to PP ≟≟ NP
to NP might
might not
not bebe provable
provable or
or disprovable
disprovable with
with the
the standard
standard
mathematical
mathematical axioms.
axioms. If If so,
so, itit might
might be
be possible
possible to
to prove
prove that
that we
we can't
can't
prove
prove it,
it, or
or itit may
may be
be impossible
impossible to to prove
prove that
that we
we can't
can't prove
prove it.
it.
(Think
(Think about
about that
that one
one for
for aa minute.)
minute.)
“What's on your bucket list?”

I'd
I'd like
like to
to go
go visit
visit Turkey.
Turkey. I'd
I'd
also
also like
like to
to go
go to
to the
the moon
moon ––
come
come on,
on, how
how cool
cool would
would that
that be?
be?

I'd
I'd also
also like
like to
to fly
fly around
around inin aa
blimp
blimp for
for aa day,
day, preferably
preferably
somewhere
somewhere scenic.
scenic.
Back to CS103!
Structuring NP-Completeness Reductions
The Shape of a Reduction
● Polynomial-time reductions work by solving one
problem with a solver for a different problem.

Most problems in NP have different pieces that
must be solved simultaneously.
● For example, in 3SAT:
● Each clause must be made true,
● but no literal and its complement may be picked.
● In INDSET:
● You can choose any nodes you want to put into the set,
● but no two connected nodes can be added.
Reductions and Gadgets
● Many reductions used to show NP-
completeness work by using gadgets.
● Each piece of the original problem is
translated into a “gadget” that handles
some particular detail of the problem.
● These gadgets are then connected
together to solve the overall problem.
Gadgets in INDSET

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

Each of these gadgets is designed


to solve one part of the problem:
ensuring each clause is satisfied.
Gadgets in INDSET

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )

y ¬y y

x ¬z ¬x z ¬x ¬z

These connections ensure that the solutions


to each gadget are linked to one another.
Gadgets in INDSET

¬x

x ¬y

¬x
A More Complex Reduction
A 3-coloring of a graph is a way of coloring its
nodes one of three colors such that no two connected
nodes have the same color.
The 3-Coloring Problem
● The 3-coloring problem is
Given an undirected graph G,
is there a legal 3-coloring of its
nodes?
● As a formal language:
3COLOR = { ⟨G⟩ | G is an undirected
graph with a legal 3-coloring. }
● This problem is known to be NP-complete
by a reduction from 3SAT.
3COLOR ∈ NP
● We can prove that 3COLOR ∈ NP by
designing a polynomial-time
nondeterministic TM for 3COLOR.
● M = “On input ⟨G⟩:
● Nondeterministically guess an assignment
of colors to the nodes.
● Deterministically check whether it is a 3-
coloring.
● If so, accept; otherwise reject.”
A Note on Terminology
● Although 3COLOR and 3SAT both have “3” in
their names, the two are very different
problems.
● 3SAT means “there are three literals in every
clause.” However, each literal can take on only
one of two different values.
● 3COLOR means “every node can take on one of
three different colors.”
● Key difference:
● In 3SAT variables have two choices of value.
● In 3COLOR nodes have three choices of value.
Why Not Two Colors?
● It would seem that 2COLOR (whether a graph
has a 2-coloring) would be a better fit.
● Every variable has one of two values.
● Every node has one of two values.
● Interestingly, 2COLOR is known to be in P and
is conjectured not to be NP-complete.
● Though, if you can prove that it is, you've just
won $1,000,000!
From 3SAT to 3COLOR
● In order to reduce 3SAT to 3COLOR, we need
to somehow make a graph that is 3-colorable
iff some 3-CNF formula φ is satisfiable.
● Idea: Use a collection of gadgets to solve the
problem.
● Build a gadget to assign two of the colors the
labels “true” and “false.”
● Build a gadget to force each variable to be either
true or false.
● Build a series of gadgets to force those variable
assignments to satisfy each clause.
Gadget One: Assigning Meanings

O
These nodes
must all have
different
colors.
T F

The color assigned to T will be interpreted as “true.”


The color assigned to F will be interpreted as “false.”
We do not associate any special meaning with O.
Gadget Two: Forcing a Choice

( x ∨ y ∨ ¬z ) ∧ ( ¬x ∨ ¬y ∨ z ) ∧ ( ¬x ∨ y ∨ ¬z )
T F

x ¬x y ¬y z ¬z
Gadget Three: Clause Satisfiability

( x ∨ y ∨ ¬z )

This
This node
node isis
colorable
colorable iff
iff one
one of
of
the
the inputs
inputs isis the
the
same
same color
color asas TT

x T y F ¬z
Gadget Three: Clause Satisfiability

( x ∨ y ∨ ¬z )

This
This node
node cannot
cannot
bebe colored
colored

x T y F ¬z
Gadget Three: Clause Satisfiability

( x ∨ y ∨ ¬z )

Every
Every other
other
combination
combination of
of inputs
inputs
can
can give
give this
this aa color
color

x T y F ¬z
Putting It All Together
● Construct the first gadget so we have a
consistent definition of true and false.
● For each variable v:
● Construct nodes v and ¬v.
● Add an edge between v and ¬v.
● Add an edge between v and O and between ¬v
and O.
● For each clause C:
● Construct the earlier gadget from C by adding in
the extra nodes and edges.
Putting It All Together

C1 C2 … Cn

T F

x1 ¬x1 ... ... xk ¬xk


Next Time
● The Big Picture
● How do all of our results relate to one
another?
● Where to Go from Here
● What's next in CS theory?

You might also like