Skip to main content

dijkstra

Function dijkstra 

Source
pub fn dijkstra(
    graph: &Graph,
    start_node: usize,
) -> (Vec<f64>, Vec<Option<usize>>)
Expand description

Finds the shortest paths from a single source node to all other nodes using Dijkstra’s algorithm.

Dijkstra’s algorithm is a greedy algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights.

§Arguments

  • graph - The graph to search.
  • start_node - The index of the starting node.

§Returns

A tuple containing:

  • A vector of distances from the start node to each node.
  • A vector of predecessors to reconstruct the shortest paths.