|
|
Question : Set theory algorithm question
|
|
|
|
I'm trying to find a relatively efficient algorithm to solve the following problem: I have a finite set S = {s_1, s_2, s_3,...}, where each s_i is itself a non-empty finite set. I need to find a subset of S -- call it T -- where the number of elements in the union over all elements in T is equal to the number of elements in T itself.
For example, if I have the set S = {{1,2,8}, {3,5}, {1,3,8}, {2,5,7}, {1,2,5,8}, {3,8}, {2,7}, {7}}, then the algorithm should return the set T = {{3,5}, {2,5,7}, {2,7}, {7}} because T has 4 elements and union({3,5}, {2,5,7}, {2,7}, {7}) also has 4 elements.
The only way I can think of solving this problem is examining each element of the power set of S to see if it matches the criteria, but that algorithm runs in exponential time. Can anybody think of a more efficient way to solve this problem, or point me in the right direction? Thanks.
|
|
|
|
Answer : Set theory algorithm question
|
|
|
|
You are close to your answer. In page 2, update the close_window function with this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
|
function close_window() {
if(document.getElementById('Page2_Txt1').value != "") {
opener.document.getElementById( gup("target") ).value = document.getElementById('Page2_Txt1').value;
}
else if(document.getElementById('Page2_Txt2').value != "") {
opener.document.getElementById( gup("target") ).value = document.getElementById('Page2_Txt2').value;
}
else {
alert("Fill in one textbox!");
return;
}
window.close();
}
|
|
|
|
|
|