Algorithm
A* search
activeNeeds verification
Shortest-path search guided by a heuristic estimate of remaining distance; with an admissible heuristic it finds optimal paths while expanding fewer nodes than Dijkstra.
Definition
Intuition
Dijkstra that prefers nodes which look closer to the goal, e.g. using straight-line distance on a map.
Complexity
| Time | Depends on the heuristic; worst case as Dijkstra |
|---|---|
| Space | O(V) |
Python
import networkx as nx
h = lambda u, v: euclid(pos[u], pos[v])
path = nx.astar_path(G, 'A', 'F', heuristic=h, weight='weight')Cypher (Neo4j GDS)
CALL gds.shortestPath.astar.stream('roads', {
sourceNode: s, targetNode: t,
latitudeProperty: 'lat', longitudeProperty: 'lon',
relationshipWeightProperty: 'distance'})
YIELD totalCost, nodeIds RETURN totalCost, nodeIdsProcedure names and options vary between GDS versions; check the GDS docs for your version.
An interactive step-by-step visualizer for this algorithm is planned for phase 3.
Profile
| Time complexity | Depends on the heuristic; worst case as Dijkstra |
|---|---|
| Space complexity | O(V) |
Relationships
- Belongs to
- Prerequisites
- Dijkstra's shortest path(Algorithm)
- Related
- A* search published(Timeline event)