You will find all of them up to 7 vertices in GraphData
. Note that GraphData
is just a database. It contains all undirected simple graphs up to 7 vertices, but only certain specific instances above 7.
Get all cactus graphs from the database:
GraphData["Cactus"]
Get all 8-vertex cactus graphs from the database:
Select[GraphData[8], GraphData[#, "Cactus"] &]
Is that all of them? To check, let's write a function to test if a graph is a cactus.
ClearAll[cactusGraphQ]
cactusGraphQ[g_?UndirectedGraphQ] :=
ConnectedGraphQ[g] && AllTrue[
KVertexConnectedComponents[g, 2],
With[{sg = Subgraph[g, #]}, EdgeCount[sg] <= VertexCount[sg]] &
]
cactusGraphQ[_] := False;
Now we want to generate all non-isomorphic 8-vertex graphs and filter the list. I like to use the geng
tool from the nauty suite for this. I have it installed at /opt/local/bin/geng
. Adjust the next command with wherever you installed this tool.
glist8 = Import["!/opt/local/bin/geng -c 8", "Graph6"];
cacti8 = Select[glist8, cactusGraphQ];
Length[cacti8]
(* 188 *)
Check OEIS to confirm we made no mistake: https://oeis.org/A000083 188
is indeed correct.