I am a new member of this forum, I hope you have not forgotten about this old question :)
Decision
Store the master set in an indexed data structure - such as an array (or an arraylist, if your library supports it). Suppose you can associate an identifier with each set (if not, how do you know which set you need to get?). So, now we need a way to find out which elements of your array are involved in this set and which are not.
Use the matrix (n x m)with nas the number of elements in your array, and m- the initial number of sets. I refer to the row index, and j refers to the column index.
A[i][j] = 0 if ith element is not in jth set
A[i][j] = 1 if ith element is in jth set
, ArrayList<ArrayList>. Java/#/++ , , Perl. # DataTable.
O(n) . 1 . , .
O(log n). ( at, 0 ). 1, . , O(log n) + O(m).
N
, O(1) , n , 1. .
, j1 j2 j3.
for (int i = 0; i < n - 1; i++) {
A[i][j3] = A[i][j1] | A[i][j2];
}
.
- O(log n). .
, . /, , . , . , .