Is there a way to generate all the connected subgraphs of a graph in mathematica without going through all the subsets of the nodes and checking if the subgraph is connected (which will be O(2^N)*O(checking_connectedness) ) ?
I wrote this code which finds the subgraphs of size 2 to n :
subs[g_,n_] :=
Select[
Subgraph[g, #]& /@ Subsets[VertexList[g], {2, n}],
ConnectedGraphQ]
ConnectedComponents
? $\endgroup$1 - 2 - 3
, the subgraphs induced by(1, 2)
and(2, 3)
are good solutions, but(1, 3)
is not. I'd expect a huge number of solutions, which makes efficiency dubious ... but it's not an uninteresting problem. $\endgroup$ConnectedComponents
first. For a graph whose largest connected component has $m$ vertices, this would require $\mathcal{O}(2^m)$ checks rather than $\mathcal{O}(2^n)$. $\endgroup$