graph problems - ecourse2.ccu.edu.tw

31
Department of Computer Science and Information Engineering 1 Graph Problems Instructor: Yao-Ting Huang Bioinformatics Laboratory, Department of Computer Science & Information Engineering, National Chung Cheng University.

Upload: others

Post on 18-Dec-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Department of Computer Science

and Information Engineering

1

Graph Problems

Instructor: Yao-Ting Huang

Bioinformatics Laboratory,

Department of Computer Science & Information Engineering,

National Chung Cheng University.

Dept. of Computer Science

& Information Engineering

2

Proving NP-Completeness

What steps do we have to take to prove a

problem P is NP-Complete? Pick a known NP-Complete problem Q

Reduce Q to P

Describe a transformation that maps instances of Q

to instances of P

Prove that the reduction holds “Yes for Q if and only

Yes for P”

Reduction must be in polynomial time

Dept. of Computer Science

& Information Engineering

3

Dept. of Computer Science

& Information Engineering

4

3SAT

3-CNF Satisfiability problem: Conjunction normal form (CNF)

3-conjunction normal form (3-CNF)

Every clause has three literals.

Suppose we know 3-CNF-SAT is NP-hard (we will

go back to this later).

)()()( 431423211 xxxxxxxxx

Dept. of Computer Science

& Information Engineering

5

Clique Clique is a subset of vertices fully connected to each

other.

A complete subgraph.

The clique problem:

Decision: does a clique of size k (for any k) exist in the

graph?

Optimization: ask for a maximum clique.

Dept. of Computer Science

& Information Engineering

6

3SAT => Clique

Show the Clique problem is in NP.

Verify the clique in O(n2) .

Reduction from 3SAT (with k clauses):

For each of the k clause, create a triple of vertices in

G.

For any two literals of two distinct clauses, add an

edge between them if one literal is not negation of

the other.

)()()( 431423211 xxxxxxxxx

Dept. of Computer Science

& Information Engineering

7

x1 x2 x3

x1 x1

x2 x2

x3 x3

3211 xxxC

3212 xxxC 3213 xxxC

3SAT => Clique

Dept. of Computer Science

& Information Engineering

8

The instance of 3-CNF-SAT is satisfiable if and

only if G has a clique of size k. =>

Suppose Φ is satisfiable. Then each cause contains at

least one literal assigned to be TRUE.

Pick one TRUE literal from all clauses to form a set of

vertices V’.

Is V’ a clique? For each pair of literals in V’, both of them are TRUE.

None of them are complements

There must be edges between all pairs of vertices.

3SAT => Clique

Dept. of Computer Science

& Information Engineering

9

3-CNF-SAT => Clique

The instance of 3-CNF-SAT is satisfiable if

and only if G has a clique of size k. <=

Suppose G has a clique V’ of size k.

Set TRUE to each literal of V’ for each clause.

Arbitrarily set other variables to TRUE or FALSE.

It is easy to see each clause will be satisfied.

Dept. of Computer Science

& Information Engineering

10

x1 x2 x3

x1 x1

x2 x2

x3 x3

3211 xxxC

3212 xxxC 3213 xxxC

3-CNF-SAT => Clique

x2=0, x3=1

Dept. of Computer Science

& Information Engineering

11

Independent Set

Let G = (V, E) be an undirected graph. Let I be a subset of V.

I is independent if there is no edge between nodes in I.

Dept. of Computer Science

& Information Engineering

12

Independent Set

Let G = (V, E) be an undirected graph. Let I be a subset of V.

I is independent if there is no edge between nodes in I.

The independent set problem Given a graph, is there an independent set of size K?

Clearly, in a triangle, any independent set can only have at

most one node.

How to reduce from 3SAT in similar way?

Given an instance of 3SAT, construct a graph ….

Dept. of Computer Science

& Information Engineering

13

Reduction from 3SAT

Consider a 3SAT instance with k clauses. Create a triangle for each clause with the literals

as nodes.

Add edges between x and –x for each variable.

Dept. of Computer Science

& Information Engineering

14

Reduction from 3SAT

The 3 SAT instance is satisfiable iff the

graph has an independent set of size k.

Dept. of Computer Science

& Information Engineering

15

Proof Suppose G has an independent set of size k.

An independent set can have one node in each

triangle.

Assign true to those literals in I.

The truth assignment is consistent since all

contradictory literals are connected.

All clauses (triangles) are satisfied.

The 3SAT is satisfiable.

Dept. of Computer Science

& Information Engineering

16

Proof

Suppose 3SAT is satisfiable.

Pick one node from each clause whose

value is TRUE

This set of nodes form the independent set.

Dept. of Computer Science

& Information Engineering

17

Clique vs Independent Set

The clique problem can be reduced to the

independent set problem, and vice versa. Let C be the complement graph of G.

I is a clique in C iff I is an independent set in G.

Dept. of Computer Science

& Information Engineering

18

Dept. of Computer Science

& Information Engineering

19

Vertex Cover

A vertex cover for a graph G is a set of

vertices incident to every edge in G

The vertex cover problem: does a vertex

cover of size k exist in G?

Dept. of Computer Science

& Information Engineering

20

Clique Vertex Cover

First, show vertex cover in NP. Check all edges.

Next, reduce k-clique to vertex cover

The complement GC of a graph G contains exactly

those edges not in G

Compute GC in polynomial time

G has a clique of size k iff GC has a vertex cover of

size |V| - k

Dept. of Computer Science

& Information Engineering

21

u

z w

v

xy

u

z w

v

xy

Clique Vertex Cover

GCG

Dept. of Computer Science

& Information Engineering

22

Claim: If G has a clique of size k, GC has a

vertex cover of size |V| - k

Let V’ be the k-clique

Then V -V’ is a vertex cover in GC

Let (u,v) be any edge in GC

u and v cannot both be in V’

Thus at least one of u or v is in V-V’, so

any edge (u, v) is covered by V-V’

u

z w

v

xy

u

z w

v

xy

Dept. of Computer Science

& Information Engineering

23

Claim: If GC has a vertex cover V’ with |V’| =

|V| - k, then G has a clique V of size k.

For all u,v V, if (u,v) GC then u V’ or

v V’ or both.

If u V’ and v V’, then (u,v) G

In other words, all vertices in V-V’ are connected

by an edge, thus V-V’ is a clique.

u

z w

v

xy

u

z w

v

xy

Dept. of Computer Science

& Information Engineering

24

u

z w

v

xy

u

z w

v

xy

Clique Vertex Cover

GCG

V’={z, w}V={u, v, y, x}

Dept. of Computer Science

& Information Engineering

25

Alternative Proof

Try reduction from the independent set

problem. I is an independent set of G iff V-I is a node cover

of G.

Dept. of Computer Science

& Information Engineering

26

Graph Isomorphism

An isomorphism of graphs G and H is a bijection

between the vertex sets of G and H such that any

two vertices u and v of G are adjacent in G if and

only if ƒ(u) and ƒ(v) are adjacent in H.

ƒ(a) = 1 ƒ(b) = 6 ƒ(c) = 8 ƒ(d) = 3 ƒ(g) = 5 ƒ(h) = 2 ƒ(i) =

4 ƒ(j) = 7

Dept. of Computer Science

& Information Engineering

27

Graph Isomorphism

However, the graph isomorphism problem

is neither known to be NP-complete nor

to be P. It is in NP but not in NP-complete nor in P so far.

Dept. of Computer Science

& Information Engineering

28

Subgraph Isomorphism

Input: Two graphs G1 and G2.

Question: Is G1 isomorphic to a subgraph of

G2? The subgraph isomorphism problem is a

generalization of the graph isomorphism problem.

Dept. of Computer Science

& Information Engineering

29

Subgraph Isomorphism

Input: Two graphs G1 and G2.

Question: Is G1 isomorphic to a subgraph

of G2? The subgraph isomorphism problem is a

generalization of the graph isomorphism problem.

How to prove hardness of this problem?

Hint: reduction from some problems in this

lecture.

3-SAT, vertex cover, clique, independent set.

Dept. of Computer Science

& Information Engineering

30

Subgraph Isomorphism

Reduction from the clique problem. Decision version: does a graph G contains a clique of

size K?

Construct a clique C of size K.

Run the algorithm of subgraph isomorphism to see if C

is isomorphic to subgraph of G.

G contains a clique of size K iff C is isomorphic to a

subgraph of G.

The subgraph isomorphism problem is NP-hard.

But the graph isomorphism is unknown.

Dept. of Computer Science

& Information Engineering

Conclusion

Clique is NP-hard.

Independent set is NP-hard.

Vertex cover is NP-hard.

Subgraph isomorphism is NP-hard.

Graph isomorphism is not yet clear.

31