Inferensys

Glossary

A* Search

A* Search is a best-first graph traversal algorithm that finds the least-cost path from a start node to a goal node by combining the known cost to reach a node (g(n)) with a heuristic estimate of the remaining cost to the goal (h(n)).
Developer reviewing semantic search engine results on laptop, relevance scores visible, technical search demo.
HEURISTIC SEARCH ALGORITHM

What is A* Search?

A* (pronounced "A-star") is a foundational graph traversal and pathfinding algorithm that finds the least-cost path from a start node to a goal node by intelligently guiding its search using a heuristic.

A Search* is a best-first, informed search algorithm that finds the optimal path between nodes in a weighted graph. It operates 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 function estimating the cost from n to the goal. The algorithm efficiently explores the most promising paths first, balancing between the known cost and the estimated remaining cost.

For A* to guarantee an optimal solution, the heuristic h(n) must be admissible (never overestimates the true cost) and consistent. It is a cornerstone of automated planning systems and robotics, used in applications from GPS navigation to game AI. Its efficiency makes it superior to uninformed searches like Dijkstra's algorithm when a good heuristic is available, directly enabling efficient state-space search in agentic cognitive architectures.

AUTOMATED PLANNING SYSTEMS

Core Components of the A* Algorithm

A* is a best-first graph search algorithm that finds a least-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)). Its optimality and efficiency depend on the precise interaction of its core components.

01

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

The evaluation function f(n) is the core equation of A*, determining the priority of each node n during the search. It is the sum of two distinct costs:

  • g(n): The exact, known cost of the path from the start node to the current node n. This is the cumulative cost of all actions taken so far.
  • h(n): The heuristic function, which estimates the cost from node n to the goal node. This is an informed guess that guides the search. 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

The Heuristic Function h(n)

The heuristic function h(n) provides an estimate of the remaining cost to the goal. Its quality is critical to A*'s performance:

  • Admissible Heuristic: A heuristic that never overestimates the true remaining cost. Using an admissible heuristic guarantees that A* will find an optimal path (lowest total cost).
  • Consistent (Monotonic) Heuristic: A stronger condition where the estimated cost from a node to the goal is less than or equal to the cost of moving to a successor plus the estimate from that successor. Consistency ensures optimality and that nodes are never re-opened with a better cost.
  • Example Heuristics: For pathfinding on a grid, the Manhattan distance (sum of horizontal and vertical steps) or Euclidean distance (straight-line distance) are common admissible heuristics, assuming unit or direct movement costs.
03

Open and Closed Sets

A* maintains two primary data structures to manage the frontier of exploration and visited nodes:

  • Open Set (Priority Queue): This is typically a min-priority queue (e.g., a binary heap) containing nodes that have been discovered but not yet expanded. Nodes are ordered by their f(n) score. The node with the lowest f(n) is always selected for expansion next.
  • Closed Set: A set (e.g., a hash table) containing nodes that have already been expanded. This prevents the algorithm from revisiting and re-processing nodes, which is essential for efficiency. In consistent heuristic scenarios, a node is never re-opened, but the closed set is still used for cycle prevention. The algorithm iteratively moves nodes from the open set to the closed set as it expands them, generating their successors for potential addition to the open set.
04

Optimality and Completeness Guarantees

A* possesses strong formal guarantees under specific conditions:

  • Completeness: A* is complete on finite graphs with a finite branching factor, provided a solution exists. It will always find a path to the goal if one is reachable.
  • Optimality: A* is guaranteed to find a least-cost path (an optimal solution) if the heuristic function h(n) is admissible. If the heuristic is also consistent, A* is optimally efficient, meaning no other optimal algorithm using the same heuristic is guaranteed to expand fewer nodes.
  • Trade-off: A perfectly accurate heuristic (h(n) = true remaining cost) would lead A* directly to the goal. A heuristic of zero (h(n)=0) degrades A* to Dijkstra's Algorithm, which is still optimal but less efficient as it explores uniformly in all directions.
05

Relation to Other Search Algorithms

A* is a member of the best-first search family and generalizes several fundamental algorithms:

  • Dijkstra's Algorithm: A* with h(n) = 0. It finds the shortest path by exploring based solely on the known cost g(n) from the start.
  • Greedy Best-First Search: A search that uses only the heuristic h(n) for prioritization (f(n) = h(n)). It is fast but not optimal, as it ignores the cost incurred so far.
  • Uniform-Cost Search: Another name for Dijkstra's algorithm in the context of search problems, equivalent to A* with a zero heuristic.
  • Bidirectional Search: A performance optimization where two simultaneous A* searches run—one from the start and one from the goal—meeting in the middle. This can drastically reduce the number of nodes expanded in large state spaces.
06

Applications in Automated Planning & AI

While classic for pathfinding, A* is a general state-space search algorithm applicable to many AI planning problems:

  • Automated Planning: Searching through a graph of world states, where nodes are states and edges are actions. The heuristic estimates the cost from a given state to a goal state.
  • Puzzle Solving: For problems like the 8-puzzle or 15-puzzle, heuristics like the sum of Manhattan distances of tiles from their goal positions guide A* to a solution.
  • Game AI: Used for strategic pathfinding for non-player characters (NPCs) in video games and for high-level action planning in turn-based strategy games.
  • Robotics Motion Planning: Finding optimal collision-free paths for robot arms or mobile robots in configuration space, often using Euclidean distance as a heuristic.
