Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the total number of unique pairs of a set in the database? [closed]

Tags:

database

math

4 items:

A
B
C
D

6 unique pairs possible:

AB
AC
AD
BC
BD
CD

What if I have 100 starting items? How many unique pairs are there? Is there a formula I can throw this into?

like image 675
Kirk Ouimet Avatar asked Sep 17 '13 20:09

Kirk Ouimet


People also ask

How many distinct pairings of 5 items are there?

So we say that there are 5 factorial = 5! = 5x4x3x2x1 = 120 ways to arrange five objects.

How do you find unique pairs in Python?

We take an empty list to store the output. Then, we use a loop with iterator 'e' to traverse through given list. In every iteration, we check is e+k i.e the required pair integer for e is available or not. If yes, we append the tuple to 'res'.

How many pairs can you make with 8 items?

Note: 8 items have a total of 40,320 different combinations.

How many pairs can be made from 4 numbers?

The answer to this question (which you got right) is 24. Here's how to observe this: 1. Pick one of the four numbers (there are four choices in this step).


2 Answers

TLDR; The formula is n(n-1)/2 where n is the number of items in the set.

Explanation:

To find the number of unique pairs in a set, where the pairs are subject to the commutative property (AB = BA), you can calculate the summation of 1 + 2 + ... + (n-1) where n is the number of items in the set.

The reasoning is as follows, say you have 4 items:

A
B
C
D

The number of items that can be paired with A is 3, or n-1:

AB
AC
AD

It follows that the number of items that can be paired with B is n-2 (because B has already been paired with A):

BC
BD

and so on...

(n-1) + (n-2) + ... + (n-(n-1))

which is the same as

1 + 2 + ... + (n-1)

or

n(n-1)/2
like image 55
audiomason Avatar answered Oct 06 '22 08:10

audiomason


What you're looking for is n choose k. Basically:

enter image description here

For every pair of 100 items, you'd have 4,950 combinations - provided order doesn't matter (AB and BA are considered a single combination) and you don't want to repeat (AA is not a valid pair).

like image 84
Mike Christensen Avatar answered Oct 06 '22 07:10

Mike Christensen