Imagine standing in a maze and needing the shortest way out. One option is to flood outward in every direction at once, checking each new square in turn until you stumble onto the exit. That works — it is exactly what Dijkstra's algorithm and breadth-first search do — but it wastes enormous effort exploring squares that point away from the goal.
Now suppose you also have a compass and roughly know where the exit lies. You would naturally favor steps that head toward it. That single extra hint is the whole idea behind A* (pronounced "A-star").
A* keeps a running tally of two numbers for every square it considers: the cost to reach it so far, plus an estimate of the cost still remaining to the goal. It always expands the square with the smallest total. The estimate — the heuristic — turns aimless flooding into a search that leans toward the answer.
Comments
Loading comments...