Function Repository Resource:

NextLexicographicSubset

Source Notebook

Get the next subset of a given set in lexicographic order

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

ResourceFunction["NextLexicographicSubset"][l,s]

gives the lexicographic successor of subset s of set l.

Examples

Basic Examples (2) 

Get the next lexicographic subset of {1,2,3} after the subset {1,2}:

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

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

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

Version History

  • 1.0.0 – 18 March 2020

License Information