Message Boards Message Boards

0
|
5724 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Generating all sets of unordered pairs from a list

Posted 10 years ago

Hi everybody,

Suppose that I have a list {1,2,3,4,5,6,7,8,9,10}.

A problem can be defined as "How many different ways to choose 5 disjoint pairs of items from 10 items"

I know that the number of these sets is 9!!=9x7x5x3x1.

For example {1,2},{3,4},{5,6},{7,8},{9,10} and {1,3},{2,4},{5,6},{7,8},{9,10} are such sets and of course {1,2},{3,4},{5,6},{7,8},{9,10} ={2,1},{3,4},{5,6},{7,8},{9,10}.

My question is how can I create and export these sets in Mathematica. Is there any built in function or programming is needed?.

Thanks in advance

POSTED BY: Selcuk Kumbasar
2 Replies
Posted 10 years ago

Not sure if this is what you are asking, but:

1) Subsets[Range[10], {2}] would create all pairs where ordering is not important.

2) Then taking Subsets[Subsets[Range[10], {2}], {5}] would give all sets of 5 of these pairs, again where ordering is unimportant. If ordering of the pairs within the set of 5 is important, could try Tuples[Subsets[Range[10], {2}], 5].

3) And to export just: Export["C:\temp\pairs.txt", Subsets[Subsets[Range[10], {2}], {5}]].

POSTED BY: Adrian Ericsson
Posted 10 years ago

Hi Adrian, thank you for quick response.

From your answer I understand that I was not very clear about my question.

Subsets[Subsets[Range[10], {2}], {5}] is not the answer because the first set is {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, in which "1" s are used more than once. The list elements should be used once and ordering is not important for the pairs.

Let me give 5 sample sets to clarify

{1,2},{3,4},{5,6},{7,8},{9,10} -- {1,3},{2,4},{5,6},{7,8},{9,10} -- {1,2},{3,5},{4,6},{7,8},{9,10} -- {1,2},{3,4},{5,6},{7,9},{8,10} -- {1,2},{3,4},{5,10},{7,8},{9,6} = {2,1},{3,4},{5,6},{7,8},{9,10}

In all these sets list members are used only once and all members are used. Do you think I can use partitions to generate all these sets?

By the way there are 945 = 9!! = 9 x 7 x 5 x 3 x 1 sets with this property. I know the number but I can not generate them in Mathematica.

Any suggestion?

POSTED BY: Selcuk Kumbasar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract