Skip to content

has-path ​

Guide: /guide/algorithms/graph/has-path

Signature ​

ts
hasPath({ graph, from, to, traversalType });

Params: ​

NameTypeRequiredDescription
graphIGraph<T>+Graph to search
fromT+Start vertex
toT+End vertex
traversalTypeEnumGraphTraversalType+BFS, DFS, DIJKSTRA, BELLMAN_FORD, or A_STAR

BELLMAN_FORD and A_STAR search with BFS. A reachable negative cycle still returns true.

Returns: ​

boolean ​

true when a path exists. false when the goal is in the graph and unreachable.

Throws: ​

IsNotFoundException when a vertex does not exist ​

MIT Licensed