Graph Theory & Pathfinding Visualizer
Explore, step through, and analyze classic graph search algorithms (A*, Dijkstra, BFS, DFS, Greedy BFS) on dynamic 2D grid topologies with obstacles, weighted terrain, and procedural mazes.
Shortest-Path & Graph Search Complexity Matrix
| Algorithm | Weighted Graphs? | Guaranteed Shortest? | Time Complexity (Worst) | Space Complexity | Primary Data Structure |
|---|---|---|---|---|---|
| A* Search | Yes | Yes (Admissible h) | O(E + V log V) | O(V) | Min-Priority Queue (Binary Heap) |
| Dijkstra's Algorithm | Yes | Yes (Non-negative weights) | O(E + V log V) | O(V) | Min-Priority Queue (Binary Heap) |
| Breadth-First Search (BFS) | No (Uniform only) | Yes (Fewest Edges) | O(V + E) | O(V) | FIFO Queue (First-In First-Out) |
| Depth-First Search (DFS) | No | No (Path can be poor) | O(V + E) | O(V) (Tree Depth) | LIFO Stack (Call Stack) |
| Greedy Best-First Search | Yes | No (Can get trapped) | O(V log V) | O(V) | Min-Priority Queue (Keyed on h) |
| Bidirectional BFS | No (Uniform only) | Yes | O(bd/2) | O(bd/2) | Dual FIFO Queues |
Heuristic Metrics & Mathematical Admissibility
1. Manhattan Distance (L1 Norm)
Standard distance metric for 4-directional grid graphs where diagonal traversal is forbidden (taxicab geometry). It computes the minimal orthogonal moves required to reach the target.
2. Euclidean Distance (L2 Norm)
Straight-line ruler distance in continuous Euclidean space. Always admissible because straight-line distance is the shortest possible path between any two points.
3. Chebyshev Distance (L∞ Norm)
Optimal metric for 8-directional movement (King's movement in chess), where orthogonal and diagonal steps each cost 1 unit of traversal.
Admissibility & Consistency Conditions:
- Admissibility: An estimated heuristic h(n) is admissible if it never overestimates the true minimal cost h*(n) to reach the goal: h(n) ≤ h*(n). This guarantees that A* never bypasses an optimal path.
- Consistency (Monotonicity): For every node u and successor v connected by edge weight c(u, v): h(u) ≤ c(u, v) + h(v). If consistent, nodes expanded by A* never need to be re-opened in the closed set.
Graph Theory & Edge Relaxation Fundamentals
Grid as an Implicit Graph G = (V, E)
In computer science, a 2D tile grid represents an implicit planar graph:
- Vertices V: Every cell (x, y) represents a vertex with coordinates and state.
- Edges E: Connections exist between adjacent cells unless blocked by wall obstacles.
- Edge Weights w(u, v): Normal floor tiles have weight w = 1; mud/swamp tiles have weight w = 5.
The Edge Relaxation Principle
The fundamental building block of Dijkstra's algorithm and A*:
dist[v] = dist[u] + weight(u, v);
parent[v] = u;
}
By relaxing edges and always extracting the minimum-cost node from a Priority Queue, Dijkstra's algorithm iteratively discovers the true shortest path to every reachable vertex.