# tree ordering in sage

I am using the following code to generate the isomorphism class of trees of order $n$.

sage: from sage.graphs.trees import TreeIterator
sage: def check_trees(n):
....:     trees = []
....:     for t in TreeIterator(n):
....:         if not t.is_tree():
....:             return False
....:         if t.num_verts() != n:
....:             return False
....:         if t.num_edges() != n - 1:
....:             return False
....:         for tree in trees:
....:             if tree.is_isomorphic(t):
....:                 return False
....:         trees.append(t)
....:     return True


Then when I print the trees in TreeIterator using loops it is giving the trees in a particular order.

Can anyone explain to me what is this predefined order on trees of order $n$ on sage?

For n = 6, we have the following order.

edit retag close merge delete

1

As a side-comment, when pasting code in your question please mark it as pre-formatted code (there's a button on the WYSIWYG toolbar, but you can also select the code and press Ctrl-K to indent it all at once, which causes it to be treated as pre-formatted text. I have gone ahead and fixed it for you in this case.

( 2019-08-07 14:18:49 +0200 )edit

That's a good question though. I looked at the code, and even the code does not include any commentary explaining how it works. Yes, one can read the code and figure it out, but I don't think it's at all "obvious".

( 2019-08-07 14:23:51 +0200 )edit

Sorry, I shall paste it like this in future. Thanks for your comment.

( 2019-08-08 08:13:05 +0200 )edit

Sort by » oldest newest most voted
sage: r.library("fortunes")
sage: r.fortune("'WTFM'")

This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
-- Barry Rowlingson
R-help (October 2003)


This won't give you a "ready-made" answer, but may point you in the right direction. In last resort, try the source code...

more

It's really not that obvious. No need for snark.

( 2019-08-14 12:38:56 +0200 )edit

The documentation in the reference manual says that it is using the algorithm from this paper.

more