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.
Glossary
A* Search

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.
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.
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.
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
nto the goal node. This is an informed guess that guides the search. The algorithm always expands the node with the lowestf(n)value first, balancing the certainty of the path taken with the promise of the path ahead.
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.
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 lowestf(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.
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.
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 costg(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.
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.
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.
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.
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.
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.
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).
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.
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 Feature | A* Search | Uniform-Cost Search (Dijkstra's) | Greedy Best-First Search | Breadth-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 |
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
A* Search is a foundational algorithm within automated planning. The following concepts are essential for understanding its role, alternatives, and extensions in building intelligent, goal-directed systems.
Heuristic Function
A heuristic function, denoted as h(n), provides an estimate of the cost from a given node n to the goal. In A*, this estimate guides the search toward promising paths. Key properties include:
- Admissibility: A heuristic is admissible if it never overestimates the true cost to the goal, guaranteeing A*'s optimality.
- Consistency (Monotonicity): A heuristic is consistent if the estimated cost from a node to the goal is not greater than the step cost to a successor plus the estimated cost from that successor. This ensures efficient graph search. Example: In pathfinding on a grid, the Manhattan distance is a common admissible heuristic when movement is restricted to four directions.
Best-First Search
Best-First Search is a family of graph search algorithms that expand the most promising node based on an evaluation function f(n). A* is a specific, optimal instance of best-first search where f(n) = g(n) + h(n). Other variants include:
- Greedy Best-First Search: Uses f(n) = h(n). It is fast but not optimal, as it pursues the heuristic target without considering the cost incurred so far.
- Beam Search: A bounded variant that only keeps the top k most promising nodes at each level, trading completeness for memory efficiency. These algorithms form the core of informed search strategies in planning.
Dijkstra's Algorithm
Dijkstra's Algorithm finds the shortest path from a start node to all other nodes in a graph with non-negative edge weights. It is a fundamental predecessor to A*.
- Relationship to A*: Dijkstra's algorithm can be seen as a special case of A* where the heuristic function h(n) is uniformly zero. This makes it uniform-cost search.
- Use Case: Optimal when no domain-specific heuristic is available. It guarantees the shortest path but may explore a larger portion of the state space than A* with a good heuristic.
- Mechanism: It uses a priority queue ordered by the cumulative cost g(n) from the start.
Monte Carlo Tree Search (MCTS)
Monte Carlo Tree Search (MCTS) is a heuristic search algorithm for optimal decision-making in sequential problems, especially in large, stochastic environments like games. It contrasts with A*:
- Probabilistic vs. Deterministic: MCTS uses random sampling (rollouts) to estimate node values, while A* uses a deterministic heuristic.
- Balancing Act: MCTS explicitly balances exploration of uncertain paths and exploitation of known good paths using policies like UCT (Upper Confidence bounds applied to Trees).
- Application: Dominates in domains with high branching factors and complex reward structures where constructing an accurate heuristic for A* is difficult, such as Go or real-time strategy games.
State Space
The state space is the set of all possible configurations or situations that a planning problem can be in. A* searches this space.
- Representation: Formally, a state is defined by the values of a set of variables or logical propositions (e.g., in STRIPS/PDDL).
- Graph Structure: The state space forms a graph where nodes are states and edges are actions that transition between states.
- Challenge: The state space is often astronomically large or infinite (combinatorial explosion). A*'s efficiency depends on a heuristic that effectively prunes this vast space, guiding the search through the most relevant regions.
Admissible Heuristic
An admissible heuristic is one that never overestimates the true cost to reach the goal from any given node. This property is critical for A*'s optimality guarantee.
- Optimality Proof: If h(n) is admissible, A* is guaranteed to return a least-cost path.
- Trade-off: The closer h(n) is to the true cost (without exceeding it), the more efficient A* becomes. A heuristic that is exactly the true cost would lead A* directly to the goal without exploring unnecessary nodes.
- Common Examples: Straight-line distance for pathfinding in Euclidean space (never longer than the actual road distance). The max heuristic in planning, which takes the maximum cost of achieving individual subgoals, is also admissible.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us