Dijkstra Module
Dijkstra's algorithm for single-source shortest paths in graphs with non-negative edge weights.
Dijkstra's algorithm finds the shortest path from a source node to all other reachable nodes in a graph. It works by maintaining a priority queue of nodes to visit, always expanding the node with the smallest known distance.
Algorithm
Algorithm |
Function |
Complexity |
Best For |
|---|---|---|---|
Dijkstra (single-target) |
shortestPath |
O((V + E) log V) |
One-to-one shortest path |
Dijkstra (single-source) |
singleSourceDistances |
O((V + E) log V) |
One-to-all shortest paths |
Implicit Dijkstra |
implicitDijkstra |
O((V + E) log V) |
Large/infinite graphs |
History
Edsger W. Dijkstra published this algorithm in 1959. The original paper described it for finding the shortest path between two nodes, but it's commonly used for single-source shortest paths to all nodes.
Use Cases
- Network routing: OSPF, IS-IS protocols use Dijkstra
- Map services: Shortest driving directions
- Social networks: Degrees of separation
- Game development: Shortest path on weighted grids
Functions and values
| Function or value |
Description
|
Full Usage:
implicitDijkstra zero add compare successors isGoal start
Parameters:
'cost
add : 'cost -> 'cost -> 'cost
compare : 'cost -> 'cost -> int
successors : 'state -> ('state * 'cost) list
isGoal : 'state -> bool
start : 'state
Returns: 'cost option
|
Finds the shortest path in an implicit graph using Dijkstra's algorithm.
|
Full Usage:
implicitDijkstraBy zero add compare successors keyFn isGoal start
Parameters:
'cost
add : 'cost -> 'cost -> 'cost
compare : 'cost -> 'cost -> int
successors : 'state -> ('state * 'cost) list
keyFn : 'state -> 'key
isGoal : 'state -> bool
start : 'state
Returns: 'cost option
|
Like
|
|
|
|
|
|
|
|
|
|
|
|