2
$\begingroup$

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

For example:

leafNodes={1,2,3,4,5} 
nonLeafNodes=<|a->2, b -> 3, c->2|>

Should return 311 trees:

a->{c->{1, 2}, b->{3, 4, 5}}, etc...
$\endgroup$
0

1 Answer 1

4
$\begingroup$

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

$\endgroup$

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.