shortest-path

Eppstein's algorithm and Yen's algorithm for k shortest paths

放肆的年华 提交于 2019-11-29 01:51:19
I'm trying to understand exactly how these algorithms work, but I have been unable to find a simple explanation. I would greatly appreciate it if someone could provide or point me to a description of these algorithms that is easier to understand than the description in the original papers. Thanks. Alma Rahat First of all let me provide you with the links to the papers you were talking about. Eppstein's paper: D. Eppstein, “Finding the k shortest paths,” SIAM J. Comput., vol. 28, no. 2, pp.652–673, Feb. 1999 Yen's paper: J. Y. Yen, “Finding the K Shortest Loopless Paths in a Network,”

graph - How to find Minimum Directed Cycle (minimum total weight)?

我与影子孤独终老i 提交于 2019-11-28 22:02:54
Here is an excise: Let G be a weighted directed graph with n vertices and m edges, where all edges have positive weight. A directed cycle is a directed path that starts and ends at the same vertex and contains at least one edge. Give an O(n^3) algorithm to find a directed cycle in G of minimum total weight. Partial credit will be given for an O((n^2)*m) algorithm. Here is my algorithm. I do a DFS . Each time when I find a back edge , I know I've got a directed cycle. Then I will temporarily go backwards along the parent array (until I travel through all vertices in the cycle) and calculate the

Efficiently finding the shortest path in large graphs

十年热恋 提交于 2019-11-28 21:23:22
问题 I'm looking to find a way to in real-time find the shortest path between nodes in a huge graph. It has hundreds of thousands of vertices and millions of edges. I know this question has been asked before and I guess the answer is to use a breadth-first search, but I'm more interested in to know what software you can use to implement it. For example, it would be totally perfect if it already exist a library (with python bindings!) for performing bfs in undirected graphs. 回答1: python-graph added

Dijkstra vs. Floyd-Warshall: Finding optimal route on all node pairs

那年仲夏 提交于 2019-11-28 17:52:25
I am reading up on Dijkstra's algorithm and the Floyd-Warshall algorithm. I understand that Dijkstra's finds the optimal route from one node to all other nodes and Floyd-Warshall finds the optimal route for all node pairings. My question is would Dijkstra's algorithm be more efficient than Floyd's if I run it on every single node in order to find the optimal route between all pairings. Dijkstra's runtime is O(E + VlogV) where Floyd's is O(V 3 ). If Dijkstra's fails, what would its runtime be in this case? Thanks! As others have pointed out, Floyd-Warshall runs in time O(n 3 ) and running a

Using BFS for Weighted Graphs

女生的网名这么多〃 提交于 2019-11-28 17:35:28
I was revising single source shortest path algorithms and in the video, the teacher mentions that BFS/DFS can't be used directly for finding shortest paths in a weighted graph (I guess everyone knows this already) and said to work out the reason on your own. I was wondering the exact reason/explanation as to why it can't be used for weighted graphs. Is it due to the weights of the edges or anything else ? Can someone explain me as I feel a little confused. PS: I went through this question and this question. Consider a graph like this: A---(3)-----B | | \-(1)-C--(1)/ The shortest path from A to

Minimum distance between start and end by going through must visit points in a maze

旧街凉风 提交于 2019-11-28 11:39:06
问题 So, suppose i have a maze, which has a start point and an end point, marked with Orange and red respectively and my goal is to find the minimum distance between them. The blocked path is represented by black colour and the open path is represented by white colour . However there are two modification done in this. There are some cells which are must visit, marked in grey colour. Any cell can be visited any number of times(even the start, finish and must visit points) for ex- B=Black, W=white,

How can I use the A star algorithm to find the first 100 shortest paths?

拜拜、爱过 提交于 2019-11-28 05:49:54
问题 How can I use the A star algorithm to find the first 100 shortest paths? 回答1: The problem of finding k'th shortest path is NP-Hard, so any modification to A-Star that will do what you are after - will be exponential in the size of the input. Proof: (Note: I will show on simple paths) Assume you had a polynomial algorithm that runs in polynomial time and returns the length of k the shortest path let the algorithm be A(G,k) The maximal number of paths is n! , and by applying binary search on

What is the difference between Dijkstra and Prim's algorithm?

别来无恙 提交于 2019-11-28 04:56:05
Can any one tell me the difference between Dijkstra's and Prim's algorithms? I know what each of the algorithms do. But they look the same to me. Dijkstra's algorithm stores a summation of minimum cost edges whereas Prim's algorithm stores at most one minimum cost edge. Isn't this the same? Dijsktra's algorithm finds the minimum distance from node i to all nodes (you specify i). So in return you get the minimum distance tree from node i. Prims algorithm gets you the minimum spaning tree for a given graph . A tree that connects all nodes while the sum of all costs is the minimum possible. So

Shortest path (fewest nodes) for unweighted graph

泄露秘密 提交于 2019-11-28 03:52:13
I'm trying build a method which returns the shortest path from one node to another in an unweighted graph. I considered the use of Dijkstra's but this seems a bit overkill since I only want one pair. Instead I have implemented a breadth-first search, but the trouble is that my returning list contains some of the nodes that I don't want - how can I modify my code to achieve my goal? public List<Node> getDirections(Node start, Node finish){ List<Node> directions = new LinkedList<Node>(); Queue<Node> q = new LinkedList<Node>(); Node current = start; q.add(current); while(!q.isEmpty()){ current =

How to calculate the shortest path between two points in a grid

岁酱吖の 提交于 2019-11-28 03:34:55
I know that many algorithms are available for calculating the shortest path between two points in a graph or a grid, like breadth-first, all-pairs (Floyd's), Dijkstra's. However, as I noticed, all of these algorithms compute all the paths in that graph or grid, not only those between the two points we are interested in. MY QUESTION IS: if I have a grid, i.e. a two dimensional array, and I'm interested in computing the shortest path between two points, say P1 and P2, and if there are restrictions on the way I can move on the grid (for example only diagonally, or only diagonally and upwards, etc