| 1. |
Describe the Dijkstra’s algorithm for finding a shortest path in a given graph. |
|
Answer» Let G = (v,e) be a simple graph. Let a & z be any two vertices of the graph. Suppose L(x) denotes the label of the vertex z which represents the length of the shortest path from the vertex a to the vertex z. Wij denotes the weight of the edge eig = (Vi , Vj) 1. let P = Q where p is the set of those vertices which have permanent labels & T = {all vertices of the graph G} Set L (a) = 0, L (x) = ∞for all x €T & x≠a 2. Select the vertex v in T which has the smallest label. This label is called the permanent label of v. Also set P = P U {v} and T = T-{v} if v=z then L (z) is the length of the shortest path from the vertex a to z and stop. 3. If v ≠z then revise the labels of vertices of T i.e. the vertices which do not have permanent labels. The new label of a vertex x in T is given by L (x) = min{old L(x),L(v)+w(y,x)} where w (v,x) is the weight of the edge joining the vertex v & x If there is no direct edge joining v & x then take w(v,x) = ∞ 4. Repeat steps 2 and 3 until z gets the permanent label. |
|