DEV Community

Cover image for Graph Search: Dijkstra vs A*
Carlos Almonte
Carlos Almonte

Posted on

Graph Search: Dijkstra vs A*

These are two famous algorithm to find a target value in a graph data structure. A graph is a data structure that allows to represent relationships between values. A graph is useful to represent followings, e.g., Carlos follows alice, bob, and charlie.

Dijkstra find the distance between start node to all other nodes. Effectively each node will have a distance between start and the current node. A* finds the distance between start node and a specfic target node, and as it moves through the graph it evaluates which node to go to next so that it travels closer to the target at each step. Dijsktra traverses the graph by picking the next node with the smallest distance from current node, this means there are cases where it could be moving away form the target node, if a target node is what is expected. For this reason, A* is faster at finding a target node, Dijkstra is better at finding overall distances to all nodes starting from a start node.

It would be nice to actually use this in practice.

Top comments (0)