Question: Dijkstra's Algorithm provides the shortest path from a starting point in a graph to every other point in a graph. It does so by selecting
Dijkstra's Algorithm provides the shortest path from a starting point in a graph to every other point in a graph. It does so by selecting the next closest vertex to the start and updating the list of distances as new vertices are visited.
Modify your existing Graph code to include Dijkstra's Algorithm for finding the shortest distance between vertices.
Add code to the main.cpp to accept as input, the name of a file. Read from the file the number of vertices and the edges between vertices, including edge weights and construct an adjacency graph. The file will contain a positive integer on the first line that represents the number of vertices in the graph. Each of the subsequent lines will contain three values that represent a single edge in the graph; the from vertex, the to vertex, and the nonnegative weight. These edges are directed and will always be between valid vertices.
Provide code to read in these edges and construct an adjacency matrix for this graph.
For example, the file inputtxt contains:
This corresponds to the adjacency matrix:
Then, take as inputs a starting vertex for the algorithm, provide the distances, and show the path.
Vertex Distance Path
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
