Design and
Analysis of
Algorithms
SLAYING THE NP-HARD
DRAGON
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms NP-completeness 2
LOGISTICS
Input for
SAT
Output for
SAT
Algorithm for Known NPC Problem – Say SAT
Reduction
from
SAT to X
Algorithm
for X
x R(x)
Yes/No
Algorithms NP-completeness 3
GOOD NEWS: REDUCIBILITY
Problem X is at least as hard as SAT.
Problem X is NP-Hard.
 Business problems are not NP-complete
Algorithms NP-completeness 4
BAD NEWS: PROVING THAT SOMETHING IS
NPC IS NOT THE END OF THE GAME
MECHANISMS TO SOLVE REAL LIFE
PROBLEMS – NPC OR OTHERWISE
Strategy 1: Look for simplifications that render the
problem solvable in polynomial time
Strategy 2: Look for improvements in running time
which make the exponential “bearable”
Strategy 3: Understand performance bounds that are
acceptable practically, and use approximation
algorithms
Strategy 4: Use parallel processing, cloud computing
and server farms (Google, Facebook and government
agencies do it)
Algorithms NP-completeness 5
 For general graphs, this problem is NPC
 What if your graph is a tree (or a forest)?
 MIS in Trees is very easily solvable
 Recursive Formulation coming up next..
Algorithms NP-completeness 6
MAXIMUM INDEPENDENT SET (MIS)
 Consider a tree (or subtree) rooted at node v
 NMIS(v): maximum independent set for the tree rooted at
node v, such that v cannot be in the set.
 MIS(v): maximum independent set for the tree rooted at
node v.
 If v is a leaf node, |NMIS(v)| = 0, |MIS(v)| = 1
 Otherwise, MIS(v) = max {
{v} union NMIS(u) for all child nodes u of v,
MIS(u) for all child nodes u of v
}
 NMIS(v) = union of MIS(u) for all child nodes u of v
 How long does this take?
Algorithms NP-completeness 7
MIS IN TREES
 Given S ⊆ V, Let C(S, j) be the shortest path that
starting at 1, visits all nodes in S and ends at j. (1
and j must be in S.)
 If |S| = 2, then C(S, k) = d(1,k) for k = 2… n
 If |S| > 2, then C(S, k) = the optimal tour from
C(1,m) + d(m,k)
Algorithms NP-completeness 8
TRAVELING SALESPERSON PROBLEM – A
BETTER ALGORITHM USING DP
Note to Self: O(n2 2n) is much better than O(n!)
 An r-approximation algorithm is a polynomial time
algorithm that
 returns a feasible solution in polynomial time
 with value at most “r” times worse than optimal
 Question: How can we compare our solution to the
optimal that we cannot compute?
 Answer: lower bound optimal value
Algorithms NP-completeness 9
TSP – APPROXIMATION ALGORITHMS
 Given n cities with distances between them
 Find the shortest tour that visits each city at least once
Algorithms NP-completeness 10
EXAMPLE: TSP (1/4)
1 2
3 4
5
d(1,2)
1 2
3 4
5
1 2
3 4
5
 Removing one edge gives a spanning tree
 Kruskal’s algorithm runs in time O(n2log n)
Algorithms NP-completeness 11
LOWER BOUND (2/4)
1 2
3 4
5
1 2
3 4
5
 Run DFS on MST
 Each vertex is visited at least once
 Each edge traversed at most twice
 Value of tour at most twice the MST, if triangle
inequalities hold.
Algorithms NP-completeness 12
CONSTRUCTING TOUR FROM MST (3/4)
1
23
45
1. Find MST as lower bound
2. Construct tour by running DFS on MST
Algorithms NP-completeness 13
2-APPROXIMATION ALGORITHM (4/4)
OPTMST 2*MST
 Is the problem discrete or continuous?
 If you have a Yes/No solver for the decision version of IS problem,
we can find Maximum Independent Set in O(log n) invocations of
Yes/No solver.
 So, if problem is discrete, optimization problem is no harder than
decision problem (assuming search space if finite)
 If the problem is continuous, then read on…
 NP-Complete vs. NP-Hard
 Given a TSP tour and x: We can verify that the given TSP tour is a
valid tour (covers each city exactly once) and its cost is less than x,
in polynomial time. The decision version of the problem is in NP.
 Given a TSP tour: We do not know of a way to verify that a given
solution to TSP is indeed the optimal one. The optimization
version is not known to be in NP. It is NP-Hard, but not known to
be NP-Complete
Algorithms NP-completeness 14
DECISION VERSUS OPTIMIZATION PROBLEM
 Even NP-complete problems deserve solutions
 You can use 3 tricks to solve NPC problems
 Look for better exponential solutions
 Look for approximation scheme
 Look for idiosyncrasies in data
Algorithms NP-completeness 15
SUMMARY

