Number of Combinations of Items from Sets with Dependencies
$begingroup$
Given a collection of $n$ sets of elements, and choosing exactly 1 element from each set, where $S$ is the size (number of elements) of a set, then the total number $w$ of possible combinations of elements across all sets is simply the product of the sizes of each set:
$$w = prod_{i=1}^n S_i$$
Simple enough. Now, suppose the sets themselves (not the elements within) are arranged in a specific order, so that we can number them Set 1, Set 2, Set 3, etc. Again choosing exactly 1 element from each set, always choosing in order from Set 1 first, then from Set 2, then Set 3, etc., we still have $w$ possible combinations of elements across all sets. The fact that we always choose from sets in the same order is irrelevant.
Now, suppose we introduce dependencies, called links, between the sets as follows. A whole set can be linked to a specific element in an earlier set, such that the later set only exists (is only chosen from) when the earlier set's linked element was chosen from the earlier set. Example: if there are 3 sets, and if Set 2 is linked to Set 1's second element, then we start by choosing an element from Set 1. If we chose the second element, we choose an element from Set 2, then Set 3, as before. But if we did not choose the second element from Set 1, then we skip Set 2 and move on to choosing an element from Set 3. Combinations of elements that involve skipping over sets that are rendered void by their links are still considered valid combinations; they simply do not contain elements from the skipped sets. It is permissible for a set to link to multiple items and/or across multiple earlier sets; at least 1 of a set's links must be satisfied for the set to exist. It is also permissible for multiple later sets to link to the same earlier value.
Example:
Set 1 = {A,B,C,D}; Set 2 = {A,B,C}; Set 3 = {A,B}
^ ^ ^ | |
| | | | |
---|-|----- |
-+----------------------
S2 linked to S1:A. S3 linked to S1:C and S1:D. The possible combinations of elements across these sets is (with dashes indicating skipped sets):
A,A,-
A,B,-
A,C,-
B,-,-
C,-,A
C,-,B
D,-,A
D,-,B
So there are $8$ possible combinations in this example. I know this from listing them by hand above and counting. My question is: for the general case, how can I calculate the total number of possibilities? I am looking to write an algorithm that takes the sizes of the sets and the the links between them, and calculates the number of possibilities. I want to do it without brute-force enumeration of each combination, and my preference would be to avoid recursion and computational inefficiency. My common use case is large sets (thousands or millions of elements) but only a handful of links. It seems to me that there must be a way to calculate the total number without enumerating them. Any help or tips would be appreciated.
Background info for those interested:
I am designing an algorithm where I am trying to squeeze as much information as I can into as few bits as possible, on a very small scale of a few dozen bits. It works by grouping all data fields (the 'sets' in this question) into a single numeric representation which is the index in the mathematical list of all possible combinations of each field's value (the 'elements' in this question) thereby eliminating any wasted entropy in the binary encoding of each field. However, sometimes data fields are only relevant when other data fields are set to a certain value (the 'links' in this question). I have improved my algorithm to handle these cases and further eliminate wasted entropy, but it hinges on being able to calculate the total number of combinations. This is where I got stuck.
combinatorics permutations algorithms combinations
$endgroup$
add a comment |
$begingroup$
Given a collection of $n$ sets of elements, and choosing exactly 1 element from each set, where $S$ is the size (number of elements) of a set, then the total number $w$ of possible combinations of elements across all sets is simply the product of the sizes of each set:
$$w = prod_{i=1}^n S_i$$
Simple enough. Now, suppose the sets themselves (not the elements within) are arranged in a specific order, so that we can number them Set 1, Set 2, Set 3, etc. Again choosing exactly 1 element from each set, always choosing in order from Set 1 first, then from Set 2, then Set 3, etc., we still have $w$ possible combinations of elements across all sets. The fact that we always choose from sets in the same order is irrelevant.
Now, suppose we introduce dependencies, called links, between the sets as follows. A whole set can be linked to a specific element in an earlier set, such that the later set only exists (is only chosen from) when the earlier set's linked element was chosen from the earlier set. Example: if there are 3 sets, and if Set 2 is linked to Set 1's second element, then we start by choosing an element from Set 1. If we chose the second element, we choose an element from Set 2, then Set 3, as before. But if we did not choose the second element from Set 1, then we skip Set 2 and move on to choosing an element from Set 3. Combinations of elements that involve skipping over sets that are rendered void by their links are still considered valid combinations; they simply do not contain elements from the skipped sets. It is permissible for a set to link to multiple items and/or across multiple earlier sets; at least 1 of a set's links must be satisfied for the set to exist. It is also permissible for multiple later sets to link to the same earlier value.
Example:
Set 1 = {A,B,C,D}; Set 2 = {A,B,C}; Set 3 = {A,B}
^ ^ ^ | |
| | | | |
---|-|----- |
-+----------------------
S2 linked to S1:A. S3 linked to S1:C and S1:D. The possible combinations of elements across these sets is (with dashes indicating skipped sets):
A,A,-
A,B,-
A,C,-
B,-,-
C,-,A
C,-,B
D,-,A
D,-,B
So there are $8$ possible combinations in this example. I know this from listing them by hand above and counting. My question is: for the general case, how can I calculate the total number of possibilities? I am looking to write an algorithm that takes the sizes of the sets and the the links between them, and calculates the number of possibilities. I want to do it without brute-force enumeration of each combination, and my preference would be to avoid recursion and computational inefficiency. My common use case is large sets (thousands or millions of elements) but only a handful of links. It seems to me that there must be a way to calculate the total number without enumerating them. Any help or tips would be appreciated.
Background info for those interested:
I am designing an algorithm where I am trying to squeeze as much information as I can into as few bits as possible, on a very small scale of a few dozen bits. It works by grouping all data fields (the 'sets' in this question) into a single numeric representation which is the index in the mathematical list of all possible combinations of each field's value (the 'elements' in this question) thereby eliminating any wasted entropy in the binary encoding of each field. However, sometimes data fields are only relevant when other data fields are set to a certain value (the 'links' in this question). I have improved my algorithm to handle these cases and further eliminate wasted entropy, but it hinges on being able to calculate the total number of combinations. This is where I got stuck.
combinatorics permutations algorithms combinations
$endgroup$
add a comment |
$begingroup$
Given a collection of $n$ sets of elements, and choosing exactly 1 element from each set, where $S$ is the size (number of elements) of a set, then the total number $w$ of possible combinations of elements across all sets is simply the product of the sizes of each set:
$$w = prod_{i=1}^n S_i$$
Simple enough. Now, suppose the sets themselves (not the elements within) are arranged in a specific order, so that we can number them Set 1, Set 2, Set 3, etc. Again choosing exactly 1 element from each set, always choosing in order from Set 1 first, then from Set 2, then Set 3, etc., we still have $w$ possible combinations of elements across all sets. The fact that we always choose from sets in the same order is irrelevant.
Now, suppose we introduce dependencies, called links, between the sets as follows. A whole set can be linked to a specific element in an earlier set, such that the later set only exists (is only chosen from) when the earlier set's linked element was chosen from the earlier set. Example: if there are 3 sets, and if Set 2 is linked to Set 1's second element, then we start by choosing an element from Set 1. If we chose the second element, we choose an element from Set 2, then Set 3, as before. But if we did not choose the second element from Set 1, then we skip Set 2 and move on to choosing an element from Set 3. Combinations of elements that involve skipping over sets that are rendered void by their links are still considered valid combinations; they simply do not contain elements from the skipped sets. It is permissible for a set to link to multiple items and/or across multiple earlier sets; at least 1 of a set's links must be satisfied for the set to exist. It is also permissible for multiple later sets to link to the same earlier value.
Example:
Set 1 = {A,B,C,D}; Set 2 = {A,B,C}; Set 3 = {A,B}
^ ^ ^ | |
| | | | |
---|-|----- |
-+----------------------
S2 linked to S1:A. S3 linked to S1:C and S1:D. The possible combinations of elements across these sets is (with dashes indicating skipped sets):
A,A,-
A,B,-
A,C,-
B,-,-
C,-,A
C,-,B
D,-,A
D,-,B
So there are $8$ possible combinations in this example. I know this from listing them by hand above and counting. My question is: for the general case, how can I calculate the total number of possibilities? I am looking to write an algorithm that takes the sizes of the sets and the the links between them, and calculates the number of possibilities. I want to do it without brute-force enumeration of each combination, and my preference would be to avoid recursion and computational inefficiency. My common use case is large sets (thousands or millions of elements) but only a handful of links. It seems to me that there must be a way to calculate the total number without enumerating them. Any help or tips would be appreciated.
Background info for those interested:
I am designing an algorithm where I am trying to squeeze as much information as I can into as few bits as possible, on a very small scale of a few dozen bits. It works by grouping all data fields (the 'sets' in this question) into a single numeric representation which is the index in the mathematical list of all possible combinations of each field's value (the 'elements' in this question) thereby eliminating any wasted entropy in the binary encoding of each field. However, sometimes data fields are only relevant when other data fields are set to a certain value (the 'links' in this question). I have improved my algorithm to handle these cases and further eliminate wasted entropy, but it hinges on being able to calculate the total number of combinations. This is where I got stuck.
combinatorics permutations algorithms combinations
$endgroup$
Given a collection of $n$ sets of elements, and choosing exactly 1 element from each set, where $S$ is the size (number of elements) of a set, then the total number $w$ of possible combinations of elements across all sets is simply the product of the sizes of each set:
$$w = prod_{i=1}^n S_i$$
Simple enough. Now, suppose the sets themselves (not the elements within) are arranged in a specific order, so that we can number them Set 1, Set 2, Set 3, etc. Again choosing exactly 1 element from each set, always choosing in order from Set 1 first, then from Set 2, then Set 3, etc., we still have $w$ possible combinations of elements across all sets. The fact that we always choose from sets in the same order is irrelevant.
Now, suppose we introduce dependencies, called links, between the sets as follows. A whole set can be linked to a specific element in an earlier set, such that the later set only exists (is only chosen from) when the earlier set's linked element was chosen from the earlier set. Example: if there are 3 sets, and if Set 2 is linked to Set 1's second element, then we start by choosing an element from Set 1. If we chose the second element, we choose an element from Set 2, then Set 3, as before. But if we did not choose the second element from Set 1, then we skip Set 2 and move on to choosing an element from Set 3. Combinations of elements that involve skipping over sets that are rendered void by their links are still considered valid combinations; they simply do not contain elements from the skipped sets. It is permissible for a set to link to multiple items and/or across multiple earlier sets; at least 1 of a set's links must be satisfied for the set to exist. It is also permissible for multiple later sets to link to the same earlier value.
Example:
Set 1 = {A,B,C,D}; Set 2 = {A,B,C}; Set 3 = {A,B}
^ ^ ^ | |
| | | | |
---|-|----- |
-+----------------------
S2 linked to S1:A. S3 linked to S1:C and S1:D. The possible combinations of elements across these sets is (with dashes indicating skipped sets):
A,A,-
A,B,-
A,C,-
B,-,-
C,-,A
C,-,B
D,-,A
D,-,B
So there are $8$ possible combinations in this example. I know this from listing them by hand above and counting. My question is: for the general case, how can I calculate the total number of possibilities? I am looking to write an algorithm that takes the sizes of the sets and the the links between them, and calculates the number of possibilities. I want to do it without brute-force enumeration of each combination, and my preference would be to avoid recursion and computational inefficiency. My common use case is large sets (thousands or millions of elements) but only a handful of links. It seems to me that there must be a way to calculate the total number without enumerating them. Any help or tips would be appreciated.
Background info for those interested:
I am designing an algorithm where I am trying to squeeze as much information as I can into as few bits as possible, on a very small scale of a few dozen bits. It works by grouping all data fields (the 'sets' in this question) into a single numeric representation which is the index in the mathematical list of all possible combinations of each field's value (the 'elements' in this question) thereby eliminating any wasted entropy in the binary encoding of each field. However, sometimes data fields are only relevant when other data fields are set to a certain value (the 'links' in this question). I have improved my algorithm to handle these cases and further eliminate wasted entropy, but it hinges on being able to calculate the total number of combinations. This is where I got stuck.
combinatorics permutations algorithms combinations
combinatorics permutations algorithms combinations
edited Jan 11 at 16:42
Asaf Karagila♦
306k33437768
306k33437768
asked Jan 11 at 15:52
Ben HersheyBen Hershey
133
133
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
My common use case is large sets (thousands or millions of elements) but only a handful of links.
For me a clustered recursion seems to be a good algorithm. The idea is simple but it is a bit hard for me to explain it clearly. I’ll hope you’ll understand it from the below. An input for a clustered recursion is the following. Assume that we are given sets $S_1,dots, S_n$. Then for each $i$ and each subset $I$ of ${i+1,dots, n}$ we count a number $(i,I)$ of elements of $S_i$ which linked to exactly members of $I$. Also assume that we are given a subset $Z$ of ${1,dots, n}$ of indices $i$ of sets $S_i$ which do not need links to be listed. Clearly, suffices to consider reduced inputs $(i,I)$ with $Icap Zvarnothing$, with $(i,I):=sum {(i,I’):Isubset I’subset Icup Z}$. For instance, in your example we have $n=3$, $Z={1}$, $(1,{2})=1$, $(1,{3})=2$, $(1,varnothing)=1$, $(2,varnothing)=3$, $(3,varnothing)=2$, and all other $(i,I)$ are zero. Then using the same arguments as in the question, we can count the total number $N$ of possibilities as follows. For each subset $I$ of ${2,dots, n}$ we recursively calculate the total number $N_I$ of possibilities in which the first element is linked with exactly members of $I$ and then count $N=sum {N_I: Isubset {2,dots, n}}$. For instance, in your example there are
$(1,{2})=1$ choice to choose an element linked exactly with the set $S_2$. In this case we add $2$ to and remove $1$ from the set $Z$ of indices of sets which do not need links to be listed. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_2$ are not linked with other sets, in this case we have only $(2,varnothing)=3$ choices. So in total we have $N_{{2}}=(1,{2})(2,varnothing)=3$.
$(1,{3})=2$ choices to choose an element linked exactly with the set $S_3$. In each of these cases we add $3$ to and remove $1$ from the set $Z$. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_3$ are not linked with other sets, in this case we have only $(3,varnothing)=2$ choices. So in total we have $N_{{3}}=(1,{3})(3,varnothing)=4$.
$(1, varnothing)=1$ choice to choose an element not linked with any set $S_i$. In this case we remove $1$ from the set $Z$, but add to it nothing. So in total we have $N_varnothing =(1,varnothing)=1$.
Thus we have $N= N_varnothing + N_{{2}}+ N_{{3}}=1+3+4=8$.
$endgroup$
1
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3069994%2fnumber-of-combinations-of-items-from-sets-with-dependencies%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
My common use case is large sets (thousands or millions of elements) but only a handful of links.
For me a clustered recursion seems to be a good algorithm. The idea is simple but it is a bit hard for me to explain it clearly. I’ll hope you’ll understand it from the below. An input for a clustered recursion is the following. Assume that we are given sets $S_1,dots, S_n$. Then for each $i$ and each subset $I$ of ${i+1,dots, n}$ we count a number $(i,I)$ of elements of $S_i$ which linked to exactly members of $I$. Also assume that we are given a subset $Z$ of ${1,dots, n}$ of indices $i$ of sets $S_i$ which do not need links to be listed. Clearly, suffices to consider reduced inputs $(i,I)$ with $Icap Zvarnothing$, with $(i,I):=sum {(i,I’):Isubset I’subset Icup Z}$. For instance, in your example we have $n=3$, $Z={1}$, $(1,{2})=1$, $(1,{3})=2$, $(1,varnothing)=1$, $(2,varnothing)=3$, $(3,varnothing)=2$, and all other $(i,I)$ are zero. Then using the same arguments as in the question, we can count the total number $N$ of possibilities as follows. For each subset $I$ of ${2,dots, n}$ we recursively calculate the total number $N_I$ of possibilities in which the first element is linked with exactly members of $I$ and then count $N=sum {N_I: Isubset {2,dots, n}}$. For instance, in your example there are
$(1,{2})=1$ choice to choose an element linked exactly with the set $S_2$. In this case we add $2$ to and remove $1$ from the set $Z$ of indices of sets which do not need links to be listed. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_2$ are not linked with other sets, in this case we have only $(2,varnothing)=3$ choices. So in total we have $N_{{2}}=(1,{2})(2,varnothing)=3$.
$(1,{3})=2$ choices to choose an element linked exactly with the set $S_3$. In each of these cases we add $3$ to and remove $1$ from the set $Z$. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_3$ are not linked with other sets, in this case we have only $(3,varnothing)=2$ choices. So in total we have $N_{{3}}=(1,{3})(3,varnothing)=4$.
$(1, varnothing)=1$ choice to choose an element not linked with any set $S_i$. In this case we remove $1$ from the set $Z$, but add to it nothing. So in total we have $N_varnothing =(1,varnothing)=1$.
Thus we have $N= N_varnothing + N_{{2}}+ N_{{3}}=1+3+4=8$.
$endgroup$
1
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
add a comment |
$begingroup$
My common use case is large sets (thousands or millions of elements) but only a handful of links.
For me a clustered recursion seems to be a good algorithm. The idea is simple but it is a bit hard for me to explain it clearly. I’ll hope you’ll understand it from the below. An input for a clustered recursion is the following. Assume that we are given sets $S_1,dots, S_n$. Then for each $i$ and each subset $I$ of ${i+1,dots, n}$ we count a number $(i,I)$ of elements of $S_i$ which linked to exactly members of $I$. Also assume that we are given a subset $Z$ of ${1,dots, n}$ of indices $i$ of sets $S_i$ which do not need links to be listed. Clearly, suffices to consider reduced inputs $(i,I)$ with $Icap Zvarnothing$, with $(i,I):=sum {(i,I’):Isubset I’subset Icup Z}$. For instance, in your example we have $n=3$, $Z={1}$, $(1,{2})=1$, $(1,{3})=2$, $(1,varnothing)=1$, $(2,varnothing)=3$, $(3,varnothing)=2$, and all other $(i,I)$ are zero. Then using the same arguments as in the question, we can count the total number $N$ of possibilities as follows. For each subset $I$ of ${2,dots, n}$ we recursively calculate the total number $N_I$ of possibilities in which the first element is linked with exactly members of $I$ and then count $N=sum {N_I: Isubset {2,dots, n}}$. For instance, in your example there are
$(1,{2})=1$ choice to choose an element linked exactly with the set $S_2$. In this case we add $2$ to and remove $1$ from the set $Z$ of indices of sets which do not need links to be listed. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_2$ are not linked with other sets, in this case we have only $(2,varnothing)=3$ choices. So in total we have $N_{{2}}=(1,{2})(2,varnothing)=3$.
$(1,{3})=2$ choices to choose an element linked exactly with the set $S_3$. In each of these cases we add $3$ to and remove $1$ from the set $Z$. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_3$ are not linked with other sets, in this case we have only $(3,varnothing)=2$ choices. So in total we have $N_{{3}}=(1,{3})(3,varnothing)=4$.
$(1, varnothing)=1$ choice to choose an element not linked with any set $S_i$. In this case we remove $1$ from the set $Z$, but add to it nothing. So in total we have $N_varnothing =(1,varnothing)=1$.
Thus we have $N= N_varnothing + N_{{2}}+ N_{{3}}=1+3+4=8$.
$endgroup$
1
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
add a comment |
$begingroup$
My common use case is large sets (thousands or millions of elements) but only a handful of links.
For me a clustered recursion seems to be a good algorithm. The idea is simple but it is a bit hard for me to explain it clearly. I’ll hope you’ll understand it from the below. An input for a clustered recursion is the following. Assume that we are given sets $S_1,dots, S_n$. Then for each $i$ and each subset $I$ of ${i+1,dots, n}$ we count a number $(i,I)$ of elements of $S_i$ which linked to exactly members of $I$. Also assume that we are given a subset $Z$ of ${1,dots, n}$ of indices $i$ of sets $S_i$ which do not need links to be listed. Clearly, suffices to consider reduced inputs $(i,I)$ with $Icap Zvarnothing$, with $(i,I):=sum {(i,I’):Isubset I’subset Icup Z}$. For instance, in your example we have $n=3$, $Z={1}$, $(1,{2})=1$, $(1,{3})=2$, $(1,varnothing)=1$, $(2,varnothing)=3$, $(3,varnothing)=2$, and all other $(i,I)$ are zero. Then using the same arguments as in the question, we can count the total number $N$ of possibilities as follows. For each subset $I$ of ${2,dots, n}$ we recursively calculate the total number $N_I$ of possibilities in which the first element is linked with exactly members of $I$ and then count $N=sum {N_I: Isubset {2,dots, n}}$. For instance, in your example there are
$(1,{2})=1$ choice to choose an element linked exactly with the set $S_2$. In this case we add $2$ to and remove $1$ from the set $Z$ of indices of sets which do not need links to be listed. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_2$ are not linked with other sets, in this case we have only $(2,varnothing)=3$ choices. So in total we have $N_{{2}}=(1,{2})(2,varnothing)=3$.
$(1,{3})=2$ choices to choose an element linked exactly with the set $S_3$. In each of these cases we add $3$ to and remove $1$ from the set $Z$. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_3$ are not linked with other sets, in this case we have only $(3,varnothing)=2$ choices. So in total we have $N_{{3}}=(1,{3})(3,varnothing)=4$.
$(1, varnothing)=1$ choice to choose an element not linked with any set $S_i$. In this case we remove $1$ from the set $Z$, but add to it nothing. So in total we have $N_varnothing =(1,varnothing)=1$.
Thus we have $N= N_varnothing + N_{{2}}+ N_{{3}}=1+3+4=8$.
$endgroup$
My common use case is large sets (thousands or millions of elements) but only a handful of links.
For me a clustered recursion seems to be a good algorithm. The idea is simple but it is a bit hard for me to explain it clearly. I’ll hope you’ll understand it from the below. An input for a clustered recursion is the following. Assume that we are given sets $S_1,dots, S_n$. Then for each $i$ and each subset $I$ of ${i+1,dots, n}$ we count a number $(i,I)$ of elements of $S_i$ which linked to exactly members of $I$. Also assume that we are given a subset $Z$ of ${1,dots, n}$ of indices $i$ of sets $S_i$ which do not need links to be listed. Clearly, suffices to consider reduced inputs $(i,I)$ with $Icap Zvarnothing$, with $(i,I):=sum {(i,I’):Isubset I’subset Icup Z}$. For instance, in your example we have $n=3$, $Z={1}$, $(1,{2})=1$, $(1,{3})=2$, $(1,varnothing)=1$, $(2,varnothing)=3$, $(3,varnothing)=2$, and all other $(i,I)$ are zero. Then using the same arguments as in the question, we can count the total number $N$ of possibilities as follows. For each subset $I$ of ${2,dots, n}$ we recursively calculate the total number $N_I$ of possibilities in which the first element is linked with exactly members of $I$ and then count $N=sum {N_I: Isubset {2,dots, n}}$. For instance, in your example there are
$(1,{2})=1$ choice to choose an element linked exactly with the set $S_2$. In this case we add $2$ to and remove $1$ from the set $Z$ of indices of sets which do not need links to be listed. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_2$ are not linked with other sets, in this case we have only $(2,varnothing)=3$ choices. So in total we have $N_{{2}}=(1,{2})(2,varnothing)=3$.
$(1,{3})=2$ choices to choose an element linked exactly with the set $S_3$. In each of these cases we add $3$ to and remove $1$ from the set $Z$. This gives us the same problem, but with the smaller number of sets. Since the elements of the set $S_3$ are not linked with other sets, in this case we have only $(3,varnothing)=2$ choices. So in total we have $N_{{3}}=(1,{3})(3,varnothing)=4$.
$(1, varnothing)=1$ choice to choose an element not linked with any set $S_i$. In this case we remove $1$ from the set $Z$, but add to it nothing. So in total we have $N_varnothing =(1,varnothing)=1$.
Thus we have $N= N_varnothing + N_{{2}}+ N_{{3}}=1+3+4=8$.
answered Jan 25 at 20:28
Alex RavskyAlex Ravsky
42.6k32383
42.6k32383
1
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
add a comment |
1
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
1
1
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
$begingroup$
Thank you, this is a very solid approach! I actually ended up solving this problem after I asked it much in the way you describe, with some adjustments to increase computational efficiency. It is good to have some re-assurance that this is a good way to approach the problem. Thanks so much for taking the time to write that out!
$endgroup$
– Ben Hershey
Jan 28 at 14:10
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3069994%2fnumber-of-combinations-of-items-from-sets-with-dependencies%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown