0

I would like to make pairs out of X number of database objects.

  • Order of pairs does not matter.
  • Pairs will be made over multiple rounds.
  • I do not want pairs to be repeated in a subsequent round.

If I have:

A
B
C
D

The first round might be:

AB
CD

Second round might be:

AD
CB

Third round might be:

AC
DB

And there would be no other possibilities.

So for 4 elements, I could do 3 rounds before I have to repeat a pair.

What is the formula to help me with this for any number of elements?

Related How do I get the total number of unique pairs of a set in the database?

MicFin
  • 2,431
  • 4
  • 32
  • 59

1 Answers1

0

You can use round-robin tournament algorithm to generate all possible pairs. Your example shows r-r algo in action: make two rows of elements, fix the first one (A) and rotate other elements in cyclic manner.

Note that N elements form N*(N-1)/2 pairs, and (N-1) rounds are needed to generate all of them

MBo
  • 77,366
  • 5
  • 53
  • 86