I'm trying to find an algorithm for graphs with the following contents:
- Nodes with no edges leading out of them (shown here as a red circle)
- All other nodes have exactly two edges leading out (shown here as green diamonds)
I need to render these graphs a specific way:
- Each circle has a known position.
- Each diamond's position is determined by the positions of the nodes it is connected to.
The data is arranged as shown, but to be clear
CircleNode : { Position }
DiamondNode : { NodeA, NodeB, Position = Route(NodeA, NodeB) }
Graph : { CircleNodes, DiamondNodes }
My solution works for most of the graphs I've constructed, but the more complex graphs I have overflow the stack long before they converge. I think I can use most of my existing code if I provide the nodes in depth last order - circles, then nearest diamonds, then next nearest to those, and so on. However, I'm not sure how to prove this will work for all graphs of this type.
What is this kind of problem called?
Is there a proven algorithm that can be applied?
Note: the diagrams above do not reflect the intended render layout, only how the data is represented in memory.