I have a set of elements Nthat are sets of integers, let's say that it is ordered and calls it I[1..N]. Given the set candidate, I need to find a subset Ithat have non-empty intersections with candidate.
So, for example, if:
I = [{1,2}, {2,3}, {4,5}]
I want to determine valid_items(items, candidate)that:
valid_items(I, {1}) == {1}
valid_items(I, {2}) == {1, 2}
valid_items(I, {3,4}) == {2, 3}
I am trying to optimize for one given set Iand set of variables candidate. I am currently doing this by caching items_containing[n] = {the sets which contain n}. In the above example, this would be:
items_containing = [{}, {1}, {1,2}, {2}, {3}, {3}]
That is, 0 is not contained in any element, 1 is contained in paragraph 1, 2 is contained in it 1 and 2, 2 is contained in paragraph 2, 3 is contained in paragraph 2, and 4 and 5 are contained in paragraph 3.
, valid_items(I, candidate) = union(items_containing[n] for n in candidate).
( ) ? 2^N , N N*log(N) .