Dijkstra's algorithm (or Dijkstra's Shortest path First algorithm, SPF algorithm) is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. A widely used application of shortest path algorithm is network routing protocols, most notably IS-IS (Intermediate System to Intermediate System) and open Shortest path As a solution, he re-observed the algorithm known as Prim's minimal spanning tree algorithm (known earlier to Jarník, and also rediscovered by Prim).He designed the shortest path algorithm and later implemented it for ARMAC for a slightly simplified transportation map of 64 city in the Netherlands (64, so that 6 bits would be sufficient to encode the city number).What is the shortest manner to travel from Rotterdam to Groningen, in general: from given city to given city.

If the destination node has been marked visited (when planning a path between two specific nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when planning a complete traversal; happens when there is no connection between the initial node and remaining unvisited nodes), then stop. Otherwise, choose the unvisited node that is marked with the smallest tentative distance, put it as the new" current node", and go back to step 3.When planning a path, it is actually not necessary to wait until the destination node is" visited" as above: the algorithm can stop once the destination node has the smallest tentative distance among all" unvisited" nodes (and thus could be choose as the next" current").

```
package org.gs.digraph
/** Solves for all pairs shortest path from a source where edge weights are non-negative
*
* @constructor creates a new DijkstraAllPairsSP with an edge weighted digraph
* @param g acyclic digraph, edges have direction and weight
* @see [[https://algs4.cs.princeton.edu/44sp/DijkstraAllPairsSP.java.html]]
* @author Scala translation by Gary Struthers from Java by Robert Sedgewick and Kevin Wayne.
*/
class DijkstraAllPairsSP(g: EdgeWeightedDigraph) {
private val all = for (v <- 0 until g.numV) yield new DijkstraSP(g, v)
/** returns path from source to t if it exists */
def path(s: Int, t: Int): Option[List[DirectedEdge]] = all(s) pathTo(t)
/** returns length of shortest path from source to t */
def dist(s: Int, t: Int): Double = all(s) distTo(t)
/** returns if there is a path from source to t */
def hasPath(s: Int, t: Int): Boolean = dist(s, t) < Double.PositiveInfinity
}
```