What is the A* pathfinding algorithm?

Why Interviewers Ask This

Senior Data Structures & Algorithms engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.

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.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last Data Structures & Algorithms project, I used this when...' immediately makes your answer more credible and memorable.