Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference and advantages between dijkstra & A star [duplicate]

I read this: http://en.wikipedia.org/wiki/A*_search_algorithm

It says A* is faster than using dijkstra and uses best-first-search to speed things up.

If I need the algorithm to run in milliseconds, when does A* become the most prominent choice.

From what I understand it does not necessarily return the best results.

If I need quick results, is it better to pre-compute the paths? It may take megabytes of space to store them.

like image 867
AturSams Avatar asked Oct 23 '12 13:10

AturSams


People also ask

What are the advantages of Dijkstra Algorithm?

The main advantage of Dijkstra's algorithm is its considerably low complexity, which is almost linear. However, when working with negative weights, Dijkstra's algorithm can't be used. , if we need to calculate the shortest path between any pair of nodes, using Dijkstra's algorithm is not a good option. .

What is the difference between Dijkstra and BFS?

BFS calculates the shortest paths in unweighted graphs.On the other hand, Dijkstra's algorithm calculates the same thing in weighted graphs.

What is the disadvantages of Dijkstra's algo?

2.1.2 Disadvantage of Dijkstra's Algorithm ➢ The major disadvantage of the algorithm is the fact that it does a blind search there by consuming a lot of time waste of necessary resources. ➢ It cannot handle negative edges. This leads to acyclic graphs and most often cannot obtain the right shortest path.

Is A * or Dijkstra better?

Conclusion. Even though Dijkstra's algorithm and the A* algorithm both find the same shortest paths, the A* algorithm does it almost 60 times faster!


1 Answers

It says A* is faster than using dijkstra and uses best-first-search to speed things up.

A* is basically an informed variation of Dijkstra.
A* is considered a "best first search" because it greedily chooses which vertex to explore next, according to the value of f(v) [f(v) = h(v) + g(v)] - where h is the heuristic and g is the cost so far.

Note that if you use a non informative heuristic function: h(v) = 0 for each v: you get that A* chooses which vertex to develop next according to the "so far cost" (g(v)) only, same as Dijkstra's algorithm - so if h(v) = 0, A* defaults to Dijkstra's Algorithm.

If I need the algorithm to run in milliseconds, when does A* become the most prominent choice.

Not quite, it depends on a lot of things. If you have a descent heuristic function - from my personal experience, greedy best first (choosing according to the heuristic function alone) - is usually significantly faster than A* (but is not even near optimal).

From what I understand it does not necessarily return the best results.

A* is both complete (finds a path if one exists) and optimal (always finds the shortest path) if you use an Admissible heuristic function. If your function is not admissible - all bets are off.

If I need quick results, is it better to pre-compute the paths? It may take megabytes of space to store them.

This is a common optimization done on some problems, for example on the 15-puzzle problem, but it is more advanced. A path from point A to point B is called a Macro. Some paths are very useful and should be remembered. A Machine Learning component is added to the algorithm in order to speed things up by remembering these Macros.

Note that the path from point A to point B in here is usually not on the states graph - but in the problem itself (for example, how to move a square from the lowest line to the upper line...)

To speed things up:
If you have a heuristic and you find it too slow, and you want a quicker solution, even if not optimal - A* Epsilon is usually faster then A*, while giving you a bound on the optimality of the path (how close it is to being optimal).

like image 63
amit Avatar answered Sep 23 '22 08:09

amit