directed-graph

Union-Find/Disjoin-Set data structure for Directed Graph

孤人 提交于 2019-12-13 15:25:50
问题 I'm looking for an efficient Union-Find (aka Disjoint Set) data structure for my directed graph, which has cycles and forests. Given such a graph G , I want to to answer following queries: Can I reach node v from u ? From which nodes, u is not reachable? For a single "source" node u , I can run DFS search and answer whether I can reach v from it. A single DFS search will have an upper-bound cost of m + n in the worst-case, where m and n are the number of vertices and edges in the graph,

How to create a multiple linked & directed graph with javascript?

雨燕双飞 提交于 2019-12-13 12:38:05
问题 This is my problem: For a school project we are trying to create a directed graph and make it fit in a typical html website. We figured out it had to be written in javascript, because a java applet isn´t an option. So this is how it should look like: image. The data visualised in the graph will be gathered from some xml files. We took a look at flare and some other packages, but real thing is making a two-way link between the nodes (where the thickness of the arrow represents importance) in

Read adjacency list of digraph from a text file in C++

眉间皱痕 提交于 2019-12-13 09:53:06
问题 I have a text file which has some number of integers in each line. Example: 1 2 4 3 0 4 2 3 Here 1st line means that the 1st node is connected to nodes numbered 1, 2 and 5. Blank line means 4th node isn't connected to any node. This gives me a directed graph. This SO question might have been helpful but it assumes each line to have 2 integers, whereas in this case it can have any number of integers from 0 to N-1(N is no. of nodes). I just want to know how to read this text file. If I had two

Will SCC pattern change if we reverse a graph(using Kosaraju's Algorithm)?

孤人 提交于 2019-12-13 02:56:53
问题 Assume we have a digraph, it is not a complete graph and has more than one SCC. I wonder if the patterns of Strongly Connected Component changes if we transpose the graph and use Kosaraju's Algorithm? By saying "transpose the graph" I mean flip the direction of edges. If we try to find SCC in the transposed/reversed graph instead of the original, will the SCC we find be different? I came up with this question as I misunderstood the algorithm of SCC and runs it on my transposed/reversed graph.

Finding all cycles in directed graphs of length <= k

岁酱吖の 提交于 2019-12-13 00:53:08
问题 Is there a way of modifing the algorithm in Finding all cycles in undirected graphs to consider edges as directed and only cycles of length <= k ? 回答1: I reply by myself static void Main(string[] args) { int k = 4; for (int i = 0; i < graph.GetLength(0); i++) for (int j = 0; j < graph.GetLength(1); j++) { findNewCycles(new int[] { graph[i, j] },k); } foreach (int[] cy in cycles) { string s = "" + cy[0]; for (int i = 1; i < cy.Length; i++) s += "," + cy[i]; Console.WriteLine(s); } } static

how to use neato with spline and avoid mutual edges overlapping?

三世轮回 提交于 2019-12-12 18:40:19
问题 I have a directed graph with ~20 nodes that I need to have their positions fixed. So, I'm using neato to generate my svg file. The problem is that if I use the straight lines, I have edges overlapping some of the nodes. If a set -Gsplines=true -Gsep=1 the edges avoid the nodes nicely but them the mutual nodes (that is, nodes from a -> b and b -> a) are displayed on top of each other... Below is a piece of it, for example, where edges 9 -> 12 and 12 -> are completely overlapped. Does anyone

How to unit test graph nodes with mockito?

人走茶凉 提交于 2019-12-12 03:21:15
问题 Consider the following class: public class Node { private final Collection<Node> mDependants = new ArrayList<>(); private Node mDependency; public void initialize(final Node node) { // complex code that might call registerDependency; } private void registerDependency(final Node node) { mDependency = node; node.registerDependent(this); } private void registerDependent(final Node node) { mDependants.add(node); } } And then a unit test like: import static org.mockito.Mockito.mock; public class

Directed Graph Initialization

随声附和 提交于 2019-12-12 02:38:03
问题 public class Node { private final int vertex; private final HashSet<Node> nodes; public Node(int index) { this.index = index; this.nodes = new HashSet<Node>(); } protected void addOutgoingEdge(Node a) { nodes.add(a); } public class DirectedGraph { private Map<Integer, Node> vertices; public DirectedGraph(String str) { this.vertices = new HashMap<Integer, Node>(); str = str.replaceAll("[a\\s\\[]", ""); String[] edges = str.split("]"); for (String edge : edges) { String[] points = edge.split(",

How to reduce a strongly connected component to one vertex?

时光毁灭记忆、已成空白 提交于 2019-12-11 16:48:40
问题 From https://algs4.cs.princeton.edu/42digraph/ Reachable vertex in a digraph. Design a linear-time algorithm to determine whether a digraph has a vertex that is reachable from every other vertex. Kosaraju-Sharir algorithm gives us the strongly connected components. Java code for that can be seen here. Reducing each SCC to a single vertex, a vertex that has outdegree zero is reachable from every other. Problem is, everyone seems to be talking about reducing a SCC without providing details.

Find all spanning trees of a directed weighted graph

家住魔仙堡 提交于 2019-12-11 14:13:57
问题 I have found this paper so far. Is it outdated? Are there any faster and better implementations? By the way, Wikipedia says that there can be n^n-2 spanning trees in a undirected graph. How many spanning trees can be in a directed graph? 回答1: If you use terms from paper you mentioned and you define spanning tree of directed graph as tree rooted in vertex r, having unique path from r to any other vertex then: It's obvious that worst case when directed graph has the greatest number of the