dijkstra: Implementation of the Dijkstra algorithm

Description Usage Arguments Value See Also Examples

View source: R/dijkstra.R

Description

dijkstra finds the shortest distance from a given node in a graph to every other node in the graph, and returns a vector of these distances in the same order as the nodes. Pseudocode for this function taken from the Wikipedia page for Dijkstra Algorithm.

Usage

1
dijkstra(graph, init_node)

Arguments

graph

A data frame with three variables (v1, v2 and w) that contains the edges of the graph (from v1 to v2) with the weight of the edge (w).

init_node

A node in the graph whose distance is to be found from every other node of the graph.

Value

A vector having the same length as the number of nodes in the graph, containing the distances of the init_node from every other node in the graph, in the same order as the order of the nodes.

See Also

https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

Examples

1

Er-Prakhar/Lab003 documentation built on Dec. 17, 2021, 7:21 p.m.