Search⌘ K
AI Features

Cost vs. Distance

Discover how to compare cost and distance in maze traversal by adapting Dijkstra's algorithm to handle weighted paths. Learn why longer paths may be more optimal when obstacles like lava add expense, and understand the importance of processing cells based on lowest cost rather than shortest distance.

Comparing cost with distance

Imagine traversing a maze, and we come to a branch in the passage. In the illustration below, both paths loop around and meet up again a short distance later, but the passage to the left is blocked by a pool of molten lava. ...