graph G"(V",E") is a sub-graph of graph G(V,E), if:
V" is a sub-set of V
E" must have all Edges from E, which connect 2 vertices that exist in V"
Storing all sub-graphs of any number of vertices Space Complexity:
TIME & SPACE = SUM { k * (|V|-k+1) } for k: 1..|V|
TIME & SPACE = 1/6 n (n+1) (n+2)
TIME & SPACE ~ O(|V|^3 + |V|^2 + |V| + ..)
In English, you will need huge amount of space, to keep all possible sub-graphs of G.
TIME & SPACE ~ SUM { (|V|-k+1) * SPACE(Gk) }
for k: 1..|V|, SPACE(Gk): size of sub-graph with k nodes
The algorithm to obtain all possible sub-graphs is a brute-force algorithm ..
algorithm (in Java):
public class SubGraphs
{
public static ArrayList<Graph> getAllSubsets (Graph g)
{
// i: 1,2,3 .. |V|
for (int i=1; i<graph.V.size(); i++)
{
addSubsets(subsets, i);
}
}
public static void addSubsets (ArrayList<Graph>, int i)
{
// generate all k-permutations from set V
ArrayList<Node[]> perm = generateAllPerm(graph.V, graph.V.size()-i);
// Ex: abc ~ 3:abc ; 2:ab,ac,bc ; 1:a,b,c
for (Node[] p : perm)
{
subsets.add(removeVerticesFromGraph(graph, p));
}
}
}