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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -