DAA UNIT_5 Material
DAA UNIT_5 Material
in
UNIT-8
NP-HARD AND NP-COMPLETE PROBLEMS
Problem Types: Optimization and Decision
• Optimization problem: find a solution that maximizes or minimizes some
objective function
• Decision problem: answer yes/no to a question
Many problems have decision and optimization versions.
E.g.: traveling salesman problem
• optimization: find Hamiltonian cycle of minimum length
• decision: find Hamiltonian cycle of length ≤ m
Decision problems are more convenient for formal investigation of their
complexity.
Class P:
P: the class of decision problems that are solvable in O(p(n)) time, where p(n) is a
polynomial of problem’s input size n
Examples:
• searching
• element uniqueness
• graph connectivity
• graph acyclicity
• primality testing
Class NP
NP (nondeterministic polynomial): class of decision problems whose proposed
solutions can be verified in polynomial time = solvable by a nondeterministic
polynomial algorithm
A nondeterministic polynomial algorithm is an abstract two-stage procedure that:
• generates a random string purported to solve the problem
• checks whether this solution is correct in polynomial time
By definition, it solves the problem if it’s capable of generating and verifying a
solution on one of its tries
1
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
NP-Complete Problems
A decision problem D is NP-complete if it’s as hard as any
problem in NP, i.e.,
• D is in NP
• every problem in NP is polynomial-time reducible to D
2
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
NP problems
NP -complete
problem
known
NP -complete
problem
candidate
for NP -
completeness
P = NP ? Dilemma Revisited
• P = NP would imply that every problem in NP, including all NP-complete
problems, could be solved in polynomial time
• If a polynomial-time algorithm for just one NP-complete problem is
discovered, then every problem in NP can be solved in polynomial time, i.e.,
P = NP
3
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
NP problems
NP -complete
problem
• Most but not all researchers believe that P ≠ NP , i.e. P is a proper subset of
NP
APPROXIMATION ALGORITHMS
Approximation Approach
Apply a fast (i.e., a polynomial-time) approximation algorithm to get a solution
that is not necessarily optimal but hopefully close to it
Accuracy measures:
accuracy ratio of an approximate solution sa
r(sa) = f(sa) / f(s*) for minimization problems
r(sa) = f(s*) / f(sa) for maximization problems
where f(sa) and f(s*) are values of the objective function f for the approximate
solution sa and actual optimal solution s*
performance ratio of the algorithm A
the lowest upper bound of r(sa) on all instances
4
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
Multifragment-Heuristic Algorithm
Stage 1: Sort the edges in nondecreasing order of weights.
Initialize the set of tour edges to be constructed to
empty set
Stage 2: Add next edge on the sorted list to the tour, skipping
those whose addition would’ve created a vertex of
degree 3 or a cycle of length less than n. Repeat
this step until a tour of length n is obtained
Note: RA = ∞, but this algorithm tends to produce better tours
than the nearest-neighbor algorithm
Twice-Around-the-Tree Algorithm
Stage 1: Construct a minimum spanning tree of the graph
(e.g., by Prim’s or Kruskal’s algorithm)
Stage 2: Starting at an arbitrary vertex, create a path that goes
twice around the tree and returns to the same vertex
Stage 3: Create a tour from the circuit constructed in Stage 2 by
making shortcuts to avoid visiting intermediate vertices
more than once
5
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
Example
Christofides Algorithm
Stage 1: Construct a minimum spanning tree of the graph
Stage 2: Add edges of a minimum-weight matching of all the odd
vertices in the minimum spanning tree
Stage 3: Find an Eulerian circuit of the multigraph obtained in
Stage 2
Stage 3: Create a tour from the path constructed in Stage 2 by
making shortcuts to avoid visiting intermediate vertices
more than once
RA = ∞ for general instances, but it tends to produce better
tours than the twice-around-the-minimum-tree alg.
Example:
6
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
Euclidean Instances
Theorem If P ≠ NP, there exists no approximation algorithm
for TSP with a finite performance ratio.
Definition An instance of TSP is called Euclidean, if its
distances satisfy two conditions:
1. symmetry d[i, j] = d[j, i] for any pair of cities i and j
2. triangle inequality d[i, j] ≤ d[i, k] + d[k, j] for any cities i, j, k
For Euclidean instances:
7
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
Example of a 2-change
Example of a 3-change
8
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
Accuracy
• RA is unbounded (e.g., n = 2, C = m, w1=1, v1=2, w2=m, v2=m)
• yields exact solutions for the continuous version
9
For All jntu material visit us at www.jntumaterials.in and www.jntu3u.in
10