Brute force, and nondeterministic NestWhile[l \[Function] If[ FreeQ[VertexDegree@#, 2] \[And] TreeGraphQ@# \[And] And @@ Table[\[Not] IsomorphicGraphQ[G, #], {G, l}] ,l~Append~#,l ] &@RandomGraph@{10, 9} , {}, Length@# < 10 &] With `\[And]`, `\[Not]` and `\[Function]` counted as one character, I count 149 characters when removing the unnecessary whitespace (all whitespaces). I swear it worked immediately on my computer :) [![all graphs][1]][1] Test with `Or @@ IsomorphicGraphQ @@@ Subsets[%, {2}]` [1]: https://i.sstatic.net/obZpK.png