The A* algorithm is a popular Best First Search algorithm for finding the shortest path between two known nodes.
Info
The A* algorithm uses two pieces of information in order to make an estimate about how optimal a given node is:
- → The cost from the start node to node .
- → The heuristic function describing the estimated cost to the goal node.
This produces which A* attempts to find the minimal value of.
Process
The A* algorithm follows the following process:
- Add the neighbours of the starting node to the open set/frontier.
- Select the member of the open set/frontier with the lowest value, and expand it’s neighbours, adding them to the open set/frontier.
- Continue until the goal node is reached.
Complexity
The complexity values for A* are:
Aspect | Complexity |
---|---|
Time | |
Space |
Example
Run the A* algorithm on the following graph:
Note
The result of , the heuristic function, is marked in gold below each node. Edge weights are in black next to each edge.
Here, the open set/frontier was:
Node | |||
---|---|---|---|
Here, the open set/frontier was:
Node | |||
---|---|---|---|
Here, the open set/frontier was:
Node | |||
---|---|---|---|
Here, the open set/frontier was:
Node | |||
---|---|---|---|
Here, the open set/frontier was:
Node | |||
---|---|---|---|
goal node | |||
Since the goal node
is a member of the open set/frontier we just select it, and our shortest path is the one from