Say we want to compute the largest common subset among a very large number of sets $Q_i$. One option would be to simply run the command:
Intersection[Q1, Q2, Q3, Q4, Q5, Q6, Q7, ...];
However, this seems to choke for very large numbers of input sets ($10^4$ or so with on-order $10^2$ elements each). Another option would be compute Q12 = Intersection[Q1,Q2]
, then Q123 = Intersection[Q12,Q3]
, then Q1234 = Intersection[Q123,Q4]
, and so forth.
Are these two procedures equivalent? Is there a better way?
Intersection[]
do support multiple list. In general I always try to use those function that support exactly what I need them to and no more, because it seems to me quicker that way. $\endgroup$ – Coolwater Apr 4 '14 at 18:34Fold[Intersection, First@#, Rest@#] &@list
but it is slower. $\endgroup$ – Kuba♦ Apr 4 '14 at 18:39Fold
in documentation. It does exactly n-1 intersections. $\endgroup$ – Kuba♦ Apr 4 '14 at 18:46