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?
So we say that there are 5 factorial = 5! = 5x4x3x2x1 = 120 ways to arrange five objects.
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'.
Note: 8 items have a total of 40,320 different combinations.
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).
TLDR; The formula is n(n-1)/2
where n
is the number of items in the set.
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
What you're looking for is n choose k. Basically:
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With