directed-graph

How to detect if adding an edge to a directed graph results in a cycle?

旧街凉风 提交于 2019-11-28 05:47:01
I came upon wait-for graphs and I wonder, are there any efficient algorithms for detecting if adding an edge to a directed graph results in a cycle? The graphs in question are mutable (they can have nodes and edges added or removed). And we're not interested in actually knowing an offending cycle, just knowing there is one is enough (to prevent adding an offending edge). Of course it'd be possible to use an algorithm for computing strongly connected components (such as Tarjan's) to check if the new graph is acyclic or not, but running it again every time an edge is added seems quite

Graph serialization

北城以北 提交于 2019-11-27 10:27:44
问题 I'm looking for a simple algorithm to 'serialize' a directed graph. In particular I've got a set of files with interdependencies on their execution order, and I want to find the correct order at compile time. I know it must be a fairly common thing to do - compilers do it all the time - but my google-fu has been weak today. What's the 'go-to' algorithm for this? 回答1: Topological Sort (From Wikipedia): In graph theory, a topological sort or topological ordering of a directed acyclic graph (DAG

How do I check if a directed graph is acyclic?

╄→гoц情女王★ 提交于 2019-11-27 06:09:51
How do I check if a directed graph is acyclic? And how is the algorithm called? I would appreciate a reference. FryGuy I would try to sort the graph topologically , and if you can't, then it has cycles. Doing a simple depth-first-search is not good enough to find a cycle. It is possible to visit a node multiple times in a DFS without a cycle existing. Depending on where you start, you also might not visit the entire graph. You can check for cycles in a connected component of a graph as follows. Find a node which has only outgoing edges. If there is no such node, then there is a cycle. Start a

How to detect if adding an edge to a directed graph results in a cycle?

依然范特西╮ 提交于 2019-11-27 05:37:17
问题 I came upon wait-for graphs and I wonder, are there any efficient algorithms for detecting if adding an edge to a directed graph results in a cycle? The graphs in question are mutable (they can have nodes and edges added or removed). And we're not interested in actually knowing an offending cycle, just knowing there is one is enough (to prevent adding an offending edge). Of course it'd be possible to use an algorithm for computing strongly connected components (such as Tarjan's) to check if

GraphViz - How to connect subgraphs?

你。 提交于 2019-11-26 21:17:44
In the DOT language for GraphViz , I'm trying to represent a dependency diagram. I need to be able to have nodes inside a container and to be able to make nodes and/or containers dependent on other nodes and/or containers. I'm using subgraph to represent my containers. Node linking works just fine, but I can't figure out how to connect subgraphs. Given the program below, I need to be able to connect cluster_1 and cluster_2 with an arrow, but anything I've tried creates new nodes instead of connecting the clusters: digraph G { graph [fontsize=10 fontname="Verdana"]; node [shape=record fontsize

GraphViz - How to connect subgraphs?

人盡茶涼 提交于 2019-11-26 12:17:58
问题 In the DOT language for GraphViz , I\'m trying to represent a dependency diagram. I need to be able to have nodes inside a container and to be able to make nodes and/or containers dependent on other nodes and/or containers. I\'m using subgraph to represent my containers. Node linking works just fine, but I can\'t figure out how to connect subgraphs. Given the program below, I need to be able to connect cluster_1 and cluster_2 with an arrow, but anything I\'ve tried creates new nodes instead

Best algorithm for detecting cycles in a directed graph

好久不见. 提交于 2019-11-26 01:19:44
问题 What is the most efficient algorithm for detecting all cycles within a directed graph? I have a directed graph representing a schedule of jobs that need to be executed, a job being a node and a dependency being an edge. I need to detect the error case of a cycle within this graph leading to cyclic dependencies. 回答1: Tarjan's strongly connected components algorithm has O(|E| + |V|) time complexity. For other algorithms, see Strongly connected components on Wikipedia. 回答2: Given that this is a