Ask Your Question

Obtaining all posets from binary trees up to isomorphism

asked 2020-10-26 00:43:45 +0200

klaaa gravatar image

updated 2022-06-30 21:07:05 +0200

FrédéricC gravatar image

One can obtain all posets of binary trees for a given n as follows in Sage:

posets = [bt.to_poset() for bt in BinaryTrees(n)]

Is there a quick method to obtain the list of all such posets up to isomorphism?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-10-26 10:05:47 +0200

FrédéricC gravatar image

Make your own iterator:

def tree_iter(n): 
    if n  == 0: 
        yield BinaryTree() 
    for k in range(n): 
        if k > n - k: 
        for t1 in tree_iter(k): 
            for t2 in tree_iter(n - 1 - k): 
                s1 = t1.to_dyck_word() 
                s2 = t2.to_dyck_word() 
                if k < n - k or s1 <= s2: 
                    yield BinaryTree([t1, t2])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-10-26 00:43:45 +0200

Seen: 152 times

Last updated: Oct 26 '20