graph-algorithm

BFS traversal using cypher

穿精又带淫゛_ 提交于 2019-12-23 02:26:32
问题 I need to traverse a directed acyclic graph (DAG) using BFS. I am using neo4j via REST API, so my main way of commuication with neo4j is using Cypher. With Cypher I can retrieve a set of all the paths from a starting node, and from them derive a BFS traversal. I was wondering if there's a simpler way of getting a BFS traversal using Cypher. What I expect as output would be an array of sets of nodes. 回答1: Couldn't you then just order resulting paths after length, maybe take the last node from

python graph-tool access vertex properties

安稳与你 提交于 2019-12-22 13:52:35
问题 For my current project I want to use the graph-tool library since they claim being the fastest: https://graph-tool.skewed.de/performance. I have some algorithms (shortest path, etc.) to run on really large networks, so the faster the better! First question: Is this claim 'being the fastest' true? ;) While trying to build a graph-tool graph fitting my needs, I figured out that its not possible to access vertex properties in a efficient way. Maybe I missed something? My question is now, can the

Algorithm to find and print simple cycle in complexity of O(n) on undirected graph

一曲冷凌霜 提交于 2019-12-22 10:34:27
问题 Given graph G(V,E), un-directed graph. |E| = m, |V| = n The graph's data structure is Adjacency list How to find and print simple cycle (or print that there is no such cycle) in complexity of O(n) ? (If there is cycle the output should be the list of vertex that are part of the cycle.) I know how to find cycle on complexity of O(n) , there is also gudies on the internet. My problem is how to print it. This is what I tried to do: DFS-CheckCycle ( Graph G) { p[] <- null //parent array foreach v

Find the maximally intersecting subset of ranges

删除回忆录丶 提交于 2019-12-22 05:18:07
问题 If you have a set of ranges, such as the following simple example... [ [12, 25], #1 [14, 27], #2 [15, 22], #3 [17, 21], #4 [20, 65], #5 [62, 70], #6 [64, 80] #7 ] ... how do you compute the maximally intersecting subset (not sure quite how to phrase it, but I mean "the subset of ranges which intersects and has the highest cardinality") and determine the degree of intersection (cardinality of ranges in that subset)? Logically I can work it out, and might be able to translate that to a naive

Cycle of maximum weight in a graph

跟風遠走 提交于 2019-12-22 04:47:20
问题 Given a weighted graph (directed or undirected) I need to find the cycle of the graph with the maximum weight. The weight of a cycle being the sum of the weight of the edges of the graph. It can be any cycle, not just base cycle for which we can find all base cycle (see Algorithms to Identify All the Cycle Bases in a UnDirected Graph ) compute the weight of each base cycle and find the maximum I could try to enumerate all cycles of the graph and then compute the maximum but the total number

Minimal addition to strongly connected graph

二次信任 提交于 2019-12-22 03:23:40
问题 I have a set of nodes and set of directed edges between them. The edges have no weight. How can I found minimal number of edges which has to be added to make the graph strongly connected (ie. there should be a path from every node to all others)? Does this problem have a name? 回答1: It's a really classical graph problem. Run algorithm like Tarjan-SCC algorithm to find all SCCs. Consider each SCC as a new vertice, link a edge between these new vertices according to the origin graph, we can get

Finding all paths in directed graph with specific cost

感情迁移 提交于 2019-12-21 20:22:37
问题 Suppose we have the directed, weighted graph. Our task is to find all paths beetween two vertices (source and destination) which cost is less or equal =< N. We visit every vertex only once. In later version I'd like to add a condition that the source can be the destination (we just make a loop). I think it can be done with modified Dijkstra's algorithm, but I have no idea how implement such thing. Thanks for any help. 回答1: You could use recursive backtracking to solve this problem. Terminate

Convert weighted direct cyclic graph to equivalent acyclic graph

て烟熏妆下的殇ゞ 提交于 2019-12-21 17:36:05
问题 I have a cyclic weighted directed graph and the goal is to remove the cycle present in the path. eg: the paths are as below, from | to | weight ------------------ a -> b | 0.5 a -> c | 0.5 c -> e | 1 b -> d | 1 d -> a | 0.25 d -> f | 0.75 the cycle in the graph is introduced by the path d -> a. Can anyone suggest an algorithm to remove the cycle d -> a by adjusting the weights of the other nodes. The resulting acyclic graph to be equivalent in terms of passing on the weights to the end nodes

AStar - explanation of name

心不动则不痛 提交于 2019-12-21 07:16:32
问题 I am looking for an explanation why the AStar / A* algorithm is called AStar. All similar (shortest path problem) algorithms are often named like its developer(s), so what is AStar standing for? 回答1: There were algorithms called A1 and A2. Later, it was proved that A2 was optimal and in fact also the best algorithm possible, so he gave it the name A* which symbolically includes all possible version numbers. Source: In 1964 Nils Nilsson invented a heuristic based approach to increase the speed

Finding edge connectivity of a network by using Maximum Flow algorithm

拥有回忆 提交于 2019-12-21 04:39:08
问题 I want to find the edge connectivity (i.e. minimum number of edges to remove to disconnect a graph) of an undirected graph using maximum flow algorithms (Edmond Karp / Ford-Fulkerson algorithms) , I know that I can accomplish this task by finding the minimum maximum flow between every two nodes of a graph , but this would result O(|V| ^ 2) number of flow networks , int Edge-Connectivity(Graph G){ int min = infinite; for (Vertex u: G.V){ for (Vertex v: G.V){ if (u != v){ //create directed