Question: ( finish the algorithm ) / / Dijkstra ' s shortest path algorithm - generating a table that contains the shortest distance from start to
finish the algorithmDijkstras shortest path algorithm generating a table that contains the shortest distance from start to every other vertex and the predecessor of each vertex.
g is a graph. We will pass the graph created in our client file.
start is the start vertex.
void DijkstraShortestPathconst graph& g int start
minHeap ; Create a min heap of the data type, vertex.
Create a dynamic array pointed to by locator, which is declared globally above.
locator is an array containing the location of each vertex in the heap
locator always tells the locationindex of vertex in the heap. If the locator looks like vertex is located at index in the heap, veertex is located at index meaning vertex has the minimum distance
The following for loop populates the min heap with all the vertices. Set curDist to and predecessor to
eg vertex for vertext number should like this
vertex for vertext number should like this
vertex ver; temp vertext struct used for multiple purposes
for int i ; i ; i
fill ver declared above with values
call minHeap::insert to insert each vertex
You need to initialize the locator array. To start with, locator array should look like this telling us vertex is at index in the heap, vertex is at index
fill ver declared above with start, and start vertex should have for curDist and for predecessor
If start is ver should look like
ver.vertexNum
ver.curDist
ver.predecessor
call minHeap::updateElem to update the start vertex's info
the updateElem will update the info at index i first parameter
updateElem will fix the min heap based on curDist starting at i
Since this start vertex has for curDist and the other vertices have for curDist,
this start vertex should come up to the top
Follow Dijkstra's algorithm and complete the following
Use printHeapArrays for debugging
After Dijkstra's algorithm is finished, call showShortestDistance above to show the path and distance from start and destination
Dont forget to destroy the dynamic array you made for locator
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
