If i have a list of leaf nodes and nonleaf nodes with specified arities, how can I effieciently enumerate the possible trees?

For example:

nonLeafNodes=<|a->2, b -> 3, c->2|>

Should return 311 trees:

a->{c->{1, 2}, b->{3, 4, 5}}, etc...

1 Answer 1


Version 11, the new function Groupings does precisely what you want:

Groupings[{1,2,3,4,5}, {a->2, b->3, c->2}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.