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).