An easy way to determine if a given graph is a subgraph of some other graph?

I am looking for an algorithm to check if a given graph is a subgraph of another given graph.

I have few conditions to make this NP full bit of the problem more doable.

  • Graphs have approximately 20 vertices.
  • DAG graphs.
  • All vertices are not uniquely marked, and the corresponding vertices in the main graph and subgraph must have the same label. I do not know if I use the correct terminology (because I did not take a course in graph theory ...). It will be something like:

The line graph A - B is a subgraph A - B - A, but A - A is not a subgraph A - B - A.

Any suggestions are ok. This is not a homework question by the way .: D

+5
source share
3 answers

If the labels are unique, Nedges exist for the size graph O(N^2), assuming that there are no loops or multiple edges between each pair of vertices. Let use Efor the number of edges.

If you set the hashed edges in the parent graph, you can go through the edges of the subgraph by checking if each of them is in the hash table (and in the right amount, if necessary). You do this once for each edge, therefore O(E).

G ( N ) G_1 ( M ), G_1 is in G.

, - O(2^N), , O(M 2^N) - G_1 ( M ) .

G_1 is in G = isSubgraph( 0, empty bitmask)

:

isSubgraph( index, bitmask ) =
   for all vertex in G
       if G[vertex] is not used (check bitmask)
          and G[vertex] label is equal to G_1[index] label
          and isSubgraph( index + 1, (add vertex to bitmask) )
               return true
   return false

index = M, , ( ). if - , index, G_1[0..index] G[bitmask] ( ) .

N = 20 .

( , , DP).

+2

, . 1. . ,    , . 2. , .

, , ?

0

. a, V_1 V_2. a :

s (a) =\sum _ {(v, w)\in E_1}\sigma (v, w, a (v), a (w)),

\sigma (v, w, a (v), a (w)) = 1, (a (v), a (w))\in E_2, 0.

, .

0

All Articles