Algorithm Suggestion/Help (buiding strings from a graph)

J

Jeremy S.

Using .NET 3.5.I need to build a collection of strings given the following
input (presented in the app as a DataTable):

NodeID --- ParentNodeID --- CultureName --- NodeText
1 --- 2 --- fr-FR --- Crepes
1 --- 2 --- en-US --- Pancakes
2 --- null --- fr-FR --- Petit-Déjeuner
2 --- null --- en-US --- Breakfast
3 --- null --- en-US --- Veggies
4 --- 3 --- en-US --- Carrots
5 --- 3 --- en-US --- Peas
6 --- 5 --- en-US --- Snow Peas
7 --- 5 --- en-US --- Snap Peas
8 --- 6 --- en-US --- Large
9 --- 10 --- fr-FR --- Pois
10 --- null --- fr-FR --- Légumes

* Each string is to represent a complete valid "path" from a root node to
each possible child node, with nodes delimited with the '/' character.
* A root node is a row with a NULL ParentNodeID value
* This is a graph, not a tree, as each "child" node can have multiple
parents, and each parent can have multiple child nodes. For example, in the
sample data set, NodeID 1 has multiple parents (nodeID 2. differentiated on
CultureName).

The output string collection given the above sample DataTable input would
include these as valid strings (the output sequence is not important)

Petit-Déjeuner
Breakfast
Veggies
Légumes
Petit-Déjeuner/Crepes
Breakfast/Pancakes
Veggies/Carrots
Veggies/Peas
Veggies/Peas/Snow Peas
Veggies/Peas/Snow Peas/Large
Veggies/Peas/Snap Peas
Légumes/Pois

This string.
Breakfast/Crepes
.. would NOT be valid because the CultureName does not match between the
parent node (Breakfast is en-US) and child node (Crepes is fr-FR).

I would very much appreciate a suggestion for an algorithm I could use or
tweak to get what I need here.

Thanks
 
M

Micha³ Piaskowski

Jeremy said:
* This is a graph, not a tree, as each "child" node can have multiple
parents, and each parent can have multiple child nodes. For example, in the
sample data set, NodeID 1 has multiple parents (nodeID 2. differentiated on
CultureName).

If you group the records in source table by CultureName won't that
reduce this graph to a set of trees (one tree for each culture) and
also eliminate all invalid results ( like Breakfast/Crepes )?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top