Skip to main content
Version: 4.1

Dijkstra()

alg.Dijkstra is an implementation of the Dijkstra's shortest path algorithm. It can efficiently find the shortest path in both directed and undirected graphs. This implementation uses a binary heap based priority queue. The time complexity of this algorithm is O(|E| + |V| log |V|), where |E| is the number of edges in the graph and |V| is the number of nodes.

note

Even though alg.Dijkstra is listed as a separate plugin, you usually don't use it directly. Instead, you can use the graphUtils plugin which extends the joint.dia.Graph with a convenience method for finding the shortest path between two nodes shortestPath(source, target [, opt]). However, it could be useful to use alg.Dijkstra directly in some situations. The reason is that alg.Dijkstra calculates not only the shortest path between two nodes but the shortest path between a node and all the other nodes in the graph.

alg.Dijkstra(
adjacencyList: any,
source: string | number, weight: (aNode: any, bNode: any) => number
): any;

Find the shortest path between the node source and all the other nodes in the graph represented as adjacencyList. See the usage section for more info. weight can optionally contain a function that takes two nodes and returns the distance between them. This function defaults to: function(u, v) { return 1; }