Algorthim problem...

chiwawa626

Lifer
Aug 15, 2000
12,013
0
0
Im trying to write an algorthim to do the following, but I can't seem to think it through...

Suppose you had a set of n sets like so:
ex: S = { (3,4), (1,2), (6,7) } where n=3

How would you get all the possible combos of items in the n sets?
ex: C = { (3,1,6), (3,1,7), (3,2,6), (3,2,7), (4,1,6), (4,1,7), (4,2,6), (4,2,7) }

The problem I run into when I try to think of this is if you were to write the code in lets say java, how exactly would you do this during runtime for set S of arbitrary size n?

And no, this is not homework, just part of a project im working on...
 

chiwawa626

Lifer
Aug 15, 2000
12,013
0
0
Originally posted by: chuckywang
Umm...n nested loops.

How would you do n nested loops on the fly? During runtime your given a set S and its size n, how do you run the n nested loops?
 

chiwawa626

Lifer
Aug 15, 2000
12,013
0
0
Can anyone help...

I know recursion is the answer, but maybe the fact that its soo late isnt helping...
 

sao123

Lifer
May 27, 2002
12,653
205
106
maybe you should have went to class, instead of skipping class to sleep
 

her209

No Lifer
Oct 11, 2000
56,336
11
0
Choose n sets of m sets to get total number of combination of sets

For each combination of sets, you have z choices for each set repeated n times, i.e., z^n.
 

Soccerman06

Diamond Member
Jul 29, 2004
5,830
5
81
Ah yes, C++ bullshit, I hated that class last semester, and you will this semester. Might as well end yourself now before it gets hard.