pub fn astar_search<N, E, Ix, H>(
graph: &Graph<N, E, Ix>,
source: &N,
target: &N,
heuristic: H,
) -> Result<AStarResult<N, E>>Expand description
A* search algorithm for finding the shortest path with a heuristic
§Arguments
graph- The graph to searchsource- Source nodetarget- Target nodeheuristic- Heuristic function that estimates distance from a node to the target
§Returns
Result<AStarResult>- The shortest path and its cost
§Time Complexity
O(b^d) where b is the branching factor and d is the depth of the solution. In the worst case with an inadmissible heuristic: O(V²). With a perfect heuristic: O(V). Typical case with good heuristic: O(V log V).
§Space Complexity
O(V) for the open set, closed set, and path reconstruction.
§Note
The heuristic function must be admissible (never overestimate the actual cost) and consistent (satisfy the triangle inequality) to guarantee finding the optimal path.