Wednesday, 2 October 2013

Identify subsets of root data in a list of trees

Identify subsets of root data in a list of trees

I have following structure:
Node
{
List<String> rootData;
List<Node> Children;
}
and a collection as
List<Node> lstOfTrees
the first Structure holds some words on rootData, (List of node is not
really important here) and the collection lstOfTrees contains the the
trees.
Problem is: In lstOfTrees, there are multiple trees. Some of the trees
have subset of rootData of other trees (possibly, not necessarily). I want
to keep the tree having super-set of other rootData(s) in lstOfTrees
(subset should be ignored).
example: assuming, lstOfTrees contain the trees as
1: {rootData: A, B, C, D}
2: {rootData: E, F, G}
3: {rootData: G, H}
4: {rootData: J, A, C}
5: {rootData: D, Z}
the final answer I need, should be in a new list containing:
1: {rootData: A, B, C, D}
2: {rootData: E, F, G}
Can this be done using LINQ and TPL (or the more effecient way) ? I want
it to be efficient and correct.

No comments:

Post a Comment