Inferensys

Glossary

A* Algorithm

The A* algorithm is a graph traversal and path search algorithm that finds the least-cost path from a start node to a goal node using a best-first search guided by a heuristic function.
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.
PATHFINDING & SEARCH

What is the A* Algorithm?

The A* algorithm is a foundational graph traversal and path search method that efficiently finds the least-cost path between nodes. It is a cornerstone of task and motion planning in robotics and AI.

The A algorithm* is a best-first search algorithm that finds the lowest-cost path from a start node to a goal node by combining Dijkstra's algorithm-like certainty with a heuristic-guided direction. It evaluates nodes using a cost function, f(n) = g(n) + h(n), where g(n) is the exact cost from the start, and h(n) is an admissible heuristic estimating the cost to the goal. This balance ensures optimality and efficiency, making it superior to pure greedy or uninformed searches.

In robotics and task planning, A* operates on a discretized representation like a grid or graph, where nodes are states (e.g., robot configurations) and edges are valid actions. The heuristic, often the Euclidean or Manhattan distance, guides the search through the state space toward the goal. Its efficiency is critical for real-time applications like navigation and is a foundational component in hierarchical planners that decompose high-level tasks into feasible motion sequences.

PATH SEARCH FUNDAMENTALS

Key Features of the A* Algorithm

The A* algorithm is a cornerstone of pathfinding and graph traversal, combining the completeness of Dijkstra's algorithm with the efficiency of a best-first search via an informed heuristic.

01

Informed Best-First Search

A* is an informed search algorithm, meaning it uses a heuristic function to estimate the cost to the goal. This guides its exploration, making it far more efficient than uninformed searches like Breadth-First Search (BFS) or Depth-First Search (DFS). It expands the most promising node first, based on the sum of the cost to reach the node and the estimated cost to the goal.

  • Core Mechanism: It maintains a priority queue (the open set) sorted by the total estimated cost f(n) = g(n) + h(n).
  • Efficiency: By focusing search effort towards the goal, it typically evaluates far fewer nodes than Dijkstra's algorithm, which explores equally in all directions.
02

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

The algorithm's decision-making is governed by a cost function f(n) for each node n.

  • g(n) (Path Cost): The exact, known cost from the start node to node n. This accumulates real traversal costs (e.g., distance, time).
  • h(n) (Heuristic): An admissible heuristic function that estimates the cost from node n to the goal. Common heuristics include Euclidean distance (for flying distance) or Manhattan distance (for grid movement).
  • f(n) (Total Estimated Cost): The sum g(n) + h(n). This is the estimated total cost of the path from start to goal that goes through node n. The node with the lowest f(n) is always expanded next.
03

Admissible & Consistent Heuristics

For A* to be optimal (guarantee the shortest path), its heuristic h(n) must meet specific criteria.

  • Admissible Heuristic: The heuristic must never overestimate the true cost to reach the goal. It must be optimistic. h(n) ≤ h*(n) where h*(n) is the true cost.
  • Consistent (Monotonic) Heuristic: A stronger condition where the heuristic estimate from a node to the goal is less than or equal to the cost of moving to a successor plus the heuristic estimate from that successor. Formally: h(n) ≤ c(n, n') + h(n'). Consistency implies admissibility and ensures the algorithm finds the optimal path without needing to re-evaluate nodes.
  • Example: In a 2D grid, the Manhattan distance is admissible and consistent if the robot can only move up, down, left, or right.
04

Optimality and Completeness

A* provides strong theoretical guarantees under the right conditions.

  • Completeness: A* is complete on finite graphs with a finite branching factor. It will always find a solution if one exists, as it systematically explores all possible paths (guided by the heuristic).
  • Optimality: When using an admissible heuristic, A* is guaranteed to find the least-cost path from the start to the goal. This makes it the algorithm of choice for applications where optimality is critical, such as robotics navigation or game AI for strategic pathfinding.
  • Trade-off: The more accurate the heuristic (closer to the true cost without overestimating), the fewer nodes A* will expand, making it more efficient.
