A star search explained in plain terms means understanding how a good guess can make a shortest-path search dramatically faster. The central question is why Dijkstra’s algorithm explores in every direction when the destination is known, and the answer is that it does not have to: A star search adds a heuristic, an informed estimate of the distance remaining, and steers the search toward the goal.
A star search is a pathfinding algorithm that combines the distance travelled so far with a heuristic estimate of the distance still to go, expanding the most promising node first. When the heuristic never overestimates the true remaining distance, the algorithm is guaranteed to find the shortest path, and it usually does so while exploring far fewer nodes than Dijkstra’s algorithm.
The idea is one of those rare improvements that is both simple and profound: a little knowledge about direction saves a lot of wasted work. This article explains how A star search works, how it compares with Dijkstra’s algorithm, and where it is used.
Key takeaways
- A star search adds a heuristic estimate to Dijkstra’s algorithm.
- It expands the node with the lowest combined cost first.
- An admissible heuristic guarantees the shortest path is found.
- It explores far fewer nodes than Dijkstra for a single destination.
- It powers game pathfinding, robotics, and route planning.
What A star search is
A star search works on the same weighted graphs as Dijkstra’s algorithm, but it scores every node with two numbers instead of one. The first, usually called g, is the cost of the path from the start to the node, and the second, usually called h, is the heuristic estimate of the cost from the node to the goal. The algorithm always expands the node with the lowest sum of the two, which balances the cost already paid against the promise of the route ahead.
The heuristic is the heart of the algorithm. On a map, the straight-line distance to the goal is a natural choice, because no road can be shorter than the crow flies. On a grid, the Manhattan distance, the sum of the horizontal and vertical gaps, plays the same role. The only requirement for a guarantee is admissibility: the heuristic must never overestimate the true remaining cost, because an overestimate could make the algorithm dismiss the genuinely best route.
When the heuristic is zero everywhere, A star search becomes Dijkstra’s algorithm exactly, exploring in all directions with no sense of where the goal lies. When the heuristic is perfect, the algorithm walks straight to the goal without a single wasted step. Real heuristics sit between those extremes, and the better the estimate, the fewer nodes the search explores. Our guide to graph databases explains how the networks these algorithms run on are stored.
How A star search runs, step by step
Imagine a game character crossing a map to reach a treasure chest. The algorithm starts with the character’s position in a priority queue scored by the sum of distance travelled and estimated distance remaining, then repeatedly takes the most promising position, marks it explored, and adds its neighbours to the queue with their own scores. Positions heading toward the chest score well, because their heuristic is small, while positions heading away score badly, so the search leans toward the goal from the very first step.
The search keeps the best known cost to reach every node it has seen, just as Dijkstra’s algorithm does, and it updates that cost whenever a cheaper route to a node is found. A neighbour reached through a long detour gets a poor score and waits in the queue, while a neighbour reached by a direct road gets a good score and is expanded soon. The queue therefore acts like a frontier that bulges toward the destination rather than spreading evenly.
The search stops the moment the goal is removed from the queue, not when it is first discovered. That distinction matters, because a node is only settled when its score is the lowest in the queue, and at that point no other route could possibly beat it. The path is then recovered by following parent pointers back from the goal to the start, the same bookkeeping Dijkstra’s algorithm uses.
A concrete example shows the saving. On a large open grid, Dijkstra’s algorithm expands a growing circle of nodes in every direction, while A star search with a straight-line heuristic expands a narrow ellipse aimed at the goal. On a map with a million nodes, the difference can be tenfold or more, which is why the algorithm dominates any application where the destination is known in advance.

