Lecture 26 181 Lecture 26 181 Notes | EduRev

: Lecture 26 181 Lecture 26 181 Notes | EduRev

 Page 1


Lecture 26 	

181 	


Page 2


Lecture 26 	

181 	

 193 	

Coping with NP-Completeness	

Is your real problem a special subcase?	

E.g. 3-SAT is NP-complete, but 2-SAT is not; ditto  3- vs 2-
coloring	

E.g. you only need planar graphs, or degree 3 graphs, …?	

Guaranteed approximation good enough?	

E.g. Euclidean TSP within 2 * Opt in poly time	

Fast enough in practice (esp. if n is small), 	

E.g. clever exhaustive search like backtrack, branch & 
bound, pruning	

Heuristics – usually a good approximation and/or 
usually fast	


Page 3


Lecture 26 	

181 	

 193 	

Coping with NP-Completeness	

Is your real problem a special subcase?	

E.g. 3-SAT is NP-complete, but 2-SAT is not; ditto  3- vs 2-
coloring	

E.g. you only need planar graphs, or degree 3 graphs, …?	

Guaranteed approximation good enough?	

E.g. Euclidean TSP within 2 * Opt in poly time	

Fast enough in practice (esp. if n is small), 	

E.g. clever exhaustive search like backtrack, branch & 
bound, pruning	

Heuristics – usually a good approximation and/or 
usually fast	

194 	

5 
3 
4 
6 
4 
7 
2 
5 
8 
           Example:	

	

          b = 34	

NP-complete problem: TSP	

Input: An undirected graph 
G=(V,E) with integer edge 
weights, and an integer b.	

Output: YES iff there is a 
simple cycle in G passing 
through all vertices (once), 
with total cost = b.	


Page 4


Lecture 26 	

181 	

 193 	

Coping with NP-Completeness	

Is your real problem a special subcase?	

E.g. 3-SAT is NP-complete, but 2-SAT is not; ditto  3- vs 2-
coloring	

E.g. you only need planar graphs, or degree 3 graphs, …?	

Guaranteed approximation good enough?	

E.g. Euclidean TSP within 2 * Opt in poly time	

Fast enough in practice (esp. if n is small), 	

E.g. clever exhaustive search like backtrack, branch & 
bound, pruning	

Heuristics – usually a good approximation and/or 
usually fast	

194 	

5 
3 
4 
6 
4 
7 
2 
5 
8 
           Example:	

	

          b = 34	

NP-complete problem: TSP	

Input: An undirected graph 
G=(V,E) with integer edge 
weights, and an integer b.	

Output: YES iff there is a 
simple cycle in G passing 
through all vertices (once), 
with total cost = b.	

195 	

€ 
lim
n?8
NN
OPT
?8
TSP - Nearest Neighbor Heuristic	

NN Heuristic –go to nearest unvisited vertex	

Fact: NN tour can be about (log n) x opt, i.e.  (above example is not that bad)	


Page 5


Lecture 26 	

181 	

 193 	

Coping with NP-Completeness	

Is your real problem a special subcase?	

E.g. 3-SAT is NP-complete, but 2-SAT is not; ditto  3- vs 2-
coloring	

E.g. you only need planar graphs, or degree 3 graphs, …?	

Guaranteed approximation good enough?	

E.g. Euclidean TSP within 2 * Opt in poly time	

Fast enough in practice (esp. if n is small), 	

E.g. clever exhaustive search like backtrack, branch & 
bound, pruning	

Heuristics – usually a good approximation and/or 
usually fast	

194 	

5 
3 
4 
6 
4 
7 
2 
5 
8 
           Example:	

	

          b = 34	

NP-complete problem: TSP	

Input: An undirected graph 
G=(V,E) with integer edge 
weights, and an integer b.	

Output: YES iff there is a 
simple cycle in G passing 
through all vertices (once), 
with total cost = b.	

195 	

€ 
lim
n?8
NN
OPT
?8
TSP - Nearest Neighbor Heuristic	

NN Heuristic –go to nearest unvisited vertex	

Fact: NN tour can be about (log n) x opt, i.e.  (above example is not that bad)	

198 	

2x Approximation to EuclideanTSP	

A TSP tour visits all vertices, so contains a spanning tree, so 
TSP cost is > cost of min spanning tree.	

Find MST	

Find “DFS” Tour	

Shortcut	

TSP = shortcut < DFST = 2 * MST < 2 * TSP	

5 
3 
4 
2 
5 
6 
4 
7 
8 
Read More
Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!