โ† Wiki Index / Computation & Algorithms / A* Search Algorithm
๐Ÿ’ป Computation & Algorithms

A* Search Algorithm

The A* search algorithm is an informed best-first graph traversal and pathfinding procedure that combines accumulated path cost g(n) with an admissible heuristic estimate h(n) to find provably minimum-cost paths.

A* search algorithm (pronounced "A-star") is an informed best-first graph traversal and heuristic pathfinding algorithm within computation and algorithms that computes a minimum-cost path from a start state s to a goal state t in a weighted state-space graph G = (V, E). Formulated in 1968 by Peter E. Hart, Nils J. Nilsson, and Bertram Raphael at the Stanford Research Institute to guide the mobile robot Shakey, the algorithm extends Dijkstra's algorithm by ordering its priority-queue frontier according to an evaluation function f(n) = g(n) + h(n), where g(n) is the accumulated path cost from s to node n and h(n) is a heuristic lower-bound estimate of the remaining cost from n to t.

Within computational complexity theory and artificial intelligence, Hart, Nilsson, and Raphael proved that whenever the heuristic h(n) is admissible (never overestimating the true remaining cost h*(n)) and consistent (satisfying the triangle inequality across every edge), A* is both complete and optimally efficient: no other deterministic search algorithm with access to the same heuristic can guarantee finding an optimal path while expanding fewer state-space nodes up to tie-breaking. Consequently, A* underpins autonomous robotics motion planning, heuristic multiple sequence alignment over dynamic programming lattices, protein side-chain rotamer packing, and seed-chain genomic read alignment using trie and suffix array indexes.

Mathematical Formulation and Heuristic Optimality Conditions

The Evaluation Function f(n) = g(n) + h(n)

Let G = (V, E, w) be a locally finite directed graph with step costs w(u, v) โ‰ฅ ฮต > 0, start vertex s โˆˆ V, and goal set T โІ V. Let g*(n) be the true shortest-path cost from s to n, h*(n) the true shortest-path cost from n to T, and C* = h*(s) the optimal solution cost. A* maintains a priority queue (OPEN) of frontier nodes and a set (CLOSED) of expanded nodes, tracking the best known cost g(n) from s to n and ordering OPEN by:

f(n) = g(n) + h(n)

At each step, A* extracts n โˆˆ OPEN minimizing f(n). If n โˆˆ T, the search terminates and reconstructs the optimal path. Otherwise, n enters CLOSED and each neighbor m is relaxed: if g(n) + w(n, m) < g(m), update g(m), set f(m) โ† g(m) + h(m), and insert or update m in OPEN.

Admissibility vs. Consistency (Monotonicity)

Two mathematical properties of h : V โ†’ โ„โ‰ฅ0 govern optimality and node-expansion complexity:

  1. Admissibility: h never overestimates the true remaining cost:
0 โ‰ค h(n) โ‰ค h*(n) for all n โˆˆ V, with h(t) = 0 for t โˆˆ T

Under admissibility, A* returns an optimal solution C* because any suboptimal goal tโ€ฒ has f(tโ€ฒ) = g(tโ€ฒ) > C*, whereas a frontier node n on an optimal path satisfies f(n) = g*(n) + h(n) โ‰ค C* and is extracted first.

  1. Consistency (Monotonicity): For every edge (u, v) โˆˆ E, h satisfies the triangle inequality:
h(u) โ‰ค w(u, v) + h(v) and h(t) = 0 for t โˆˆ T

Every consistent heuristic is admissible, and f(v) = g(u) + w(u, v) + h(v) โ‰ฅ g(u) + h(u) = f(u) is non-decreasing along any path.

Equivalence to Dijkstra's Algorithm via Potential Reweighting

