22NP Complete 1
22NP Complete 1
the class NP
• If any NP-complete problem can be solved by a
CS 3813: Introduction to Formal polynomial time deterministic algorithm, then
Languages and Automata every problem in NP can be solved by a
polynomial time deterministic algorithm
• But no polynomial time deterministic algorithm
NP-Completeness is known to solve any of them
Polynomial-time reduction
Examples of NP-complete problems
Let L1 and L2 be two languages over alphabets
• Traveling salesman problem Σ1 and Σ2,, respectively. L1 is said to be
• Hamiltonian cycle problem polynomial-time reducible to L2 if there is a
• Clique problem total function f: Σ1*→ Σ2* for which
• Subset sum problem 1) x ∈ L1 if an only if f(x) ∈ L2, and
• Boolean satisfiability problem 2) f can be computed in polynomial time
The function f is called a polynomial-time
• Many thousands of other important
computational problems in computer science, reduction.
mathematics, economics, manufacturing,
communications, etc.
Exercise
Another view In English, describe a Turing machine that
Polynomial-time
NP-complete problems
polynomial time. Using machine that computes the
Set of instances of Problem Q Set of instances of Problem Q’ big-O notation, give the reduction.
reduction reduces L1 to L2 in time complexity of the
second problem entails a yes (or no) answer to the first.
One decision problem is polynomial-time reducible to – L1 = {aibiaj} L2 = {cidi} – L1 = {ai(bb)i} L2 =
another if a polynomial time algorithm can be developed
that changes each instance of the first problem to an {aibi}
instance of the second such that a yes (or no) answer to the
1
A more interesting polynomial-time reduction • Partition Problem: Given a finite set of
• The Hamiltonian cycle problem can be polynomial-time integers, determine if it can be partitioned into
reduced to the traveling salesman problem. two sets such that the sum of all integers in the
• For any undirected graph G, we show how to construct an first set equals the sum of all integers in the
undirected weighted graph G’ and a bound B such that G has second set
a Hamiltonian cycle if and only if there is a tour in G’ with
total weight bounded by B. • Subset Sum Problem: Given a set of integers
• Given G = (V,E), let B = 0 and define G’ = (V,E’) as the and a number t, determine if there is a subset of
complete graph with the following weights assigned to edges:
if these integers whose sum is t.
v v E • Show that the Partition Problem is polynomial
i j wi j
0 ( , )∈ time reducible to the Subset Sum Problem
= 1 ( , )∈
if v v
, i jE
• A problem is NP-Complete if
1. It is an element of the class NP
2. Another NP-complete problem is polynomial
time reducible to it
• Show that it belongs to the class NP by describing a • Show that the problem is NP-hard by showing that
nondeterministic Turing machine that solves it in another NP-hard problem is polynomial-time
polynomial time. (This establishes an upper bound reducible to it. (This establishes a lower bound on
on the complexity of the problem.) the complexity of the problem.)
2
P ≠ NP ?
NP
• Theorem: If any NP-complete problem can be NP
solved by a polynomial-time deterministic
algorithm, then P = NP. If any problem in NP
complexity classes
• NC ⊆ P ⊆ NP ⊆ PSPACE = NPSPACE ⊆ EXPTIME
• P ≠ EXPTIME
• Saying a problem is in NP (P, PSPACE, etc.) gives an
upper bound on its difficulty
• Saying a problem is NP-hard (P-hard, PSPACE-hard,
etc.) gives a lower bound on its difficulty. It means it
is at least as hard to solve as any other problem in NP.
• Saying a problem is NP-complete (P-complete,
PSPACE-complete, etc.) means that we have
What should we do? matching upper and lower bounds on its
complexity
• Just because a problem is NP-complete,
doesn’t mean we should give up on trying to Complexity classes
solve it.
• A complexity class is a class of problems grouped
• For some NP-complete problems, it is possible together according to their time and/or space
to develop algorithms that have average-case complexity
polynomial complexity (despite having worst • NC: can be solved very efficiently in parallel • P:
case exponential complexity) solvable by a DTM in poly-time (can be solved
• For other NP-complete problems, approximate efficiently by a sequential computer)
solutions can be found in polynomial time. • NP: solvable by a NTM in poly-time (a solution can be
checked efficiently by a sequential computer) • PSPACE:
Developing good approximation algorithms is
solvable by a DTM in poly-space • NPSPACE: solvable
an important area of research. by a NTM in poly-space • EXPTIME: solvable by a
DTM in exponential time
Relationships between
3