graph-theory

Dijkstra's algorithm with back tracking?

女生的网名这么多〃 提交于 2019-12-01 11:18:00
In a related thread , it was suggested that I impliment Dijkstra's algorithm for finding the shortest path on a graph. Looking at this .gif of the algorithm from wikipedia: What if the path 1,3,6,5 turned out to be very low cost? For example, the weight on 3-6 was 1, and the weight on 6-5 was 2? Dijkstra's algorithm would not consider this path because it only looks one step ahead; it skipped node 3. Is it acceptable to specify a parameter that makes the algorithm look 2,3,4...n steps ahead before choosing each node? I realize that this could potentially blow up computational time, but as long

Does this python code employs Depth First Search (DFS) for finding all paths?

我与影子孤独终老i 提交于 2019-12-01 09:49:43
This code is given in python official essays on graph theory . Here's the code: def find_all_paths(graph, start, end, path=[]): path = path + [start] if start == end: return [path] if not graph.has_key(start): return [] paths = [] for node in graph[start]: if node not in path: newpaths = find_all_paths(graph, node, end, path) for newpath in newpaths: paths.append(newpath) return paths I am not adept at python as I haven't yet had enough of practicing and reading in it. Can you please explain the code by relating this to the child-sibling concept in DFS diagram? Thanks. The key to seeing that

Does this python code employs Depth First Search (DFS) for finding all paths?

假如想象 提交于 2019-12-01 07:35:01
问题 This code is given in python official essays on graph theory. Here's the code: def find_all_paths(graph, start, end, path=[]): path = path + [start] if start == end: return [path] if not graph.has_key(start): return [] paths = [] for node in graph[start]: if node not in path: newpaths = find_all_paths(graph, node, end, path) for newpath in newpaths: paths.append(newpath) return paths I am not adept at python as I haven't yet had enough of practicing and reading in it. Can you please explain

How to filter data in R?

♀尐吖头ヾ 提交于 2019-12-01 06:42:28
I have huge data sets which contains more than millions of rows and has some peculiar attributes. I need to filter the data retaining its other properties. My data is as like following: ID Prop1 Prop2 TotalProp 56891940 G02 G02 2 56892558 A61 G02 4 56892558 A61 A61 4 56892558 G02 A61 4 56892558 A61 A61 4 56892552 B61 B61 3 56892552 B61 B61 3 56892552 B61 A61 3 56892559 B61 G61 3 56892559 B61 B61 3 56892559 B61 B61 3 and so on more than million rows What I want is, I need to remove rows if all rows ID having 56891940 and 56892559 which have "prop1" and "prop2" same but not 56892558 and 56892559

How to compute the critical path of a directional acyclic graph?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 05:55:31
What is the best (regarding performance) way to compute the critical path of a directional acyclic graph when the nodes of the graph have weight? For example, if I have the following structure: Node A (weight 3) / \ Node B (weight 4) Node D (weight 7) / \ Node E (weight 2) Node F (weight 3) The critical path should be A->B->F (total weight: 10) I have no clue about "critical paths", but I assume you mean this . Finding the longest path in an acyclic graph with weights is only possible by traversing the whole tree and then comparing the lengths, as you never really know how the rest of the tree

How to filter data in R?

余生长醉 提交于 2019-12-01 05:29:10
问题 I have huge data sets which contains more than millions of rows and has some peculiar attributes. I need to filter the data retaining its other properties. My data is as like following: ID Prop1 Prop2 TotalProp 56891940 G02 G02 2 56892558 A61 G02 4 56892558 A61 A61 4 56892558 G02 A61 4 56892558 A61 A61 4 56892552 B61 B61 3 56892552 B61 B61 3 56892552 B61 A61 3 56892559 B61 G61 3 56892559 B61 B61 3 56892559 B61 B61 3 and so on more than million rows What I want is, I need to remove rows if all

Find all possible Euler cycles

坚强是说给别人听的谎言 提交于 2019-12-01 04:58:23
问题 I have implemented an algorithm to find an Euler cycle for a given starting vertex in an undirected graph (using DFS and removing visited edges), but it always returns only one path. How do I modify the algorithm to search for all possible Euler cycles for a vertex? Here is relevant code: typedef int Graph[200][200]; // adjacency matrix int v, e; // vertex count, edge count ...... void DFS(Graph &G, int x) { int i; Push(x); for (i = 0; i < v; i++) if (G[i][x] > 0) { G[i][x] = 0; G[x][i] = 0;

Finding all cycles in an undirected graph

和自甴很熟 提交于 2019-12-01 04:12:08
If I have an undirected graph, how can I get a list of all cycles? For example, from the following graph, I would want the cycles: (a,b,d,e,c) (a,b,c) (b,d,e) You presumably want only simple cycles (those that don't repeat a vertex), or there's an infinite number of them. Even then, there can be an exponential number of cycles. Perhaps this isn't the problem you really want to solve? this is not possible in polynomial time as if possible then we could use this to find all cycles and hence cycle of largest length which implies we can solve hamiltonian cycle problem completely in polynomial time

A tree, where each node could have multiple parents

↘锁芯ラ 提交于 2019-12-01 03:44:17
Here's a theoretical/pedantic question: imagine properties where each one could be owned by multiple others. Furthermore, from one iteration of ownership to the next, two neighboring owners could decide to partly combine ownership. For example: territory 1, t=0: a,b,c,d territory 2, t=0: e,f,g,h territory 1, t=1: a,b,g,h territory 2, t=1: g,h That is to say, c and d no longer own property; and g and h became fat cats, so to speak. I'm currently representing this data structure as a tree where each child could have multiple parents. My goal is to cram this into the Composite design pattern; but

Use Dijkstra's to find a Minimum Spanning Tree?

十年热恋 提交于 2019-12-01 03:18:08
Dijkstra's is typically used to find the shortest distance between two nodes in a graph. Can it be used to find a minimum spanning tree ? If so, how? Edit: This isn't homework, but I am trying to understand a question on an old practice exam. Strictly, the answer is no. Dijkstra's algorithm finds the shortest path between 2 vertices on a graph. However, a very small change to the algorithm produces another algorithm which does efficiently produce an MST. The Algorithm Design Manual is the best book I've found to answer questions like this one. Brian Cristante The answer is no. To see why, let