Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started