0% found this document useful (0 votes)
29 views24 pages

Lec32 CS345

Uploaded by

shivna0809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views24 pages

Lec32 CS345

Uploaded by

shivna0809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Design and Analysis of Algorithms

CS345

Lecture 32
• NP Completeness – III
• Coping with NP-completeness

1
NP Complete problems

Is P = NP ?

P NP

NP-complete

If any NP-complete problem is solved in polynomial time


 P = NP
Showing a problem to be NP-complete

Let be a problem which we wish to show to be NP-complete


1. Show that ϵ NP
2. Pick a problem which is already known to be NP-complete
3. Show that

NP
𝑨
𝑿
EXAMPLE

Showing Dominating Set to be NP-complete

4
Dominating Set
Definition: Given an undirected graph ,
= {| or () }
In other words, is the set consisting of and all neighbors of in .
a subset is said to be an dominating set if
For each , IsIsititthe
thesmallest
smallest
dominating
dominatingset
set??
𝒃 NO.
YES

𝒂 𝒙

𝒛 𝒚 𝒕
Optimization version: compute dominating set of smallest size.
Decision version: Does there exist a dominating set of size ?

5
Dominating Set
Definition: Given an undirected graph ,
= {| or () }
In other words, is the set consisting of and all neighbors of in .
a subset is said to be a dominating set if
For each ,

Decision version:
Does there exist a dominating set of size ?

Efficient Verifier:
Input: (, , ),
Behavior:
It checks
1. || = ?
2. for each , whether ?
This algorithm takes O() time.  Dominating Set NP 6
VC DS

VC: Vertex Cover DS: Dominating Set


Input: a graph and Input: a graph and
Problem: Does there exist a vertex Problem: Does there exist a dominating
cover of size ? set of size ?

𝒃 𝒃

𝒂 𝒙 𝒂 𝒙

𝒛 𝒚 𝒕 𝒛 𝒚 𝒕

7
VC DS

Observation 1: Let be vertex cover of .


is also a dominating set for provided there is no isolated vertex in .


So without loss of generality assume does not have any isolated vertex.

8
VC DS

(, )
𝒇 (, )

Aim: Given a graph , how should transform it to graph such that


has a vertex cover of size if and only if has a dominating set of size .

9
VC DS

VC: Instance (, ) DS: Instance (, )


𝒃 𝒃

𝒂 𝒙 𝒂 𝒙

𝒛 𝒚 𝒕 𝒛 𝒕
𝒚

Theorem :
has a vertex cover of size if and only if has a dominating set of size .

10
VC DS

Theorem ():
If has a vertex cover of size
𝒗 𝒚 then has a dominating set of size .
𝒗 Proof:
Let be a vertex cover of of size .
𝒘 𝒚
Consider any vertex .
Case 1:
 is dominated (use Observation 1)
Case 2:
(,) and the edge is covered by ,
so either or .
 is dominated in this case as well 

11
VC DS
Replace by .
If is already in , Theorem ():
then just remove . If has a dominating set of size ,
then has a vertex cover of size .
𝒗 Proof:
Let be a dominating set of .
𝒘 𝒚
We can assume that .
𝒗 Now consider any edge (,) .
𝒘 𝒚 Since is dominated in .
 or .
We are done.
Lemma:
If has a dominating set of size ,
then also has a dominating set
of size . 12
MORE NP-COMPLETE PROBLEMS

13
Subgraph Isomorphism
 𝟏 𝟐

𝒂 𝒖
 𝒃 𝒗 𝟔
 𝟑
 𝒄 𝒘

𝟓 𝟒
Definition: Graph is said to be isomorphic to
if there is a bijection :  such that for any two vertices
if and only if
Problem: Given two graphs and ,
¿
does there exist a subgraph of which is isomorphic to ?

Homework: Show that subgraph isomorphism problem is NP-complete.


14
Subset sum problem
Problem:
Given a set of integers: , ,…, ,
does there exist any subset such that

Showing that subset sum problem is in NP: easy


Showing that subset sum problem is NP-complete :
neither Homework
nor Exam problem

15
HOW TO HANDLE
NP-COMPLETE PROBLEMS

Approximation Algorithms

16
Approximation algorithms

• Vertex cover problem:


There is an O() time algorithm that computes a vertex cover such that

• Dominating set problem:


There is an O() time algorithm that computes a dominating set such that

• Traveling Salesman Problem:


If triangle inequality holds : approximation ratio
If triangle inequality does not hold: no constant approximation ratio is possible

17
VERTEX COVER PROBLEM

an O() time algorithm


-approximate solution

18
The algorithm

;
While <> empty do
{ Let () be any edge present in ;
;
Remove every edge incident on ;
?
Remove every edge incident on ;
}
Return

Observation: The set is always a vertex cover of the given graph.


Homework: Prove that

19
SET COVER PROBLEM

20
Set Cover Problem
– a set = {, ,…,}
– , ,…, , with
Optimization version: Compute least number of sets that can cover .
Decision version: Does there exist subsets that can cover all elements ?

𝒆𝟐 𝒆𝟕

𝒆𝟓
𝒆𝟏
𝒆𝟑 𝒆𝟖
𝒆𝟒 𝒆𝟔
𝒆𝟗

21
Set Cover Problem
– a set = {, ,…,}
– , ,…, , with
Optimization version: Compute least number of sets that can cover .
Decision version: Does there exist subsets that can cover all elements ?

𝒆𝟐 𝒆𝟕

𝒆𝟓
𝒆𝟏
𝒆𝟑 𝒆𝟖
𝒆𝟒 𝒆𝟔
𝒆𝟗

22
Set Cover Problem
– a set = {, ,…,}
– , ,…, , with
Optimization version: Compute least number of sets that can cover .
Decision version: Does there exist subsets that can cover all elements ?

𝒆𝟐 𝒆𝟕

𝒆𝟓
𝒆𝟏
𝒆𝟑 𝒆𝟖
𝒆𝟒 𝒆𝟔
𝒆𝟗

23
Set Cover Problem
– a set = {, ,…,}
– , ,…, , with
Optimization version: Compute least number of sets that can cover .
Decision version: NP-complete Homework

Approximation algorithm for the optimization version:


;
While <> empty do
{ Pick a set such that is maximum;
Remove all elements of from ;
}
Return all subsets picked in the while loop.

Think simple.
Follow your intuition
24

You might also like