Gallery of unlabelled trees with n vertices

8.6k Views Asked by At

Can anyone point me to a gallery (printed or online) of unlabelled trees, sorted according to their order (i.e., number of vertices)? That is, for each order n in oeis.org/A000055 (up to maybe n=11 or so) I'd like to see a visualization of all the trees.

I found Gary Fredericks' online database Small Simple Graphs but there are a few problems which make it unsuitable for my purposes: 1) It's for graphs in general as opposed to trees. (Though maybe there is some way of using the filters in this tool to suppress the graphs with cycles?) 2) It works only for n up to 9. 3) It shows only five graphs at a time, though I'd like to see all the trees for a given n on the same web page (or printed page).

Alternatively can someone point me to some code which can automatically generate images of such trees, preferably in a vector format? Then I could arrange them myself into a single web page or LaTeX document.

3

There are 3 best solutions below

3
On BEST ANSWER

geng which comes with nauty can generate these trees (along with other classes of graphs) very quickly; they can be viewed with showg. It will give a list of adjacencies and it's straightforward to write one's own script to convert it to one's desired format. The command is e.g.

geng 7 6:6 -c

for $7$-node trees.

Here's the 6 to 8 vertex trees below (it could easily extend this table to 15-node graphs, and beyond that with a bit of effort):

6-vertex

7-vertex

8-vertex

1
On

Frank Harary's Graph Theory has all the trees from p = 1 to p=10 displayed on pp. 233-234; the 10-vertex trees take up the whole page 234.

0
On

You can also enumerate them easily with the linear arrangement library. It contains an implementation of McKay's algorithm to enumerate free trees. You can either use C++ or Python.

C++:

lal::generate::all_ulab_free_trees Gen(10);
while (not Gen.end()) {
    lal::graphs::free_tree t = Gen.get_tree();
    // do whatever you want with the tree
    Gen.next();
}

Python:

Gen = lal.generate.all_ulab_free_trees(10)
while not Gen.end():
    t = Gen.get_tree()
    # do whatever you want with the tree
    Gen.next()

Using one of the two above, you can render them any way you want by filling in the "do whatever you want". Since I know a thing or two about programming I made a couple of scripts to generate first a series of .dot files and then these are rendered into .svg files. I had help from a stack overflow user in this post.

You will find said files here. There are .svg files for all trees up to 14 vertices (for 15 vertices or more the files take too long to render and the files start to get large). There are also plain text files that list the trees in a "compressed" format and also carry a label to indicate their class. The labels are a subset of {unknown, caterpillar, spider, star, bistar, linear}. Yes, some of these labels are more general than others...

EDIT I updated the files so that they contain a Copyright notice. Enjoy!