directed-graph

How can I find all 'long' simple acyclic paths in a graph?

删除回忆录丶 提交于 2019-12-11 13:22:27
问题 Let's say we have a fully connected directed graph G . The vertices are [a,b,c] . There are edges in both directions between each vertex. Given a starting vertex a , I would like to traverse the graph in all directions and save the path only when I hit a vertex which is already in the path. So, the function full_paths(a,G) should return: - [{a,b}, {b,c}, {c,d}] - [{a,b}, {b,d}, {d,c}] - [{a,c}, {c,b}, {b,d}] - [{a,c}, {c,d}, {d,b}] - [{a,d}, {d,c}, {c,b}] - [{a,d}, {d,b}, {b,c}] I do not need

Confusions on finding a cycle in a possibly unconnected directed graph

二次信任 提交于 2019-12-11 12:49:53
问题 I am confused about this answer. Why can't DFS decide if there is a cycle in a directed graph while visiting each node and each edge at most once? Using the white, gray, black method, one should be able to find a cycle if there is a backward edge. For an unconnected directed graph, why can't one do the following: run DFS from an arbitrary node v and visit as many nodes as v is connected to, then run DFS on another unvisited arbitrary node in the graph, if any, until all nodes are visited? It

What is the difference between Floyd-Warshall and matrix multiplication graph algorithms?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 09:26:40
问题 I have to solve the following problem: Write a program that, given a directed graph with costs and two vertices, finds a lowest cost walk between the given vertices, or prints a message if there are negative cost cycles in the graph. The program shall use the matrix multiplication algorithm. I implemented the matrix multiplication algorithm as it is defined: a pseudo-matrix multiplication, where addition is replaced by minimization and multiplication with addition. But by doing this, I ended

How to create an adjacency list of a directed graph in C?

限于喜欢 提交于 2019-12-11 07:34:22
问题 EDIT: No one has answered yet but I think it has to do with how I'm storing my list. Right now I'm storing every vertex in an array of nodes called G. However I think I need to make it a two dimensional array in order for me not to overwrite data in other Nodes. (This is very confusing) As the title says I'm trying to create a directed graph. I'm running into a problem where each time I try to add a Node to the adjacency list of a vertex it is altering a previous vertex's list. For example I

Obtain weight of a path with iGraph in R

為{幸葍}努か 提交于 2019-12-11 04:14:13
问题 I have a graph I created from a data frame, in the form of from, to, cost columns. I also have a path (as a succession of vertexes, in the vpath format of igraph ) which is valid (my graph is directed). Is there any function that, given my graph and my path, would give me the cost of that path? I'm not asking for the shortest path, as I obtained the path from all_shortest_paths . However, I only get the node succession and not the weight of the path, which I also need. Edit: Data This is my

neo4j logic gate simulation, how to?

China☆狼群 提交于 2019-12-11 03:14:39
问题 I would like to create a bunch of "and" and "or" and "not" gates in a directed graph. And then traverse from the inputs to see what they results are. I assume there is a ready made traversal that would do that but I don't see it. I don't know what the name of such a traversal would be. Certainly breadth first will not do the job. I need to get ALL the leaves, and go up toward the root. In other words A = (B & (C & Z)) I need to resolve C @ Z first. I need to put this type of thing in a graph

How to count all reachable nodes in a directed graph?

↘锁芯ラ 提交于 2019-12-10 16:57:59
问题 There is a directed graph (which might contain cycles), and each node has a value on it, how could we get the sum of reachable value for each node. For example, in the following graph: the reachable sum for node 1 is: 2 + 3 + 4 + 5 + 6 + 7 = 27 the reachable sum for node 2 is: 4 + 5 + 6 + 7 = 22 ..... My solution: To get the sum for all nodes, I think the time complexity is O(n + m), the n is the number of nodes, and m stands for the number of edges. DFS should be used,for each node we should

Data structure for directed graphs, allowing fast node deletion?

夙愿已清 提交于 2019-12-10 12:55:12
问题 I need to store a directed graph (not necessarily acyclic), so that node deletion is as fast as possible. I wouldn't mind storing additional data in order to know exactly which edges have to go when a node is deleted. If I store a list of edges (as pairs of node indexes), then when killing some node n I have to search the whole list for edges whose source or target is n. This is too costly for my application. Can this search be avoided by storing some additional data in the nodes? One idea

Is backtracking absolutely necessary for cycle detection using DFS in directed graph?

痞子三分冷 提交于 2019-12-10 10:53:27
问题 I came across this SO post where it is suggested that cycle detection using DFS in a directed graph is faster because of backtracking. Here I quote from that link: Depth first search is more memory efficient than breadth first search as you can backtrack sooner. It is also easier to implement if you use the call stack but this relies on the longest path not overflowing the stack. Also if your graph is directed then you have to not just remember if you have visited a node or not, but also how

Generate all possible subgraphs of a directed graph keeping the number of vertices

Deadly 提交于 2019-12-10 10:48:36
问题 I have two lists of vertices: V and S . I would like to generate all possible directed graphs from V and S so, that each vertex from V has only one out-edge and exactly one in-edge, and each vertex from S can have any number of in- and out- edges. Each graph in the result should contain exactly all vertices from V and from S . The result can contain both connected and disconnected graphs. First I thought it was a powerset-related problem, but powerset has many other sets that may contain just