NP-Completeness - II

  • 1.
  • 2.
     Instructor Prof. AmrinderArora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms NP-completeness 2 LOGISTICS
  • 3.
    Input for SAT Output for SAT Algorithmfor Known NPC Problem – Say SAT Reduction from SAT to X Algorithm for X x R(x) Yes/No Algorithms NP-completeness 3 GOOD NEWS: REDUCIBILITY Problem X is at least as hard as SAT. Problem X is NP-Hard.
  • 4.
     Business problemsare not NP-complete Algorithms NP-completeness 4 BAD NEWS: PROVING THAT SOMETHING IS NPC IS NOT THE END OF THE GAME
  • 5.
    MECHANISMS TO SOLVEREAL LIFE PROBLEMS – NPC OR OTHERWISE Strategy 1: Look for simplifications that render the problem solvable in polynomial time Strategy 2: Look for improvements in running time which make the exponential “bearable” Strategy 3: Understand performance bounds that are acceptable practically, and use approximation algorithms Strategy 4: Use parallel processing, cloud computing and server farms (Google, Facebook and government agencies do it) Algorithms NP-completeness 5
  • 6.
     For generalgraphs, this problem is NPC  What if your graph is a tree (or a forest)?  MIS in Trees is very easily solvable  Recursive Formulation coming up next.. Algorithms NP-completeness 6 MAXIMUM INDEPENDENT SET (MIS)
  • 7.
     Consider atree (or subtree) rooted at node v  NMIS(v): maximum independent set for the tree rooted at node v, such that v cannot be in the set.  MIS(v): maximum independent set for the tree rooted at node v.  If v is a leaf node, |NMIS(v)| = 0, |MIS(v)| = 1  Otherwise, MIS(v) = max { {v} union NMIS(u) for all child nodes u of v, MIS(u) for all child nodes u of v }  NMIS(v) = union of MIS(u) for all child nodes u of v  How long does this take? Algorithms NP-completeness 7 MIS IN TREES
  • 8.
     Given S⊆ V, Let C(S, j) be the shortest path that starting at 1, visits all nodes in S and ends at j. (1 and j must be in S.)  If |S| = 2, then C(S, k) = d(1,k) for k = 2… n  If |S| > 2, then C(S, k) = the optimal tour from C(1,m) + d(m,k) Algorithms NP-completeness 8 TRAVELING SALESPERSON PROBLEM – A BETTER ALGORITHM USING DP Note to Self: O(n2 2n) is much better than O(n!)
  • 9.
     An r-approximationalgorithm is a polynomial time algorithm that  returns a feasible solution in polynomial time  with value at most “r” times worse than optimal  Question: How can we compare our solution to the optimal that we cannot compute?  Answer: lower bound optimal value Algorithms NP-completeness 9 TSP – APPROXIMATION ALGORITHMS
  • 10.
     Given ncities with distances between them  Find the shortest tour that visits each city at least once Algorithms NP-completeness 10 EXAMPLE: TSP (1/4) 1 2 3 4 5 d(1,2) 1 2 3 4 5 1 2 3 4 5
  • 11.
     Removing oneedge gives a spanning tree  Kruskal’s algorithm runs in time O(n2log n) Algorithms NP-completeness 11 LOWER BOUND (2/4) 1 2 3 4 5 1 2 3 4 5
  • 12.
     Run DFSon MST  Each vertex is visited at least once  Each edge traversed at most twice  Value of tour at most twice the MST, if triangle inequalities hold. Algorithms NP-completeness 12 CONSTRUCTING TOUR FROM MST (3/4) 1 23 45
  • 13.
    1. Find MSTas lower bound 2. Construct tour by running DFS on MST Algorithms NP-completeness 13 2-APPROXIMATION ALGORITHM (4/4) OPTMST 2*MST
  • 14.
     Is theproblem discrete or continuous?  If you have a Yes/No solver for the decision version of IS problem, we can find Maximum Independent Set in O(log n) invocations of Yes/No solver.  So, if problem is discrete, optimization problem is no harder than decision problem (assuming search space if finite)  If the problem is continuous, then read on…  NP-Complete vs. NP-Hard  Given a TSP tour and x: We can verify that the given TSP tour is a valid tour (covers each city exactly once) and its cost is less than x, in polynomial time. The decision version of the problem is in NP.  Given a TSP tour: We do not know of a way to verify that a given solution to TSP is indeed the optimal one. The optimization version is not known to be in NP. It is NP-Hard, but not known to be NP-Complete Algorithms NP-completeness 14 DECISION VERSUS OPTIMIZATION PROBLEM
  • 15.
     Even NP-completeproblems deserve solutions  You can use 3 tricks to solve NPC problems  Look for better exponential solutions  Look for approximation scheme  Look for idiosyncrasies in data Algorithms NP-completeness 15 SUMMARY