Ask Your Question
0

Obtaining all posets from binary trees up to isomorphism

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

klaaa gravatar image

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

FrédéricC gravatar image

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

n=4
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
2

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

FrédéricC gravatar image

Make your own iterator:

def tree_iter(n): 
    if n  == 0: 
        yield BinaryTree() 
        return 
    for k in range(n): 
        if k > n - k: 
            continue 
        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

Stats

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

Seen: 171 times

Last updated: Oct 26 '20