CSC 551 Design and Analysis of Algorithms Giving credit where
credit is due These lecture notes are based on slides by Dr. Cusack
http://www.cse.unl.edu/~goddard/Courses/CSCE310J/Lectures/Lecture10-NPcomplete.pdf
Dr. Leubke http://www.cs.virginia.edu/~luebke/cs332/index.html Dr.
Goddard http://www.cse.unl.edu/~goddard/Courses/CSCE310J And
Wikipedia I have modified them and added new slides 2
Slide 3
Tractability Some problems are intractable As they grow large,
we are unable to solve them in reasonable time What is reasonable
time? Standard working definition: polynomial time On input of size
n, the worst-case running time is (n k ) Polynomial time: (n 2 ),
(n 3 ), (1) (nlgn) Not in polynomial time: (2 n ), (n n ), (n!)
3
Slide 4
Polynomial-Time Algorithms Are some problems solvable in
polynomial time? Of course: every algorithm weve studied provides
polynomial-time solution to some problem Are all problems solvable
in polynomial- time? No Most are optimization problems 4
Slide 5
NP-completeness Near the end of 60s Growing list of problems
with no efficient solution Remarkable discovery: many of these
problems were interrelated If one solved in polynomial time, all
will be solved in polynomial time NP-completeness
Slide 6
Our new focus: showing a given problem cannot be solved
efficiently!
Slide 7
Optimization/Decision Problems Optimization problems They ask:
What is the optimal solution to problem X? Examples 0-1 Knapsack
Fractional Knapsack Minimum Spanning Tree Decision problems They
ask: Is there a solution to problem X with property Y? Example Does
graph G have a MST of weight W? 7
Slide 8
Optimization/Decision Problems An optimization problem tries to
find an optimal solution A decision problem tries to answer a
yes/no question Many problems will have decision and optimization
versions E.g: MST Optimization: find an MST of graph G Decision:
does graph G have a MST of weight < W? 8
Slide 9
Our new focus: showing a given problem cannot be solved
efficiently! We will phrase optimization problems as decision
problems If the decision version (which is intuitively easier to
solve) cannot be solved effciiently, the optimization version also
cannot be solevd effciiently.
Slide 10
The Class P P: the class of decision problems that have
polynomial-time deterministic algorithms That is, they are solvable
in (n k ) A deterministic algorithm is (essentially) one that
always computes the correct answer Sample problems in P Fractional
knapsack MST Single-source shortest path Sorting 10
Slide 11
The Class NP NP (nondeterministic polynomial-time): the class
of decision problems that are verifiable in polynomial time.
11
Slide 12
Sample Problems in NP Fractional Knapsack MST Single-source
shortest path Sorting Others? Knapsack Hamiltonian Cycle Problem
Satisfiability (SAT) Conjunctive Normal Form (CNF) SAT 3-CNF SAT
12
Slide 13
Hamiltonian Cycle Problem (HCP) A hamiltonian-cycle of an
undirected graph is a simple cycle that contains every vertex
exactly once and returns to the starting vertex The
Hamiltonian-Cycle Problem: given an undirected graph G, does it
have a hamiltonian cycle? The HCP is in NP A solution is easy to
verify in polynomial time (how?) 13
Slide 14
The MILLION DOLLAR Question Does P = NP? This is literally a
million dollar question The Millennium Problems The Clay
Mathematics Institute of Cambridge, Massachusetts (CMI) has
designated 7 problems as Millennium Problems
http://www.claymath.org/millennium/ Each problem has a prize of
$1,000,000.00 to whomever solves it P = NP is one of the seven
problems 14
Slide 15
P and NP What do we mean when we say a problem is in P? A: A
solution can be found in polynomial time What do we mean when we
say a problem is in NP? A: A solution can be verified in polynomial
time What is the relation between P and NP? A: P NP, but no one
knows whether P = NP 15
Slide 16
NP-Complete Problems NPC problems are the hardest problems in
NP If any one NPC problem can be solved in polynomial time then
every NPC problem can be solved in polynomial time and in fact
every problem in NP can be solved in polynomial time (which would
show that P = NP) Thus: solve the hamiltonian-cycle in (n 100 )
time, youve proved that P = NP. Retire rich & famous. 16
Slide 17
Reduction The crux of NP-Completeness is reducibility
Informally, a problem P can be reduced to another problem Q if any
instance of P can be easily rephrased as an instance of Q, the
solution to which provides a solution to the instance of P What do
you suppose easily means? This rephrasing is called transformation
Intuitively: If P reduces to Q easily, P is no harder to solve than
Q 17
Slide 18
Reducibility An example: P: Given a set of Booleans, is at
least one TRUE? Q: Given a set of integers, is their sum positive?
Transformation: (x 1, x 2, , x n ) (y 1, y 2, , y n ) where y i = 1
if x i = TRUE, y i = 0 if x i = FALSE 18
Slide 19
Using Reductions If P is polynomial-time reducible to Q, we
denote this P P Q Definition of NP-Complete: A decision problem Q
is NPC iff 1.Q NP (What does this mean?) 2.Every problem in NP is
polynomial-time reducible to Q I.e. R P Q for every R NP 19
Slide 20
NP-Hard Problems Definition: P is NP-Hard iff Every problem in
NP is polynomial-time reducible to P I.e. R P P for every R NP So,
an alternative definition for NPC: P is NPC iff P is NP-Hard and P
NP Important: For a problem to be NP-hard it does not have to be in
class NP 20
Slide 21
The Relationship between P, NP, and NP-Hard If there is a
polynomial algorithm for any NP- hard problem Then there are
polynomial algorithms for all problems in NP And hence P = NP If P
NP, then NP-hard problems have no solutions in polynomial time If P
= NP, it does not resolve whether the NP- hard problems can be
solved in polynomial time 21
Slide 22
The Relationship between P, NP, and NP-Hard NP-Hard P = NP =
NPC NP-Hard NPC P NP If P NP If P = NP possibilities 22
Slide 23
Proving NP-Completeness Steps to prove a problem Q is NPC?
Prove Q NP Pick a known NPC problem P Reduce P to Q Describe a
transformation that maps instances of P to instances of Q, such
that yes for Q = yes for P Prove the transformation works Prove it
runs in polynomial time 23 NP-hard
Slide 24
Why reduction to single NPC problem P is okay? If P is NPC,
then every problem in NP is polynomial- time reducible to P
Transitivity: If P can be polynomial reducible to Q, then every
problem in NP is polynomial-time reducible to Q Hence, If P P Q and
P is NPC, Q is also NPC This is the key idea for today
Slide 25
Why Prove NP-Completeness? Though nobody has proven that P NP,
if you prove a problem NP-Complete, most people accept that it is
probably intractable Therefore it can be important to prove that a
problem is NP-Complete Dont need to come up with an efficient
algorithm Can instead work on approximation algorithms 25
Slide 26
NPC Problems We will now look at some NPC problems In some
cases we will also look at the transformations 26
Slide 27
Hamiltonian Cycle Problem A hamiltonian-cycle of an undirected
graph is a simple cycle that contains every vertex exactly once and
returns to the starting vertex The Hamiltonian-Cycle Problem: given
an undirected graph G, does it have a hamiltonian cycle? The HCP is
in NPC 27
Slide 28
Traveling salesman problem (TSP) The well-known traveling
salesman problem: Optimization variant: a salesman must travel to n
cities, visiting each city exactly once and finishing where he
begins. How to minimize travel time? Model as complete graph with
cost c(i,j) to go from city i to city j How would we turn this into
a decision problem? A: ask if a TSP with cost