Skip to main content
1 of 2
Luca Anzalone
  • 3.2k
  • 3
  • 14

A* is in general more efficient than BFS and GFS because it employs a heuristic function that basically provides the remaining distance between the actual node and the goal node (indeed, it depends on how you implement it.) So, in this way, A* tends to explore less nodes in general because it focuses more on the most important (nearest to the goal) ones.

For example, say you perform A* on a grid in which you can explore following 4 directions (up, down, left, and right). The heuristics would be the Manhattan distance telling the remaining distance from the actual position to the goal. So when this information is combined with the cost of the edge (or weight) it enables A* to be more efficient when exploring nodes.

Luca Anzalone
  • 3.2k
  • 3
  • 14