How to check subsets efficiently
Suppose we have a 5-bit 0-1 string "01001" and a set of 5-bit 0-1 strings {"01010","10111","01011"}. Define a relation on string a and b: $a subseteq b$ if and only if all bits 1 in a exist in b in the same position. For example. 01001$subseteq$01011 because all bits 1 in 01001 also exist in 01011 in the same position. Here is the question: Could we design a pattern, like a encoding function F($a$,$S$) to use bit operation to encode all strings in the string set $S$, such that whenever a new string $a$ comes, we can check whether $a$ is a subset of one of the string in the string set $S$ in $textbf{one operation}$, $textbf{in which we don't need to iterative every element in S}$. We just need to know whether it is a subset and we don't care which set is $a$'s superset. In the example, F(01001,{01010,10111,01011}) = 1 because 01001 is a subset of one element in {01010,10111,01011}.
algorithms
add a comment |
Suppose we have a 5-bit 0-1 string "01001" and a set of 5-bit 0-1 strings {"01010","10111","01011"}. Define a relation on string a and b: $a subseteq b$ if and only if all bits 1 in a exist in b in the same position. For example. 01001$subseteq$01011 because all bits 1 in 01001 also exist in 01011 in the same position. Here is the question: Could we design a pattern, like a encoding function F($a$,$S$) to use bit operation to encode all strings in the string set $S$, such that whenever a new string $a$ comes, we can check whether $a$ is a subset of one of the string in the string set $S$ in $textbf{one operation}$, $textbf{in which we don't need to iterative every element in S}$. We just need to know whether it is a subset and we don't care which set is $a$'s superset. In the example, F(01001,{01010,10111,01011}) = 1 because 01001 is a subset of one element in {01010,10111,01011}.
algorithms
If your string sequences are $n$-bit long you can construct a binary tree that checks for every bit whether there's still a string in your sequence that matches it. That way the checking part is only $n$ operations at most, but you'll need a binary tree with up to $2^n$ nodes.
– Rchn
Nov 29 '18 at 11:29
Yes I think binary tree is a good idea. But the space complexity is a little big. :)
– Sooner
Nov 29 '18 at 15:01
In reality the space complexity wouldn't be that big because you would be able to do quite a lot of pruning. In your example, after prunning your tree would only have 5 leaves instead of 32.
– Rchn
Nov 29 '18 at 15:46
It would look like this: $$ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ 1end{array}right. end{array} right. $$
– Rchn
Nov 29 '18 at 15:52
add a comment |
Suppose we have a 5-bit 0-1 string "01001" and a set of 5-bit 0-1 strings {"01010","10111","01011"}. Define a relation on string a and b: $a subseteq b$ if and only if all bits 1 in a exist in b in the same position. For example. 01001$subseteq$01011 because all bits 1 in 01001 also exist in 01011 in the same position. Here is the question: Could we design a pattern, like a encoding function F($a$,$S$) to use bit operation to encode all strings in the string set $S$, such that whenever a new string $a$ comes, we can check whether $a$ is a subset of one of the string in the string set $S$ in $textbf{one operation}$, $textbf{in which we don't need to iterative every element in S}$. We just need to know whether it is a subset and we don't care which set is $a$'s superset. In the example, F(01001,{01010,10111,01011}) = 1 because 01001 is a subset of one element in {01010,10111,01011}.
algorithms
Suppose we have a 5-bit 0-1 string "01001" and a set of 5-bit 0-1 strings {"01010","10111","01011"}. Define a relation on string a and b: $a subseteq b$ if and only if all bits 1 in a exist in b in the same position. For example. 01001$subseteq$01011 because all bits 1 in 01001 also exist in 01011 in the same position. Here is the question: Could we design a pattern, like a encoding function F($a$,$S$) to use bit operation to encode all strings in the string set $S$, such that whenever a new string $a$ comes, we can check whether $a$ is a subset of one of the string in the string set $S$ in $textbf{one operation}$, $textbf{in which we don't need to iterative every element in S}$. We just need to know whether it is a subset and we don't care which set is $a$'s superset. In the example, F(01001,{01010,10111,01011}) = 1 because 01001 is a subset of one element in {01010,10111,01011}.
algorithms
algorithms
edited Nov 29 '18 at 11:08
Sooner
asked Nov 29 '18 at 10:56
SoonerSooner
197
197
If your string sequences are $n$-bit long you can construct a binary tree that checks for every bit whether there's still a string in your sequence that matches it. That way the checking part is only $n$ operations at most, but you'll need a binary tree with up to $2^n$ nodes.
– Rchn
Nov 29 '18 at 11:29
Yes I think binary tree is a good idea. But the space complexity is a little big. :)
– Sooner
Nov 29 '18 at 15:01
In reality the space complexity wouldn't be that big because you would be able to do quite a lot of pruning. In your example, after prunning your tree would only have 5 leaves instead of 32.
– Rchn
Nov 29 '18 at 15:46
It would look like this: $$ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ 1end{array}right. end{array} right. $$
– Rchn
Nov 29 '18 at 15:52
add a comment |
If your string sequences are $n$-bit long you can construct a binary tree that checks for every bit whether there's still a string in your sequence that matches it. That way the checking part is only $n$ operations at most, but you'll need a binary tree with up to $2^n$ nodes.
– Rchn
Nov 29 '18 at 11:29
Yes I think binary tree is a good idea. But the space complexity is a little big. :)
– Sooner
Nov 29 '18 at 15:01
In reality the space complexity wouldn't be that big because you would be able to do quite a lot of pruning. In your example, after prunning your tree would only have 5 leaves instead of 32.
– Rchn
Nov 29 '18 at 15:46
It would look like this: $$ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ 1end{array}right. end{array} right. $$
– Rchn
Nov 29 '18 at 15:52
If your string sequences are $n$-bit long you can construct a binary tree that checks for every bit whether there's still a string in your sequence that matches it. That way the checking part is only $n$ operations at most, but you'll need a binary tree with up to $2^n$ nodes.
– Rchn
Nov 29 '18 at 11:29
If your string sequences are $n$-bit long you can construct a binary tree that checks for every bit whether there's still a string in your sequence that matches it. That way the checking part is only $n$ operations at most, but you'll need a binary tree with up to $2^n$ nodes.
– Rchn
Nov 29 '18 at 11:29
Yes I think binary tree is a good idea. But the space complexity is a little big. :)
– Sooner
Nov 29 '18 at 15:01
Yes I think binary tree is a good idea. But the space complexity is a little big. :)
– Sooner
Nov 29 '18 at 15:01
In reality the space complexity wouldn't be that big because you would be able to do quite a lot of pruning. In your example, after prunning your tree would only have 5 leaves instead of 32.
– Rchn
Nov 29 '18 at 15:46
In reality the space complexity wouldn't be that big because you would be able to do quite a lot of pruning. In your example, after prunning your tree would only have 5 leaves instead of 32.
– Rchn
Nov 29 '18 at 15:46
It would look like this: $$ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ 1end{array}right. end{array} right. $$
– Rchn
Nov 29 '18 at 15:52
It would look like this: $$ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ 1end{array}right. end{array} right. $$
– Rchn
Nov 29 '18 at 15:52
add a comment |
1 Answer
1
active
oldest
votes
To check if $a subseteq b$ you can check whether $a & b =a$. Therefore you can try something like
$$F(a,S)=OR_{b in S} (a&b=a)$$
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
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%2f3018471%2fhow-to-check-subsets-efficiently%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
To check if $a subseteq b$ you can check whether $a & b =a$. Therefore you can try something like
$$F(a,S)=OR_{b in S} (a&b=a)$$
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
add a comment |
To check if $a subseteq b$ you can check whether $a & b =a$. Therefore you can try something like
$$F(a,S)=OR_{b in S} (a&b=a)$$
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
add a comment |
To check if $a subseteq b$ you can check whether $a & b =a$. Therefore you can try something like
$$F(a,S)=OR_{b in S} (a&b=a)$$
To check if $a subseteq b$ you can check whether $a & b =a$. Therefore you can try something like
$$F(a,S)=OR_{b in S} (a&b=a)$$
answered Nov 29 '18 at 11:04
fonfonxfonfonx
3,492823
3,492823
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
add a comment |
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
Yes but I want to design a encoding method. In your way, we need to do n OR operations, in which n is the size of S. But I want to think out a way that we just need to do one operation, so that we can check.
– Sooner
Nov 29 '18 at 11:07
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
you can use early stopping when doing the OR operations. But the worst case complexity will always be linear in $n$
– fonfonx
Nov 29 '18 at 11:14
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2f3018471%2fhow-to-check-subsets-efficiently%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
If your string sequences are $n$-bit long you can construct a binary tree that checks for every bit whether there's still a string in your sequence that matches it. That way the checking part is only $n$ operations at most, but you'll need a binary tree with up to $2^n$ nodes.
– Rchn
Nov 29 '18 at 11:29
Yes I think binary tree is a good idea. But the space complexity is a little big. :)
– Sooner
Nov 29 '18 at 15:01
In reality the space complexity wouldn't be that big because you would be able to do quite a lot of pruning. In your example, after prunning your tree would only have 5 leaves instead of 32.
– Rchn
Nov 29 '18 at 15:46
It would look like this: $$ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ left{ begin{array}{ll} left{ begin{array}{ll} 0 \ 1end{array}right. \ 1end{array}right. end{array} right. $$
– Rchn
Nov 29 '18 at 15:52