ALGORITHM

How the A* Search Algorithm Works

A* (pronounced "A-star") is a foundational graph traversal and pathfinding algorithm used in automated planning and artificial intelligence to find an optimal path between nodes.

The A search algorithm* is a best-first, informed search algorithm that finds a least-cost path from a start node to a goal node. It operates 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 an open set of nodes to explore, prioritized by the lowest f(n), and a closed set of already evaluated nodes to avoid cycles.

For A* to guarantee an optimal solution, the heuristic h(n) must be admissible, meaning it never overestimates the true remaining cost. A common variant uses a consistent (or monotonic) heuristic, which ensures the estimated cost to the goal is always less than or equal to the cost to a successor plus the heuristic from that successor. This property guarantees that the first time A* expands a node, it has found the optimal path to it. The algorithm terminates when the goal node is selected for expansion, at which point the optimal path can be reconstructed by tracing parent pointers backward.

AUTOMATED PLANNING SYSTEMS

Practical Applications of A* Search

A* search is a cornerstone algorithm for optimal pathfinding and planning, combining the actual cost from the start with a heuristic estimate to the goal. Its efficiency and optimality guarantee make it indispensable across numerous technical domains.

02

Video Game AI and NPC Movement

A* is the industry-standard algorithm for non-player character (NPC) pathfinding in video games. It enables characters to navigate complex, dynamic terrains intelligently.

  • Real-time strategy (RTS) games use it for unit movement across varied terrain with different movement costs (e.g., grass vs. swamp).
  • Massively multiplayer online (MMO) games calculate paths for thousands of entities simultaneously.
  • Modern implementations use hierarchical pathfinding and jump point search (an A* optimization) for massive game worlds.
04

Logistics and Supply Chain Optimization

A* optimizes vehicle routing problems (VRP) and task sequencing in complex supply chains.

  • Delivery fleets: Calculates the most efficient multi-stop route for a truck, minimizing fuel cost and time while respecting delivery windows.
  • Air traffic control: Plans optimal flight corridors, considering weather and restricted airspace.
  • Manufacturing: Sequences robotic arm movements on an assembly line to minimize cycle time, where the graph represents possible arm joint configurations.
05

Natural Language Processing Parsing

In computational linguistics, A* is used for syntactic parsing—determining the grammatical structure of a sentence. The search space is a chart of possible parse tree fragments.

  • Each state is a partial parse, and the goal is a complete tree covering the sentence.
  • The cost g(n) is the negative log probability of the partial parse.
  • The heuristic h(n) estimates the best possible completion cost, allowing the algorithm to efficiently find the most probable parse according to a probabilistic context-free grammar (PCFG).
06

Integrated Circuit Design and PCB Routing

A* is critical in electronic design automation (EDA) for routing connections on chips and printed circuit boards (PCBs).

  • It finds wiring paths between millions of transistors or components, avoiding obstacles and minimizing wire length to reduce signal delay and cross-talk.
  • The search graph is a 3D grid representing different metal layers.
  • Costs incorporate electrical properties like capacitance and resistance. Admissible heuristics, such as Manhattan distance to the target pin, guarantee the shortest physical path is found, which is essential for performance and manufacturability.
FEATURE COMPARISON

A* Search vs. Other Search Algorithms

A comparison of key algorithmic properties for A* Search and other common search methods used in automated planning and pathfinding.

Algorithmic FeatureA* SearchUniform-Cost Search (Dijkstra's)Greedy Best-First SearchBreadth-First Search (BFS)

Primary Search Strategy

Best-first (cost + heuristic)

Best-first (cost only)

Best-first (heuristic only)

Breadth-first (level order)

Optimality Guarantee

Completeness Guarantee

Heuristic Requirement

Admissible (for optimality)

Not required

Required (any)

Not required

Typical Time Complexity

O(b^(d))

O(b^(1 + C*/ε))

O(b^(m))

O(b^(d))

Typical Space Complexity

O(b^(d))

O(b^(1 + C*/ε))

O(b^(m))

O(b^(d))

Primary Use Case

Optimal pathfinding with a good heuristic

Optimal pathfinding with no heuristic

Fast, suboptimal search with a heuristic

Finding the shallowest solution

A* SEARCH

Frequently Asked Questions

A* is a foundational algorithm for optimal pathfinding and planning. These questions address its core mechanics, applications, and relationship to other automated planning systems.

The A search algorithm* is a best-first, graph traversal and pathfinding algorithm that finds the least-cost path from a start node to a goal node. It works by combining two cost functions: g(n), the exact cost from the start node to the current node n, and h(n), a heuristic estimate of the cost from n to the goal. The algorithm prioritizes expanding nodes with the lowest total estimated cost f(n) = g(n) + h(n). It maintains an open set of nodes to explore and a closed set of already-explored nodes, systematically moving towards the goal while guaranteeing an optimal solution if the heuristic is admissible.

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.