AStar – explanation of name

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 of Dijkstra’s algorithm. This … Read more

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

As others have pointed out, Floyd-Warshall runs in time O(n3) and running a Dijkstra’s search from each node to each other node, assuming you’re using a Fibonacci heap to back your Dijkstra’s implementation, takes O(mn + n2 log n). However, you cannot always safely run Dijkstra’s on an arbitrary graph because Dijkstra’s algorithm does not … Read more

Finding all the shortest paths between two nodes in unweighted undirected graph

As a caveat, remember that there can be exponentially many shortest paths between two nodes in a graph. Any algorithm for this will potentially take exponential time. That said, there are a few relatively straightforward algorithms that can find all the paths. Here’s two. BFS + Reverse DFS When running a breadth-first search over a … Read more

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

Lee’s algorithm: http://en.wikipedia.org/wiki/Lee_algorithm It’s essentially a BF search, here’s an example: http://www.oop.rwth-aachen.de/documents/oop-2007/sss-oop-2007.pdf To implement it effectively, check my answer here: Change FloodFill-Algorithm to get Voronoi Territory for two data points? – when I say mark, you mark it with the number on the position you came from + 1. For example, if you have this … Read more

Bellman-Ford vs Dijkstra: Under what circumstances is Bellman-Ford better?

Bellman-Ford algorithm is a single-source shortest path algorithm, so when you have negative edge weight then it can detect negative cycles in a graph. The only difference between the two is that Bellman-Ford is also capable of handling negative weights whereas Dijkstra Algorithm can only handle positives. From wiki However, Dijkstra’s algorithm greedily selects the … Read more

A* Algorithm for very large graphs, any thoughts on caching shortcuts?

You should be able to make it much faster by trading off optimality. See Admissibility and optimality on wikipedia. The idea is to use an epsilon value which will lead to a solution no worse than 1 + epsilon times the optimal path, but which will cause fewer nodes to be considered by the algorithm. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)