Quantcast
Channel: How does Dijkstra's Algorithm and A-Star compare? - Stack Overflow
Viewing all articles
Browse latest Browse all 13

Answer by Shahadat Hossain for How does Dijkstra's Algorithm and A-Star compare?

$
0
0

Dijkstra:

It has one cost function, which is real cost value from source to each node: f(x)=g(x).
It finds the shortest path from source to every other node by considering only real cost.

A* search:

It has two cost function.

  1. g(x): same as Dijkstra. The real cost to reach a node x.
  2. h(x): approximate cost from node x to goal node. It is a heuristic function. This heuristic function should never overestimate the cost. That means, the real cost to reach goal node from node x should be greater than or equal h(x). It is called admissible heuristic.

The total cost of each node is calculated by f(x)=g(x)+h(x)

A* search only expands a node if it seems promising. It only focuses to reach the goal node from the current node, not to reach every other nodes. It is optimal, if the heuristic function is admissible.

So if your heuristic function is good to approximate the future cost, than you will need to explore a lot less nodes than Dijkstra.


Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>