Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 2 : Implement Dijkstra s algorithm in PathFindingService ( Fig 5 ) . Use the algorithm to implement the findPath ( Tile startNode )

Step 2: Implement Dijkstras algorithm in PathFindingService (Fig 5). Use the algorithm to
implement the findPath(Tile 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.
11
DIJKSTRA(V, E,w,s):
INIT-SINGLE-SOURCE(V,s)
S Q V
while Q do
u REMOVE-MIN(Q)
S S {u}
for each vertex v Adj[u] do
RELAX(u,v,w)
Figure 5: Pseudo-code for Dijkstras algorithm
INIT-SINGLE-SOURCE(V,s)
for each v V do
d[v]
[v] null
d[s]0
Figure 6: Pseudo-code for the initialization
RELAX(u,v,w)
if d[v]> d[u]+w(u,v) then
d[v] d[u]+w(u,v)
[v] u
Figure 7: Pseudo-code for the relaxing operation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions