I was wondering if anyone can provide some pointers on how to check for diamond dependencies whilst performing a Depth-First Search over a graph…I have the following graph A -> B, A -> F, B -> C, B-> E, C -> D, E -> D.
I am trying to construct a hirearchy of containers that represent the specified graph however when I reach a diamond dependency I am not sure what to do. For example, in my graph, C and E are both child containers of B, when I resolve D, I need to reference C and E. Could I detect a diamond dependency and combine C and E into a single container?
I find it easiest to think of graph algorithms using colors.
All nodes start off white.
A node that’s being processed is colored gray.
Once a node has been processed color it black.
You color a node gray as soon as you encounter it.
You color a node black once you’ve finished processing its children.
If you encounter a black node then you’ve hit a diamond dependency.