# Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.
BUILT-IN WOLFRAM LANGUAGE SYMBOL

# Groupings

Groupings[n,k]
gives a list of all possible groupings of 1,,n taken k at a time.

Groupings[{a1,,an},k]
gives all possible groupings of a1,,an taken k at a time.

Groupings[{{a1,a2,},{b1,b2,},},k]
gives the combination of all possible groupings of each of the lists ai,bi, taken k at a time.

Groupings[aspec,fk]
gives all possible groupings of aspec taken k at a time with the function f applied at each level.

Groupings[aspec,{f1k1,f2k2,}]
gives all possible groupings in which the function fi is applied to ki elements.

Groupings[aspec,{{f1k1,m1},{f2k2,m2},}]
allows at most mi occurrences in a given grouping of fi applied to ki elements.

Groupings[aspec,kspec,h]
wraps the function h around each grouping generated.

## DetailsDetails

• Groupings[n,k] can be thought of as generating a list of k-ary expression trees with n leaves.
• In Groupings[{a1,,an},k], the integer n gives the number of leaves on the tree and k gives the number of children of each node.
• Arities k and ki must be positive integers.
• With an arity specification f->{k,Orderless}, Groupings returns only one representative for each collection of expressions whose tree structure is equivalent up to permutation of the branches of f.

## ExamplesExamplesopen allclose all

### Basic Examples  (5)Basic Examples  (5)

Construct all binary expression trees with four leaves:

 In[1]:=
 Out[1]=

Visualize them:

 In[2]:=
 Out[2]=

Construct all ternary trees with leaves in the given list:

 In[1]:=
 Out[1]=

Construct groupings from several lists of leaves:

 In[1]:=
 Out[1]=

Construct all binary trees with three leaves in the given list:

 In[1]:=
 Out[1]=

Use different heads with different arities:

 In[1]:=
 Out[1]=