Possible combinations of permutations between N variable-size sets without repetition

100 Views Asked by At

I am trying to figure out how many possible combinations of items I can have for N sets with variable number of items and how to get those combinations. Let's say I have three sets as follows.

S1: {A, B, C}
S2: {A, C}
S3: {B}

Then the expected result is:

{A, B, C} | {A, C, B} | {B, A, C} | {B, C, A} | {C, A, B} | {C, B, A}
{A, C}    | {A, C}    | {A, C}    | {A, C}    | {A, C}    | {A, C}
{B}       | {B}       | {B}       | {B}       | {B}       | {B}

{A, B, C} | {A, C, B} | {B, A, C} | {B, C, A} | {C, A, B} | {C, B, A}
{C, A}    | {C, A}    | {C, A}    | {C, A}    | {C, A}    | {C, A}    
{B}       | {B}       | {B}       | {B}       | {B}       | {B}

I suppose that for each set S1 through S3 I have to calculate all possible permutations of its items hence I will end up with three sets (S1', S2' and S3') each containing the corresponding permutations (6 for S1', 2 for S2' and 1 for S3'). Then I would calculate Cartesian product of those sets (S1' x S2' x S3').

Is such an approach correct? And what would be the formula to calculate the number of all possible combinations?