No Login Data Private Local Save

Pathfinding Visualizer - Online A*, Dijkstra & BFS Grid

16
0
0
0
40ms
Visited: 0 Path length: 0 Path cost: 0 Time: 0ms Ready
Start End Wall Weight (cost 5) Visited Path Searching

Frequently Asked Questions

BFS (Breadth-First Search) explores nodes layer by layer using a simple queue. It finds the shortest path in terms of number of steps but ignores edge weights. Dijkstra's algorithm uses a priority queue and considers edge weights to find the path with minimum total cost. A* (A-star) enhances Dijkstra by adding a heuristic function (e.g., Manhattan distance to the goal) that guides the search toward the target, making it significantly faster in practice. In unweighted grids, all three find optimal paths, but A* typically explores far fewer nodes.

This visualizer uses the Manhattan distance heuristic: h(n) = |x₁ - x₂| + |y₁ - y₂|. It calculates the sum of absolute horizontal and vertical distances between a node and the goal. Manhattan distance is admissible (never overestimates) and consistent for grid-based pathfinding where movement is restricted to 4 directions (up, down, left, right), guaranteeing that A* finds the optimal path.

Weight nodes simulate terrain with higher traversal cost (e.g., mud, rough terrain, or traffic). A regular step costs 1, while stepping through a weight node costs 5. BFS ignores these weights entirely, always finding the path with the fewest steps. Dijkstra and A* account for weights and will route around high-cost areas if a cheaper alternative exists. This demonstrates why weighted algorithms are essential for realistic pathfinding scenarios like GPS navigation.

Yes! Click and drag the start node (green) or end node (red) to reposition them anywhere on the grid. You can also use the mode buttons to place walls or weights by clicking on empty cells, or use the eraser mode to remove obstacles. All previous search results are automatically cleared when you modify the grid.

Pathfinding algorithms power countless technologies: GPS navigation systems (Dijkstra/A* for route planning), video game AI (NPC movement and enemy pathfinding), robotics (autonomous navigation and obstacle avoidance), network routing (OSPF and BGP protocols), DNA sequencing, and puzzle solving. A* is particularly popular in game development due to its speed and optimality guarantees.

BFS treats all traversable cells equally — it only counts the number of steps, not the cost of each step. A path through 3 weight cells (cost: 3×5=15) has fewer steps than a path around them with 8 regular cells (cost: 8×1=8). BFS will choose the 3-step path despite it being more "expensive." Dijkstra and A* correctly identify the 8-step绕过路径 as cheaper, demonstrating why weighted algorithms matter.