Question: Step 2 : Implement Dijkstra s algorithm in PathFindingService ( Fig 5 ) . Use the algorithm to implement the findPath ( Tile startNode )
Step : Implement Dijkstras algorithm in PathFindingService Fig Use the algorithm to
implement the findPathTile startNode method. The method uses Dijkstras algorithm
on the Graph stored in the field g to find a minimum weight path to the destination from the
input Tile. Note that the result of running Dijkstras algorithm is that each node in the graph will
contain the information needed to find the minimun weight path from the source to this node. So
after running the algorithm you will need to use the infomation stored in the predecessor field
to backtrack and find the list of Tiles that make up the path to be traversed from the start node to
the destination.
DIJKSTRAV Ews:
INITSINGLESOURCEVs
S Q V
while Q do
u REMOVEMINQ
S S u
for each vertex v Adju do
RELAXuvw
Figure : Pseudocode for Dijkstras algorithm
INITSINGLESOURCEVs
for each v V do
dv
v null
ds
Figure : Pseudocode for the initialization
RELAXuvw
if dv duwuv then
dv duwuv
v u
Figure : Pseudocode for the relaxing operation
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
