A* Heuristic Search
A shortest-path algorithm that, unlike Dijkstra's blind expansion outward, uses an estimate of remaining distance to explore in the direction of the goal first, often reaching the answer after examining far fewer nodes.
Prerequisites: Dijkstra's Shortest Paths
Dijkstra's algorithm finds the shortest path by expanding outward from the start node in every direction, always processing whichever unvisited node currently has the smallest known distance — it's guaranteed correct but explores nodes that have nothing to do with where you're actually headed. A* fixes this by adding a heuristic: an estimate of the remaining distance from any node to the goal. Instead of ranking nodes purely by distance-so-far , A* ranks them by — cost already paid plus estimated cost still to come — so it prioritizes nodes that look like they're on a promising path toward the destination, not just nodes that are cheap to reach so far.
The one condition that keeps A* correct is that the heuristic must be admissible: it must never overestimate the true remaining distance. A classic example is searching a grid where the heuristic is straight-line (Euclidean) distance to the goal — it's guaranteed to underestimate any real path that has to navigate around obstacles, so it's admissible, and A* using it is guaranteed to still find the true shortest path, just typically after visiting far fewer nodes than Dijkstra would. If the heuristic ever overestimates, A* can return a path that looks optimal but isn't.
Quant uses show up less in literal maps and more in state-space search: routing an order through a sequence of venues to minimize total cost, where remaining-cost-to-completion can be estimated from average spreads, or searching a tree of possible portfolio rebalancing trades toward a target allocation.
A* is Dijkstra's algorithm plus a heuristic estimate of remaining distance to the goal, letting it search toward the destination instead of blindly outward — it stays exactly as correct as Dijkstra as long as the heuristic never overestimates the true remaining cost.
Practice in interviews
Further reading
- Hart, Nilsson and Raphael, 'A Formal Basis for the Heuristic Determination of Minimum Cost Paths'
- Cormen et al., Introduction to Algorithms, ch. 24