algorithm - How can I convert an undirected graph to directed graph with no cycle (Directed acyclic graph) -
i have undirected graph , wish transform directed graph. have few constraint, such having directed relations.
you trying build dag infrastructure graph. note directed graph dag if , if can topologically sorted.
so, let's go end beginning. first create topological sort, , connect nodes in way obey sort.
- first, remove "undetermined" edges, , keep have directions for.
- then, topological sort on graph , find topological sort (if there none, problem cannot solved given restrictions).
- based on it, first last set direction of each edge such source node 1 lower topological sort.
time complexity of algorithm linear in number of nodes , edges.
Comments
Post a Comment