Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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])