Reputation: 1377
I have an undirected graph and I wish to transform it to a directed graph. I will have few constraint, such as already having some directed relations.
Upvotes: 0
Views: 1535
Reputation: 178471
You are actually trying to build a DAG from your infrastructure graph. Note that a directed graph is a DAG if and only if it can be topologically sorted.
So, let's go from the end to the beginning. First create the topological sort, and then connect nodes in a way that obey the sort.
Time complexity of the algorithm is linear in the number of nodes and edges.
Upvotes: 2