Question
Dijkstras algorithm is applied to a rectangular grid of size n times n. The vertices of the rectangular grid have the form (i,j), where i,j=1,2,3,,n,
Dijkstras algorithm is applied to a rectangular grid of size n times n. The vertices of the rectangular grid have the form (i,j), where i,j=1,2,3,,n, and the edges (all of unit length) connect pairs (i,j), (i+1,j) and (i,j), (i,j+1). Assume that vertex (1,1) is the source. What are the optimal paths recovered by the algorithm? What are the final values of arrays D and P? In the case of ambiguity assume that the algorithm makes choices according to lexicographic ordering of vertices, I.E. (i1,j1) < (i2,j2) if and only if i1 < i2 or (i1 = i2 and j1 < j2).
procedure Dijkstra; begin S := {1}; for i := 2 to n do begin D[i] := C[1,i]; P[i] := 1 end; for i := 1 to n-1 do begin choose a vertex w in V-S such that D[w] is minimum; add w to S; for each vertex v in V-S do if D[v] > D[w] + C[w,v] then begin D[v] := D[w] + C[w,v]; P[v] := w end end end;
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