dijkstra: Distance Computation Algorithm

Description Usage Arguments Value References Examples

View source: R/dijkstras.R

Description

Given a connected graph and starting node, find the shortest distance from the starting node to every other node in the graph using Dijkstra's algorithm

Usage

1
dijkstra(graph, init_node)

Arguments

graph

A dataframe with three numeric columns viz. "v1", "v2", and "w", representing each node, its adjacent node, and the distance between them, respectively

init_node

The starting node

Value

Shortest distance from init_node to all other nodes in the graph.

References

Dijkstra's Algorithm

Wiki page on what a graph is and more

Examples

1
2
3
wiki_graph <- data.frame(v1=c(1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,6,6,6),v2=c(2,3,6,1,3,4,1,2,4,6,2,3,5,4,6,1,3,5),w=c(7,9,14,7,10,15,9,10,11,2,15,11,6,6,9,14,2,9))
dijkstra(wiki_graph,1)
dijkstra(wiki_graph,3)

shashiniyer/Euclid_Dijkstras documentation built on Dec. 23, 2021, 1:21 a.m.