A star search versus Dijkstra’s algorithm
The comparison between A star search and Dijkstra’s algorithm is really a question about what is known before the search begins. If the destination is known and a decent heuristic exists, A star search wins on speed, and if the destination is unknown or every node is a destination, Dijkstra’s algorithm is the right tool. Neither is better in general, because they answer different questions.
The table below sets out the main contrasts between the leading approaches.
| Aspect | A star search | Dijkstra’s algorithm | Breadth-first search |
|---|---|---|---|
| Needs a destination | Yes, one specific goal | No, finds all distances | No, finds all distances |
| Guidance | Heuristic estimate of what remains | None, explores evenly | None, explores evenly |
| Nodes explored | Few, aimed at the goal | Many, in all directions | Many, in all directions |
| Shortest path guarantee | Yes, with an admissible heuristic | Yes, always | Yes, for equal weights |
| Best for | Single route with a good guess | All destinations at once | Unweighted grids and mazes |
The practical result is that A star search is the default for games, robotics, and single-route planning, while Dijkstra’s algorithm is the default for routing tables and maps that serve many destinations.
Where A star search is used
Video games are the most famous home of A star search. Every unit in a strategy game, every non-player character finding its way through a dungeon, and every vehicle in a city builder is running the algorithm dozens of times a second. The heuristic is usually the straight-line or grid distance, and the result is movement that looks intelligent without costing much processor time.
Robotics uses A star search for navigation in warehouses, hospitals, and homes. A robot planning a path between shelves needs to avoid obstacles and minimise travel time, and the algorithm’s ability to aim at the goal keeps the plan fast enough to recompute whenever the world changes. Our guide to knowledge graphs explains how machines represent the world they navigate.
Route planning in mapping services uses A star search and its descendants for point-to-point directions. The heuristic is often the travel time at motorway speed, which never overestimates the true time, and the search therefore finds the fastest route while skipping most of the map. Contraction hierarchies and other optimisations build on the same idea for continental-scale networks.
Puzzle solving uses A star search whenever a good heuristic exists for the distance to the solution. The classic fifteen puzzle, where tiles slide into order, is solved by the algorithm with a heuristic that counts how far each tile is from home, and the same approach plans motions for robotic arms and schedules tasks in factories.
Strengths and limits
The greatest strength of A star search is its efficiency on single-destination problems. A good heuristic can cut the explored nodes by an order of magnitude, turning a search that would take seconds into one that takes milliseconds, which is the difference between a game that feels responsive and one that stutters.
It is also a strength that the guarantee is conditional in a useful way. As long as the heuristic never overestimates, the shortest path is certain, so engineers can trade accuracy of the heuristic against speed with a clear understanding of what they are giving up. Our guide to in-memory computing shows how the speed of the underlying store matters just as much as the algorithm.
The limits are real, though. A bad heuristic can make A star search slower than Dijkstra’s algorithm, because the queue overhead buys nothing, and an overestimating heuristic forfeits the guarantee entirely. The algorithm also keeps every explored node in memory, which can be a problem on enormous graphs, where memory-bounded variants are needed instead.
A star search checklist
- Use A star search for a single destination with a good heuristic.
- Make sure the heuristic never overestimates the true remaining cost.
- Use straight-line distance on maps and Manhattan distance on grids.
- Stop when the goal leaves the queue, not when it is first found.
- Store parent pointers to recover the path afterwards.
- Prefer Dijkstra’s algorithm when all destinations are needed.
- Prefer breadth-first search when every edge costs the same.
- Test the heuristic on maps with walls and dead ends.
- Consider a memory-bounded variant for enormous graphs.
Frequently asked questions
What is A star search in simple terms?
It is a pathfinding method that combines the distance already travelled with an estimate of the distance still to go, expanding the most promising place first.
What is a heuristic in A star search?
It is an estimate of the remaining cost to the goal, such as the straight-line distance, which guides the search toward the destination.
What does admissible mean for a heuristic?
It means the heuristic never overestimates the true remaining cost, which is the condition that guarantees A star search finds the shortest path.
How is A star search different from Dijkstra’s algorithm?
A star search adds a heuristic that steers the search toward one goal, so it explores far fewer nodes, while Dijkstra’s algorithm explores evenly in all directions.
How fast is A star search?
It depends on the heuristic, but with a good one it explores far fewer nodes than Dijkstra’s algorithm and runs much faster for a single destination.
When should I not use A star search?
When there is no good heuristic, or when paths to every node are needed, where Dijkstra’s algorithm is the better choice.
The bottom line
A star search explained in one line is this: add a good guess about what remains, and the search walks toward its goal instead of wandering everywhere.
It is the algorithm behind game characters, warehouse robots, and route planners, and the reason a path across a huge map can be found in milliseconds.
This article is general information about how A star search works, not advice about choosing an algorithm for a particular system.







