Pathfinding Visualizer
Pathfinding Algorithms
This pathfinding visualizer implements four popular grid-based search algorithms, each with unique exploration strategies.
Breadth-First Search (BFS)
Exploration Strategy: Explores all neighboring nodes at the current depth before moving deeper.
- Uses a queue data structure
- Guarantees the shortest path in unweighted grids
- Explores nodes level by level
// Key Implementation Details function bfs(grid, start, end): - Maintains a queue of nodes to explore - Tracks visited nodes to avoid revisiting - Builds path while exploring - Stops when end node is reached - Explores in 4 directions: Up, Down, Left, Right
Best for: Finding shortest paths in uniform-cost grids
Depth-First Search (DFS)
Exploration Strategy: Explores as deep as possible along each branch before backtracking.
- Uses a stack data structure
- Does not guarantee the shortest path
- Explores one path completely before trying alternatives
// Key Implementation Details function dfs(grid, start, end): - Uses a stack instead of a queue - Explores neighbors in reverse order - Tracks visited nodes - Builds path during exploration - Stops when end node is found
Best for: Exploring all possible paths, maze generation
Dijkstra's Algorithm
Exploration Strategy: Finds the shortest path by systematically exploring nodes with minimum distance.
- Uses a priority queue
- Assumes uniform cost for all moves (1 in this implementation)
- Tracks and updates minimum distances
// Key Implementation Details function dijkstra(grid, start, end): - Maintains distances to each node - Uses sorted priority queue - Explores neighbors with minimum distance - Uniform cost of 1 for all moves - Builds path during exploration
Best for: Finding shortest paths in uniform-cost grids
A* Search Algorithm
Exploration Strategy: Uses heuristics to guide search, making it more efficient than Dijkstra's.
- Uses Manhattan distance as heuristic
- Calculates f-score (g-score + heuristic)
- Prioritizes nodes closer to the goal
// Key Implementation Details function aStar(grid, start, end): - Uses Manhattan distance heuristic - Maintains g-scores and f-scores - Prioritizes nodes with lowest f-score - Builds path during exploration - More efficient path finding
Best for: Efficient pathfinding with estimated distance to goal
Grid Exploration Details: - 4-directional movement (Up, Down, Left, Right) - Avoids walls and out-of-bounds cells - Tracks visited nodes for visualization