bestFirstSearch
bestFirstSearch<
TNode>(start,traits):GraphPath<TNode> |null
Defined in: graph/best-first-search.ts:30
Finds a path from start to a goal, always expanding whichever frontier node
looks closest to one — greedy best-first search.
Ordering is by heuristicOf alone, ignoring the cost already paid. That
reaches a goal far sooner than aStar on a graph where the heuristic
points the right way, and returns a worse than optimal path when it does
not. Use aStar whenever the cheapest path is what matters; use this
when any path, found fast, is enough.
The returned cost is still the true cost of the path walked, so a caller
can measure how far off it landed.
Time complexity: O((V + E) log V), and costOf must be non-negative.
Type Parameters
Section titled “Type Parameters”TNode extends DefinedValue
Parameters
Section titled “Parameters”TNode
The node to search from.
traits
Section titled “traits”GraphSearchTraits<TNode>
How to expand, weight and test a node. heuristicOf is what
drives this search; leaving it at its 0 default degenerates to an
arbitrary-order traversal.
Returns
Section titled “Returns”GraphPath<TNode> | null
The path found and its cost, or null if no goal is reachable.