Wolfram Research

Function Repository Resource:

MaximalSubsets

Source Notebook

Prune non-maximal subsets from a list of subsets

Contributed by: Carl Woll

ResourceFunction["MaximalSubsets"][list]

prunes non-maximal subsets from the sets in list.

Details and Options

The argument list should be a list of subsets, where each subset is a list of elements.
A non-maximal subset is a list which is completely contained in another subset.

Examples

Basic Examples

Here is a list of sets:

In[1]:=
list = {{a, b, c}, {a, b, d}, {d, e}, {d}, {a}, {a, b}, {f}};

Remove the non-maximal subsets {d}, {a}, and {a,b}:

In[2]:=
ResourceFunction["MaximalSubsets"][list]
Out[2]=

Scope

MaximalSubsets can handle a large list of subsets:

In[3]:=
SeedRandom[1];
list = DeleteDuplicates[
   RandomSample[Range@200, #] & /@ RandomInteger[{1, 99}, 1000]];

The number of maximal subsets:

In[4]:=
ResourceFunction["MaximalSubsets"][list] // Length // AbsoluteTiming
Out[4]=

Resource History

Source Metadata

Related Resources

License Information