Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NthSubset function of Combinatorica package

  • To: mathgroup at
  • Subject: [mg88835] Re: NthSubset function of Combinatorica package
  • From: Szabolcs Horvát <szhorvat at>
  • Date: Sun, 18 May 2008 07:34:29 -0400 (EDT)
  • Organization: University of Bergen
  • References: <g0o7p3$ebb$>

Roman wrote:
> Hello all:
> Do you know how the function "NthSubset" of the Combinatorica package
> works? If you can point me to a description of the algorithm, that
> would be very helpful.

You can read the source code of all standard packages.  Go to 
$InstallationDirectory/AddOns/Packages/Combinatorica, and search for 
NthSubset in Combinatorica.m.  You will find that it just calls the 
built-in Subsets function.

Subsets[] is built-in, so we cannot see its implementation.  But there 
are several subset-related functions in Combinatorica, such as KSubsets, 
whose code is available.  You can check those.

Or just search the web.  Here's the first hit I got for "generating 

And a Mathematica implementation of this algorithm (for generating all 

subsets[l_List] :=
  Table[Pick[l, IntegerDigits[k, 2, Length[l]], 1],
    {k, 0, 2^Length[l] - 1}]

  • Prev by Date: Filtering a list of list for certain elements that are neighbours
  • Next by Date: Redundant manipulate
  • Previous by thread: NthSubset function of Combinatorica package
  • Next by thread: Re: Re: NthSubset function of Combinatorica package