subset algorithm

L

Lee Garrington

Hey,

Is there an algorithm within the Standard C++ Library which performs the
following task :-

Given a set X and a parameter of size Y. Find all unique subsets of size Y
from the set X.

For example X = {1, 2, 3, 4} and Y = 2 would return

{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}

Thx

Lee
 
J

Jeff Schwab

Lee said:
Hey,

Is there an algorithm within the Standard C++ Library which performs the
following task :-

Given a set X and a parameter of size Y. Find all unique subsets of size Y
from the set X.

For example X = {1, 2, 3, 4} and Y = 2 would return

{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}

Math folks call those subsets "combinations," and the cardinality of the
set of all combinations having a particular cardinality Y, taken from
the set X, is called "X choose Y." I don't believe there's an algorithm
in the standard library specifically intended to produce combinations,
but it shouldn't be particularly hard to write one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top