dijkstra: dijkstra function

Description Usage Arguments Value Examples

Description

This function implements the Dijkstras algorithm to find the shortest path from the initial node to every other node in the graph. MOre detail about the algorithm can be found here: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

Usage

1
dijkstra(wiki_graph, init_node)

Arguments

wiki_graph

A data.frame that shows the nodes and their dependencies within a graph.

init_node

An integer that states the number of the source node in the graph.

Value

The output is a numeric vector.

Examples

1
2
3
4
5
6
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) #0 7 9 20 20 11

nahfa911/lab3 documentation built on May 9, 2019, 5:54 a.m.