How to obtain all the subgraphs of a fixed size from a graph, in pseudocode? (brute force)
Without external libraries if possible. Thanks!
How to obtain all the subgraphs of a fixed size from a graph, in pseudocode? (brute force)
Without external libraries if possible. Thanks!
Since a graph is only edges and vertices, find all possible subsets of the vertices and construct all possible subsets of the edges on them.
More or less that would be something along these lines:
GenerateSubgraphs(Graph G):
powerV = powerset(G.V)
powerE = powerset(G.E)
subgraphs = {}
foreach V in powerV:
foreach E in powerE:
accept = true
foreach edge in E:
if edge.u not in V or edge.v not in V:
accept = false
if accept:
subgraphs.insert((V, E))
return subgraphs
EDIT: Fixed indentation of 'edges.insert' line
EDIT: Removed duplicated graphs