What is the A* pathfinding algorithm?
Answer
A* (A-star) is an informed search algorithm that finds the shortest path by combining Dijkstra's systematic search with a heuristic to guide exploration toward the goal. Unlike Dijkstra (which explores all directions equally), A* prioritizes nodes that appear closer to the goal. f(n) = g(n) + h(n): g(n) = actual cost from start to node n; h(n) = heuristic estimate of cost from n to goal; f(n) = estimated total cost through n. Priority queue ordered by f(n). Algorithm: same as Dijkstra but use f(n) for priority; expand node with lowest f(n); update neighbors with new g-values; stop when goal is dequeued. Admissibility: heuristic h must never overestimate the true cost — then A* is guaranteed optimal. Consistency: h(n) ≤ cost(n, n') + h(n') for all edges. Common heuristics: Manhattan distance for grid (no diagonals); Euclidean distance for geometric graphs; Chebyshev distance for grids with diagonal moves. Time: O(E) best case, O(b^d) worst where b = branching factor, d = depth. With perfect heuristic: O(d). Applications: (1) GPS navigation; (2) Game AI pathfinding (RTS, RPGs); (3) Robotics motion planning; (4) Puzzle solving (15-puzzle, sliding puzzles). Bidirectional A*: search from both start and goal — faster in practice.
Previous
What is amortized analysis?
Next
What is Tarjan's algorithm for finding Strongly Connected Components?