Given the following graph, step through Dijkstra’s algorithm to produce the shortest path to every other vertex starting from vertex A. Provide the final table of the paths as shown in the previous chapter.
218211292BDECA
Challenge 2: Find all the shortest paths
Add a method to class Dijkstra that returns a dictionary of all the shortest paths to all vertices given a starting vertex. Here’s the method signature to get you started:
public func getAllShortestPath(from source: Vertex<T>)
-> [Vertex<T> : [Edge<T>]] {
var pathsDict = [Vertex<T> : [Edge<T>]]()
// Implement Solution Here
return pathsDict
}
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a Kodeco Personal Plan.