graph-traversal

All possible path in a graph

折月煮酒 提交于 2020-01-25 08:18:05
问题 Given a graph G(V, E) , a source vertex s and destination vertex d , the problem is to find all possible paths from s to d where G may contain loops and cycles. I want to get all simple paths, no cycle is allowed. What would be the complexity of this problem? 回答1: This problem is NP-hard, since its output may have an exponential size w.r.t its input. Finding the longest path between two points is already NP-hard (reduction to hamiltonian path problem), so finding all of them is as well. You

Breadth First enumeration in Gremlin

心不动则不痛 提交于 2020-01-11 04:10:06
问题 I'm trying to get breadth first enumeration working with Gremlin, however I'm having trouble finding a way to output all the steps observed during the enumeration. I can only print out the result of the last iteration. My question would be, given a starting node like this, how can I follow all paths (without knowing the overall depth) using Gremlin and print out everything I find along the way? study=g.v('myId') I have tried the scatter approach, looping approach (although both seem to

Find a list of related classes Recursively

谁说我不能喝 提交于 2020-01-07 04:45:12
问题 Supose I have a class representing a friend and another one representing pairs of best friends and a list of pairs of best friends and want to know each friend that is indirectly related to each one's best friend, as follows: class Friend { string Name; } class BestFriends { Friend NameFriend1; Friend NameFriend2; } List<BestFriends> ListOfBestFriends = new List<BestFriends>(); Supose I have the BestFriends pairs as follows: Adam and Brian; Brian and Chris; Chris and Daniel; Eddie and Ian;

Cheapest cost traversal on Complete graph

亡梦爱人 提交于 2020-01-05 11:54:22
问题 I was wondering if there is an algorithm which: given a fully connected graph of n-nodes (with different weights)... will give me the cheapest cycle to go from node A (a start node) to all other nodes, and return to node A? Is there a way to alter an algorithm like Primm's to accomplish this? Thanks for your help EDIT: I forgot to mention I'm dealing with a undirected graph so the in-degree = out-degree for each vertex. 回答1: Can you not modify Dijkstra, to find you the shortest path to all

Cheapest cost traversal on Complete graph

你。 提交于 2020-01-05 11:53:41
问题 I was wondering if there is an algorithm which: given a fully connected graph of n-nodes (with different weights)... will give me the cheapest cycle to go from node A (a start node) to all other nodes, and return to node A? Is there a way to alter an algorithm like Primm's to accomplish this? Thanks for your help EDIT: I forgot to mention I'm dealing with a undirected graph so the in-degree = out-degree for each vertex. 回答1: Can you not modify Dijkstra, to find you the shortest path to all

Cheapest cost traversal on Complete graph

最后都变了- 提交于 2020-01-05 11:53:22
问题 I was wondering if there is an algorithm which: given a fully connected graph of n-nodes (with different weights)... will give me the cheapest cycle to go from node A (a start node) to all other nodes, and return to node A? Is there a way to alter an algorithm like Primm's to accomplish this? Thanks for your help EDIT: I forgot to mention I'm dealing with a undirected graph so the in-degree = out-degree for each vertex. 回答1: Can you not modify Dijkstra, to find you the shortest path to all

How to implement a DFS with immutable data types

♀尐吖头ヾ 提交于 2020-01-01 04:58:05
问题 I'm trying to figure out a neat way of traversing a graph Scala-style, preferably with vals and immutable data types. Given the following graph, val graph = Map(0 -> Set(1), 1 -> Set(2), 2 -> Set(0, 3, 4), 3 -> Set(), 4 -> Set(3)) I'd like the output to be the depth first traversal starting in a given node. Starting in 1 for instance, should yield for instance 1 2 3 0 4 . I can't seem to figure out a nice way of doing this without mutable collections or vars. Any help would be appreciated.

Arangodb AQL recursive graph traversal

纵饮孤独 提交于 2019-12-31 03:21:26
问题 I have a graph with three collections which items can be connected by edges. ItemA is a parent of itemB which in turn is a parent of itemC. Elements only can be connected by edges in direction "_from : child, _to : parent" Currently I can get only "linear" result with this AQL query: LET contains = (FOR v IN 1..? INBOUND 'collectionA/itemA' GRAPH 'myGraph' RETURN v) RETURN { "root": { "id": "ItemA", "contains": contains } } And result looks like this: "root": { "id": "itemA", "contains": [ {

Completeness of depth-first search

夙愿已清 提交于 2019-12-30 07:53:31
问题 I quote from Artificial Intelligence: A Modern Approach: The properties of depth-first search depend strongly on whether the graph-search or tree-search version is used. The graph-search version, which avoids repeated states and redundant paths, is complete in finite state spaces because it will eventually expand every node. The tree-search version, on the other hand, is not complete [...]. Depth-first tree search can be modified at no extra memory cost so that it checks new states against

Returning only the vertices in the actual shortest path

旧巷老猫 提交于 2019-12-30 06:59:13
问题 I know the title is a bit messy, but I don't know how to explain it better. What I'm trying to do: Using a graph found in a text file, find and print the shortest path (minimum amount of vertices) from vertex A to vertex B. Note: using breadth-first search, not Dijkstra's. What I've got: A working algorithm that applies BFS on the graph, but no good way of actually printing out the shortest path. I'm having a hard time distinguishing a vertex in the shortest path from one that is simply run