Inferensys

Glossary

A* Search

A* Search is a best-first graph traversal and pathfinding algorithm that finds the lowest-cost path from a start node to a goal node by combining the cost to reach the node (g(n)) with a heuristic estimate of the cost to the goal (h(n)).
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
HEURISTIC SEARCH ALGORITHM

What is A* Search?

A* Search is a foundational and optimal pathfinding algorithm in artificial intelligence and computer science, renowned for its efficiency in navigating complex state spaces.

A Search* is a best-first graph traversal and pathfinding algorithm that finds the lowest-cost path from a start node to a goal node. It achieves optimal efficiency by combining the actual cost to reach a node, g(n), with a heuristic estimate of the remaining cost to the goal, h(n), to form a priority score: f(n) = g(n) + h(n). The algorithm always expands the node with the lowest f(n) score from an open set (frontier), moving it to a closed set once explored. For A* to guarantee an optimal solution, the heuristic h(n) must be admissible (never overestimates the true cost) and consistent (obeys the triangle inequality).

The algorithm's power lies in its informed guidance; a well-designed heuristic focuses the search, dramatically reducing the number of nodes explored compared to uninformed methods like Dijkstra's Algorithm or Breadth-First Search. It is a cornerstone in automated planning systems and agentic cognitive architectures, where agents must navigate large decision spaces under computational constraints. Variants like Iterative Deepening A (IDA)** address its memory usage for very large graphs. In practice, A* is ubiquitous in applications from video game AI and robotics navigation to network routing and puzzle solving.

ALGORITHM MECHANICS

Key Properties of A* Search

A* Search is distinguished by its use of a cost function f(n) = g(n) + h(n) to guide exploration. Its optimality and efficiency depend on specific mathematical properties of its components.

01

The Evaluation Function f(n)

The core mechanism of A* is the evaluation function f(n) = g(n) + h(n). This function determines the priority of nodes in the open set (frontier).

  • g(n) is the exact, known cost from the start node to node n.
  • h(n) is the heuristic function, estimating the cost from n to the goal.
  • The algorithm always expands the node with the lowest f(n) value first, balancing the certainty of the path taken with the promise of the path ahead.
02

Admissibility & Optimality Guarantee

A* is guaranteed to find a cost-optimal path if its heuristic function h(n) is admissible. An admissible heuristic never overestimates the true cost to reach the goal. For example, in pathfinding on a grid, the Manhattan distance is admissible if movement is only allowed horizontally and vertically.

If h(n) is admissible, A* is optimally efficient for a given heuristic—no other optimal algorithm using the same heuristic is guaranteed to expand fewer nodes.

03

Consistency (Monotonicity)

A stronger property than admissibility is consistency (or monotonicity). A heuristic is consistent if for every node n and its successor n', the estimated cost satisfies the triangle inequality: h(n) ≤ cost(n, n') + h(n'). This also means h(goal) = 0.

A consistent heuristic guarantees that A* finds an optimal path without ever needing to re-expand a node from the closed set, making the algorithm more efficient. All consistent heuristics are admissible, but not all admissible heuristics are consistent.

04

Completeness

A* is complete on finite graphs with non-negative edge costs and a reasonable branching factor. This means it will always find a solution if one exists. Its completeness stems from its systematic exploration, similar to Uniform-Cost Search, but guided by the heuristic to improve speed.

If no path exists, A* will exhaust the reachable state space and terminate, reporting failure.

05

Time & Space Complexity

The worst-case time and space complexity of A* is O(b^d), where b is the branching factor and d is the depth of the optimal solution. This is exponential, as it may need to explore most of the search space.

In practice, a good heuristic dramatically reduces the effective branching factor, pruning large parts of the tree. The primary memory constraint is the open set (typically a priority queue) and the closed set (for tracking visited nodes), which can grow large for complex problems.

06

Comparison to Related Algorithms

A* occupies a specific point in the search algorithm design space:

  • vs. Greedy Best-First Search: Uses only h(n). Faster but not optimal.
  • vs. Uniform-Cost Search (Dijkstra's): Uses only g(n). Optimal but explores uniformly in all directions.
  • vs. IDA*: Uses iterative deepening with an f-cost threshold. Memory-efficient but can suffer from overhead in state regeneration.

A*'s balance of g(n) and h(n) makes it the de facto standard for informed pathfinding and graph traversal where an informative heuristic is available.

A* SEARCH

Frequently Asked Questions

A* Search is a foundational algorithm for optimal pathfinding and graph traversal, critical for autonomous agent navigation and planning. These FAQs address its core mechanics, applications, and trade-offs for engineers.

A* Search is a best-first graph traversal and pathfinding algorithm that finds the lowest-cost path from a start node to a goal node. It works by evaluating nodes using a cost function f(n) = g(n) + h(n), where g(n) is the exact cost from the start node to node n, and h(n) is a heuristic estimate of the cost from n to the goal. The algorithm maintains a priority queue (open set) of nodes to explore, always expanding the node with the lowest f(n) first. It guarantees an optimal solution if the heuristic h(n) is admissible (never overestimates the true cost) and the graph is finite.

Key Steps:

  1. Add the start node to the open set with f(start) = h(start).
  2. While the open set is not empty:
    • Pop the node with the lowest f(n).
    • If it is the goal, reconstruct and return the path.
    • Generate the node's successors.
    • For each successor, calculate its g, h, and f scores.
    • If the successor is new or a better path to it is found, update its scores and add it to the open set.
  3. If the open set empties, no path exists.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.