A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

A* Search Algorithm

Graduate Depth 95 in the knowledge graph ☐ I know this ☆ Set as goal
17topics build on this
603prerequisites beneath it
See this on the map →
Breadth-First Search (BFS)Dijkstra's Algorithm+1 more→→Heuristic Search Functions
search graphs pathfinding heuristics

Core Idea

A* combines actual path cost with heuristic estimates of remaining cost to find optimal paths efficiently. It uses f(n) = g(n) + h(n), where g(n) is the cost to reach node n and h(n) estimates cost to goal. A* is complete and optimal when h(n) is admissible.

Explainer

You already know two graph search algorithms that A* builds on directly. Breadth-first search (BFS) explores nodes in order of their depth from the start — it finds the shortest path in terms of number of edges, but it ignores edge weights entirely. Dijkstra's algorithm fixes this by always expanding the node with the lowest accumulated cost g(n) — it finds the truly cheapest path, but it explores outward uniformly in all directions, wasting effort on paths heading away from the goal. A* combines the best of both worlds by adding a heuristic function h(n) that estimates how far node n is from the goal, directing the search toward promising areas of the graph.

The evaluation function f(n) = g(n) + h(n) is what makes A* work. Here g(n) is the actual cost of the cheapest known path from the start to node n (just like Dijkstra's), and h(n) is your best guess of the remaining cost from n to the goal. A* maintains a priority queue ordered by f(n) and always expands the node with the smallest f value. Think of it as answering the question: "Which unexplored node is on the most promising total path?" If h(n) = 0 for all nodes, A* degenerates into Dijkstra's algorithm. If g(n) = 0, it becomes a pure greedy best-first search that chases the heuristic without accounting for cost already spent.

The key property that guarantees A* finds the optimal path is admissibility: the heuristic must never overestimate the true cost to the goal. For pathfinding on a map, the straight-line (Euclidean) distance is admissible because you can never get somewhere faster than a straight line. Manhattan distance is admissible on a grid where you can only move in four directions. When h(n) is admissible, A* will never prematurely commit to a suboptimal path — it may explore a node with a slightly higher g(n) if the heuristic suggests the total path through it could still be cheaper. A stronger property, consistency (or monotonicity), requires that h(n) ≤ cost(n, n') + h(n') for every edge. Consistent heuristics guarantee that once A* expands a node, it has already found the optimal path to that node, eliminating the need to re-open closed nodes.

The practical performance of A* depends almost entirely on the quality of the heuristic. A tighter (closer to true cost) but still admissible heuristic prunes more of the search space, making A* dramatically faster. In the best case, a perfect heuristic leads A* straight to the goal along the optimal path with no wasted exploration. In the worst case (h = 0 everywhere), it examines every node Dijkstra's would. This is why designing good heuristics is the central challenge when applying A* — the algorithm itself is simple, but its effectiveness is only as good as the heuristic guiding it. A* is used extensively in game AI for pathfinding, in robotics for motion planning, and in any domain where you need optimal paths through weighted graphs and have domain knowledge to estimate remaining costs.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → Defining and Calling Functions → Functions: Decomposing Problems → Function Parameters and Argument Passing → Return Values → Variable Scope → Introduction to Classes → Objects and Instances → Methods and Attributes → Algorithm Design Basics → Tree Structure and Node Properties → Binary Trees → Tree Traversals → Depth-First Search (DFS) → Depth-First Search: Implementation and Applications → Topological Sort → Dynamic Programming → Longest Common Subsequence (LCS) Problem → Edit Distance: Levenshtein Distance and DP → 0/1 Knapsack Problem: Bounded Capacity DP → Greedy Algorithms → Activity Selection Problem Using Greedy Algorithms → Dijkstra's Algorithm → A* Search Algorithm

Longest path: 96 steps · 603 total prerequisite topics

Prerequisites (3)

Leads To (1)