Given a list of lists (say, 5 lists in order to have a real number to work with), I can easily find items that are common to all 5 lists (see Crossing multiple lists with IEnumerable.Intersect () ) using the following code:
var list1 = new List<int>() { 1, 2, 3 }; var list2 = new List<int>() { 2, 3, 4 }; var list3 = new List<int>() { 3, 4, 5 }; var listOfLists = new List<List<int>>() { list1, list2, list3 }; var intersection = listOfLists.Aggregate((previousList, nextList) => previousList.Intersect(nextList).ToList());
Now let's say that intersection ends with 0 elements. It is possible that there are some objects that are common to 4/5 lists. How can I find them in the most efficient way?
I know that I can just run through all the combinations from 4 lists and save all the results, but this method does not scale very well (this, ultimately, will need to be done in about 40 lists).
If no items are common to 4 lists, the repeated search will search for items common to 3/5 lists, etc. Visually, this can be represented by lists of grid points, and we are looking for points that have the greatest match.
Any ideas?
EDIT: Maybe it would be better to look at each point and track how many times it appears in each list, and then create a list of points with the highest result?
source share