Function Repository Resource:

LexicographicSubsets

Source Notebook

List the subsets of a set in lexicographic order

Contributed by: Wolfram Staff (original content by Sriram V. Pemmaraju and Steven S. Skiena)

ResourceFunction["LexicographicSubsets"][l]

gives all subsets of set l in lexicographic order.

ResourceFunction["LexicographicSubsets"][n]

gives all subsets of {1,2,,n} in lexicographic order.

Examples

Basic Examples (1) 

The subsets of {a,b,c} in lexicographic order:

In[1]:=
ResourceFunction["LexicographicSubsets"][{a, b, c}]
Out[1]=

Properties and Relations (2) 

All subsets of {1,2,3} in lexicographic order:

In[2]:=
ResourceFunction["LexicographicSubsets"][{1, 2, 3}]
Out[2]=

In canonical order, shorter subsets go first:

In[3]:=
Subsets[{1, 2, 3}]
Out[3]=

Generate subsets in lexicographic order sequentially using the resource function NextLexicographicSubset:

In[4]:=
NestList[ResourceFunction["NextLexicographicSubset"][{1, 2, 3}, #] &, {}, 7]
Out[4]=

Or together using LexicographicSubsets:

In[5]:=
ResourceFunction["LexicographicSubsets"][{1, 2, 3}]
Out[5]=
In[6]:=
% === %%
Out[6]=

Version History

  • 1.0.0 – 15 July 2020

Related Resources

License Information