I would like to compute all non-isomorphic trees with n nodes efficiently. I use the following approach: I create all possible trees ( Visualizing Cayley's Formula in Mathematica) and filter the list of all possible trees.
fun[code_] := Module[{v = Range[Length[code] + 2], cd = code, e = {}, c}, While[ Length[v] != 2, c = Sort[Complement[v, cd]]; AppendTo[e, {cd[[1]], c[[1]]}]; v = DeleteCases[v, c[[1]]]; cd = Drop[cd, 1];]; Graph[UndirectedEdge @@@ AppendTo[e, v], VertexSize -> 0.3, VertexLabels -> Table[i -> Placed[Style[i, White, Bold], {1/2, 1/2}], {i, v[[-1]]}], VertexStyle -> Table[i -> ColorData["Rainbow"][i/v[[-1]]], {i, v[[-1]]}]]] checkIsomorph[start_ : {}] := Module[{outList, check}, outList = start; Function[{seedling}, If[(check = FreeQ[outList, _?(IsomorphicGraphQ[seedling, #] &)]), AppendTo[outList, seedling]]; check]] n = 5; graphs = fun[#] & /@ Tuples[Range[n], n - 2]; selected = checkIsomorph[] /@ graphs; Any suggestion on how to do it faster?
Edit: I would like to be able to compute up to n=20.