Skip to content

@graphty/algorithms / index / astar

Function: astar() ​

astar<T>(graph, start, goal, heuristic): { cost: number; path: T[]; } | null

Defined in: pathfinding/astar.ts:17

A* pathfinding algorithm Finds the shortest path from start to goal using a heuristic function

Type Parameters ​

T ​

T

Parameters ​

graph ​

Map<T, Map<T, number>>

The graph represented as an adjacency list

start ​

T

The starting node

goal ​

T

The goal node

heuristic ​

(node, goal) => number

Heuristic function that estimates distance from node to goal

Returns ​

{ cost: number; path: T[]; } | null

Object containing the shortest path and its cost, or null if no path exists

Time Complexity: O(E) with good heuristic, O(b^d) worst case Space Complexity: O(V)