05

The Open and Closed Sets

A* manages its search frontier and explored nodes using two primary data structures.

  • Open Set (Frontier): Typically a priority queue (e.g., a min-heap) containing nodes scheduled to be evaluated. Nodes are ordered by their f(n) score. The node with the lowest f(n) is popped for expansion.
  • Closed Set (Explored): A set (e.g., a hash table) containing nodes that have already been expanded. This prevents the algorithm from re-evaluating nodes and entering infinite loops.
  • Process: When a node is expanded, it is moved from the open set to the closed set. Its neighbors are generated; if a neighbor is not in the closed set and has a better g(n) cost than a previous visit, it is added/updated in the open set.
06

Applications in Robotics & TAMP

In Task and Motion Planning (TAMP), A* is often used at the geometric or kinematic planning level.

  • Discretized State Spaces: The robot's configuration space (C-space) is discretized into a graph (a grid or lattice). A* searches this graph for a collision-free path.
  • Heuristic Design: Effective heuristics are crucial. For a mobile robot, Euclidean distance to the goal is common. For a manipulator, a heuristic might be the Euclidean distance of the end-effector.
  • Integration with High-Level Planning: A* solves the low-level motion planning or path planning subproblem. A high-level task planner (e.g., using HTNs or PDDL) might call A* repeatedly to check the feasibility of moving between different symbolic states.
  • Example: A high-level plan says "go to the kitchen." A* is used to compute the detailed, collision-free wheeled navigation path through the building.
COMPARISON

A* vs. Other Pathfinding Algorithms

A feature and performance comparison of the A* algorithm against other foundational pathfinding and graph search methods, highlighting trade-offs in completeness, optimality, and computational efficiency.

Algorithm Feature / MetricA* SearchDijkstra's AlgorithmGreedy Best-First SearchBreadth-First Search (BFS)

Core Search Strategy

Best-first search guided by f(n) = g(n) + h(n)

Uniform-cost search (expands lowest g(n))

Best-first search guided by h(n) only

FIFO queue; expands shallowest nodes first

Optimality (Finds least-cost path)

Completeness (Finds a path if one exists)

Heuristic Function Required

Time Complexity (Worst-case, with good heuristic)

O(b^d)

O((V+E) log V)

O(b^m)

O(b^d)

Space Complexity (Worst-case)

O(b^d)

O(V)

O(b^m)

O(b^d)

Primary Use Case in Robotics

Global path planning with a known map and admissible heuristic

Finding shortest paths in weighted graphs (e.g., network routing)

Quick, approximate planning where optimality is not critical

Finding shortest paths in unweighted graphs or exploring state space

Admissibility Requirement for Optimality

Heuristic must be admissible (never overestimates)

Suitability for High-Dimensional C-Spaces

Limited; suffers from the curse of dimensionality

Limited; suffers from the curse of dimensionality

Limited; suffers from the curse of dimensionality

Not suitable; exponential memory growth

A* ALGORITHM

Frequently Asked Questions

Essential questions and answers about the A* algorithm, a cornerstone of pathfinding and graph search used extensively in robotics, AI, and game development.

The A* (pronounced "A-star") algorithm is a graph traversal and path search algorithm that finds the least-cost path from a start node to a goal node by combining Dijkstra's Algorithm (which guarantees optimality) with a best-first search guided by a heuristic. It works by maintaining a priority queue of nodes to explore, ordered by a total estimated cost function: f(n) = g(n) + h(n). Here, g(n) is the exact, accumulated cost from the start node to the current node n, and h(n) is a heuristic function that estimates the cost from n to the goal. At each step, A* expands the node with the lowest f(n), effectively exploring the most promising paths first while guaranteeing an optimal solution if the heuristic is admissible (never overestimates the true cost).

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.