AlgoFrames

Compare expansions with Dijkstra

Standard · Trace the algorithm · about 6 min

Dijkstra and A* both search from S to T on the same grid. Watch each search expand cells, then type how many cells each one expanded, T included.

Example 1

Input:

{"rows":5,"cols":6,"walls":[[0,3],[1,3],[2,3]],"start":[1,0],"goal":[1,5]}

Output:

[26,15]

Dijkstra expands 26 cells and A* 15.

Constraints

  • Moves go up, right, down and left. Each costs 1.
  • A* uses the Manhattan distance to T. Ties go to the cell closer to T.

Learn the idea first: A* search with heuristics, a visual lesson.

More A* search with heuristics problems