2

Subgraph isomorphism

We have the graphs G_1=(V_1,E_1), G_2=(V_2,E_2).

Question: Is the graph G_1 isomorphic to a subgraph of G_2 ?

(i.e. is there a subset of vertices of G_2, V ⊆ V_2 and subset of the edges of G_2, E ⊆ E_2 such that |V|=|V_1| and |E|=|E_1| and is there a one-to-one matching of the vertices of G_1 at the subset of vertices V of G_2, f:V_1 -> V such that {u,v} ∈ E_1 <=> { f(u),f(v) } ∈ E)

  • Show that the problem Subgraph isomorphism belongs to NP.
  • Show that the problem is NP-complete reducing the problem Clique to it. (Hint: consider that the graph G_1 is complete)

I have tried the following:

  • A non-deterministic Turing machine first "guesses" the subset of nodes V and the subset of edges E of G_2 and after that it verifies that |V|=|V_1| and |E|=|E_1| and that there is a one-to-one correspondence f: V_1 -> V such that {u,v} ∈ E_1 <=> { f(u), f(v) } ∈ E .

Since there are O(|V_2|^2) different pairs of vertices, the check requires polynomial time. So the problem belongs to NP.

  • Let (G,k) an arbitrary instance of the clique problem, where k is the number of vertices of the clique.

We can construct an instance of the Subgraph isomorphism problem in polynomial time as follows: G_2 is a graph on n vertices.

G_1 is a complete graph on k vertices, for some k <= n. Let G=G_2. The problem Subgraph Isomorphism has a solution iff there is a complete subgraph of G_2 with k vertices, i.e. iff the graph G has a complete subgraph with k vertices.

Thus, the instance of the problem Subgraph Isomorphism has a solution iff the initial instance of the problem Clique has a solution.

Therefore, the problem Subgraph Isomorphism is NP-complete.

Could you tell me if it is right or if I could improve something?

Mary Star
  • 375
  • 7
  • 27
  • 2
    Your solutions seems correct on both parts to me. – amit Apr 19 '15 at 08:22
  • @amit How could we justify further at the first part that the check requires polynomial time? – Mary Star Apr 19 '15 at 10:41
  • You pretty much did it, you check all possible pairings - there are O(n^2) of those, and for each you check if it fits, each such check is `O(|E_1|)<=O(n^2)`. This yields total of O(n^4) algorithm to check if a given subgraph is isomorph or not, which is polynomial in the size of the input. – amit Apr 19 '15 at 10:45
  • @amit I am a little confused right now. At the beginning we say that a non-deterministic Turing machine first "guesses" the subset of nodes V and the subset of edges E of G_2. Then don't we have to look at all the V nodes that we have chosen in order to check if there are |V_1| of them such that {1,....,V}={1,....,V_1} ? Or am I wrong? If so, after that don't we look at the edges? If I am right, wouldn't the check require O(|V|^2) time, if we assume that the graphs are represented by adjacency matrices? – Mary Star Apr 19 '15 at 10:50
  • You first have to also "guess" the right pairing, which vertex from V1 matches which vertex from V2. There are O(n^2) such vertices. For each matching, you go through each vertex, and see that the edges connected to this vertex are also fine (identical). This takes O(E) time, and is repeated for each possible matching out of the n^2 possibilities, so the complexity is O(|V|^2 * |E|) <= O(|V|^4) - which is polynomial. – amit Apr 19 '15 at 10:56
  • @amit The guessing step at which the Turing machine guesses the subset of nodes V and the subset of edges E of G_2 requires constant time, right? Then at the guessing step, vwe want to verify that |V|=|V_1| and |E|=|E_1| and that there is a 1-1 f: V_1 -> V such that {u,v} ∈ E_1 <=> { f(u), f(v) } ∈ E. Since we want if the graph G_1 is isomorphic to a subgraph of G_2 , we have to go through each of the V vertices of the subgraph of G_2 to check if they are the same with the V_1 vertices of the graph G_1, and that requires O(|V|*|V_1|) =O(|V|^2) time. Right so far? – Mary Star Apr 19 '15 at 11:28
  • @amit Then do we go through all the edges E to check if they are the same with the E_1 edges of the graph G_1? Or have I understood it wrong? – Mary Star Apr 19 '15 at 11:28
  • Yes, and that totals in O(|V|^2|E|) <= O(|V|^4), which is polynomial. – amit Apr 19 '15 at 11:30
  • @amit If we go through all the edges E to check if they are the same with the E_1 edges of the graph G_1, why is O(|E|) time required and not O(|E|*|E_1|)? Could you explain it further to me? – Mary Star Apr 19 '15 at 11:37
  • You go through the adjacency list of one graph, and for each `v` you check if the list is identical to the one of `f(v)` as a set, this is simply done by populating a set of the list of `v`, and than for the list of `f(v)` - for each edge `(f(v),f(u))`, remove `u` from the set (if it does not exist - done and the suggested pairing is wrong). When you are done, the set should be empty. It takes O(|E_v|) for every `v`, where `E_v` is the subset of edges connected to `v`. Sum `E_v` for all `v` in `V`, and you get `E`. – amit Apr 19 '15 at 11:53
  • So does this mean that if v and f(v) have the same outgoing edges, will the vertices at the adjacency lists of both graphs have the same order? @amit – Mary Star Apr 19 '15 at 12:04

0 Answers0