Skip to main content
Independent Digital Museum of Artificial Intelligence · Laboratory
Accessibility

These choices are saved only on this device.

English

Laboratory · Interactive exhibit LAB-08

An algorithm that looks for a path and shows what it examined

Build walls, place a start and a goal, and watch step by step which cells the algorithm examines. Then compare three ways of searching on the same maze.

Simulation: a real A* algorithm on an artificial grid, run locally

Try it

The maze

Arrow keys move around the grid. Enter or space applies the selected tool to the cell. With a mouse you can drag to paint walls.

Comparison on the same maze

Observe

  1. On the “Wall with a gap” layout, first run the mode without a heuristic (Dijkstra) and then A*. How many cells did each one examine?
  2. Switch to the “Path that misleads” layout and press “Compare the three modes”. The heuristic-only mode finds a longer path. Why?
  3. Wall off the goal. How does the algorithm find out that no solution exists?

What happened

A* keeps two numbers for every cell. g is the number of steps already taken from the start. h is an estimate of the steps left to the goal, here the Manhattan distance: the horizontal and vertical steps if there were no walls. It examines the cell with the smallest g + h first.

When the estimate never exceeds the true cost, A* guarantees a shortest path and usually examines far fewer cells than search without a heuristic. If you look only at h, as in the greedy mode, you examine even fewer cells, but you lose the guarantee: you find a path, not necessarily the shortest.

The heuristic in this example is simple. In practice, choosing the heuristic is a design decision that determines how fast and how reliably the system works.

What to keep

  • A heuristic is an estimate that guides the search. It is not a guarantee.
  • A* is optimal when the heuristic never exceeds the true cost.
  • A* is a classical search algorithm, not machine learning. It does not learn from data.

Documentation

A* was described in the paper by Hart, Nilsson and Raphael. The exhibit implements the algorithm on a grid with movement in four directions and a cost of 1 per step.

Curatorial note: The maze is artificial. It does not represent a real robot, map or navigation system.