Number of subsets that can be formed from a set of n
items taking r
items at a time is
total = P(n, r) = n! / (r! * (n - r)!)
Let s
be the selected combination. To find the number of subsets that are not disjoint with s
, we start by finding the number of subsets that are disjoint with s
- those sets that doesn't have any items in s
(lets call that number k
). Thus k
is the number of subsets that can be formed from a set of n - r
items, taking r
at a time.
k = P(n - r, r) = (n - r)! / (r! * (n - r - r)!)
= (n - r)! / (r! * (n - 2r)!)
Thus, the number of subsets disjoint with the selected set is:
total - k = P(n, r) - P(n - r, r)
Remember that this includes the selected subset s
. Subtract one from this to get the number of disjoint sets with s
.
Consider the following example:
//Let n = 6 and r = 2
total = P(n, r) = n! / (r! * (n - r)!) = 6! / (2! * 4!) = 15
k = P(n - r, r) = (n - r)! / (r! * (n - 2r)!) = 4! / (2! * 2!) = 6
answer = 15 - 6 = 9;
answer excluding the selected set s = 8
//Super set:
{123456}
//Possible sub sets:
{12,13,14,15,16,23,24,25,26,34,35,36,45,46,56} //15 items
//Let the selected set be {12}, then sets without 1 and 2:
{34,35,36,45,46,56} //6 items
//9 sets (including the selected set) are not disjoint with the selected set