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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!