Question: Warmup with Dijkstra. ( 2 5 points ) Let G = ( V;E ) be a weighted directed graph. For the rest of this problem,
Warmup with Dijkstra. points
Let G V;E be a weighted directed graph. For the rest of this problem, assume that
s; t V and that there exists a directed path from s to t
For the rest of this problem, refer to the implementation of Dijkstra's algorithm given by
the pseudocode below.
dijkstrastpathG s t:
for all v in V set dv Infinity
for all v in V set pv None
we will use p to reconstruct the shortest st path at the end
ds
F V
D
while F isn't empty:
x vertex v in F such that dv is minimized
for y in xoutgoingneighbors:
dy min dy dx weightxy
if dy was changed in the previous line, set py x
Fremovex
Daddx
use p to reconstruct the shortest st path
path t
current t
while current s:
current pcurrent
add current to the front of the path
return path, dt
The variable p maintains the parents of the vertices in the shortest st path, so it can
be reconstructed at the end.
Step through dijkstra st pathG; s; t on the graph G shown below. Complete the table
below to show what the arrays d and p are at each step of the algorithm, and indicate
what path is returned and what its cost is
s u
v
t
G
We are expecting the table below lled out, as well as the nal shortest path
and its cost. No further justication is required.
ds du dv dt ps pu pv pt
When entering the rst while loop
for the rst time, the state is:
None None None None
Immediately after the rst ele
ment of D is added, the state is:
None s None None
Immediately after the second ele
ment of D is added, the state is:
Immediately after the third ele
ment of D is added, the state is:
Immediately after the fourth ele
ment of D is added, the state is:
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
