Weighted Graph

Dijkstra's Algorithm on JavaScript

Koowoy
Definition of Dijkstra’s Algorithm Algorithm to calculate the shortest path from one vertex of a graph to another vertex, using a priority array Input and Output Input: starting vertex, ending vertex Output: an array of vertices consisting of the shortest path from start to end in order Logic 1. To begin with, 4 variables need to be initialized. distances object: used to store the shortest distance from start to each vertex previous object: used to store the previous vertex of the path shortest to the current vertex priority queue: used to store vertices to pay visits to, in ascending order of distances from the starting vertex to the current vertex, this will be used for looping through the graph path: an array for storing path info at the end for returning the path 2.