I would like to know if there's a known algorithm or best practice way to do the following:I have a collection with a subcollection, for example:R1 R2 R3-- -- --M  M  MN  NL  L   AWhat i need is an algorithm to get the following result:R1, R2: M N LR2: AR3: MThis is -not- what i want, it has more repeating values for R than the above:R1, R2, R3: MR1, R2: N LR2: AI need to group in way that i get the most optimized groups of R.The least amount of groups of R the better so i get the largest sub collections.Another example (with the most obvious result):R1 R2 R3-- -- --M  M  AV  V  BL  L  CShould result in:R1, R2: M V LR3: A B CI need to do this in LINQ/C#.Any solutions? Tips? Links?
Algorithm to optimize grouping
c#;algorithms;linq