When h is consistent, the reduced weight wh(u, v) = w(u, v) โˆ’ h(u) + h(v) โ‰ฅ 0 is non-negative on every edge (mirroring Johnson's reweighting in the Bellman-Ford algorithm) and telescopes along any path p from s to n as wh(p) = f(n) โˆ’ h(s). Executing A* with consistent h on (G, w) is therefore identical to executing Dijkstra's algorithm on (G, wh), so the first extraction of any node u achieves g(u) = g*(u) without reopening CLOSED.

Heuristic Regime / Search VariantHeuristic ConditionSolution OptimalityCLOSED Reopening RequiredTypical Complexity / Memory Profile
Uniform-Cost Search (Dijkstra)h(n) = 0 everywhereOptimal (C*)NeverExpands all nodes with g*(n) < C*
A* with Consistent Heuristich(u) โ‰ค w(u, v) + h(v)Optimal (C*)Never (O(|V|) expansions)Expands all nodes with f(n) < C*
A* with Admissible Inconsistent hh(n) โ‰ค h*(n) onlyOptimal (C*)Yes (if graph search)Can require multiple re-expansions
Weighted A* (Pohl 1970, ฮต > 1)fฮต(n) = g(n) + ฮตยทh(n)Bounded suboptimal (โ‰ค ฮตยทC*)OptionalFewer node expansions; faster convergence
Iterative Deepening A* (IDA*)Consistent h(n)Optimal (C*)Implicit (depth-first)O(d) linear memory; suited for combinatorial trees

Dominance, Geometric Metrics, and Memory-Bounded Variants

Heuristic Dominance and Spatial Metrics

Given two consistent heuristics h1 and h2, h2 dominates h1 if h1(n) โ‰ค h2(n) โ‰ค h*(n) for all n โˆˆ V. Because A* must expand every node satisfying f(n) = g*(n) + h(n) < C*, a dominating heuristic expands a subset of the nodes expanded by h1. Moreover, the pointwise maximum hmax(n) = max(h1(n), h2(n)) of two admissible heuristics remains admissible and dominates both. On spatial grids, Manhattan (L1) distance |ฮ”x| + |ฮ”y| is consistent on 4-neighbor orthogonal grids, Octile distance max(|ฮ”x|, |ฮ”y|) + (โˆš2 โˆ’ 1)ยทmin(|ฮ”x|, |ฮ”y|) is consistent on 8-neighbor grids, and Euclidean (L2) distance โˆš(ฮ”x2 + ฮ”y2) is consistent in any-angle continuous spaces.

To overcome the memory footprint of storing OPEN and CLOSED in large state spaces, Richard Korf's Iterative Deepening A* (IDA*, 1985) executes depth-first searches pruned whenever f(n) > ฯ„, advancing ฯ„ in each pass to the minimum f-value that exceeded the prior threshold and reducing space complexity to O(d).

Applications in Bioinformatics and Robotics

In computational biology, finding an optimal multiple sequence alignment (MSA) of k sequences of length L reduces to finding a shortest path across a k-dimensional dynamic programming hypercube of Lk vertices. Carrilloโ€“Lipman A* MSA engines evaluate an admissible sum-of-pairs heuristic h(n) by summing precomputed pairwise alignment scores over all (k choose 2) unaligned suffixes, pruning over 99% of the hypercube while guaranteeing the global optimum. In pairwise long-read genomics, seed-heuristic A* aligners (A*PA, Groot Koerkamp & Ivanov, 2024) combine k-mer seed matches with match pruning to align megabase sequences in near-linear empirical time.

Frequently Asked Questions

What happens if the heuristic h(n) overestimates the true cost to the goal?

When h(n) > h*(n) (an inadmissible heuristic), A* is no longer guaranteed to return a minimum-cost path because a node on the optimal path can be assigned an inflated f-value and remain unexpanded in OPEN when a suboptimal goal is popped. However, if h(n) โ‰ค ฮตยทh*(n) for a constant ฮต > 1 (Weighted A*), the returned solution cost is bounded within ฮตยทC*.

Why is consistency stronger than admissibility for graph search?

An admissible heuristic that violates consistency can drop sharply across an edge (u, v), causing f(v) < f(u). A node v may then be expanded first along a suboptimal path and placed into CLOSED; when the shorter path to v arrives later, A* must reopen v and propagate cost reductions to its descendants, which in pathological graphs can trigger ฮฉ(2|V|) re-expansions.

References

  1. Hart, P. E., Nilsson, N. J., & Raphael, B. (1968). "A formal basis for the heuristic determination of minimum cost paths." IEEE Transactions on Systems Science and Cybernetics, 4(2), 100โ€“107. https://doi.org/10.1109/TSSC.1968.300136
  2. Dechter, R., & Pearl, J. (1985). "Generalized best-first search strategies and the optimality of A*." Journal of the ACM, 32(3), 505โ€“536. https://doi.org/10.1145/3828.3830
  3. Korf, R. E. (1985). "Depth-first iterative-deepening: An optimal admissible tree search." Artificial Intelligence, 27(1), 97โ€“109. https://doi.org/10.1016/0004-3702(85)90084-090084-0)
  4. Goldberg, A. V., & Harrelson, C. (2005). "Computing the shortest path: A* search meets graph theory." Proceedings of the 16th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), 156โ€“165. https://doi.org/10.5555/1070432.1070455
  5. Groot Koerkamp, R., & Ivanov, P. (2024). "Exact global alignment using A* with seed heuristic and match pruning." Bioinformatics, 40(Supplement_1), i202โ€“i211. https://doi.org/10.1093/bioinformatics/btae253
๐Ÿงฌ Support Open Science
Explore interactive science games on LowKey Games or browse scientific apparel & accessories in the CRV Science Shop.
๐Ÿ’ก Spot an inaccuracy or have primary literature to expand this article?
Submit a citation or revision note using your shared CRV Science / LowKey Games profile ID.
Suggest Revision